Branch 'pyramid' - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/resources.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit b2a06b679e198a122c2c1352c0e8dd9f5bc89f16
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 12:46:41 2011 -0400
Enable the users resource
diff --git a/pyramid/bodhi/bodhi/resources.py b/pyramid/bodhi/bodhi/resources.py
index ece7056..7839bf6 100644
--- a/pyramid/bodhi/bodhi/resources.py
+++ b/pyramid/bodhi/bodhi/resources.py
@@ -77,7 +77,7 @@ def default_get_root(request):
u'builds': BuildResource,
u'packages': PackageResource,
u'releases': ReleaseResource,
- #'users': UserResource,
+ u'users': UserResource,
})
return root
12 years, 11 months
Branch 'pyramid' - 4 commits - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/__init__.py | 2 +-
pyramid/bodhi/bodhi/models/models.py | 2 +-
pyramid/bodhi/bodhi/resources.py | 12 ------------
pyramid/bodhi/bodhi/tests/models/__init__.py | 4 +++-
pyramid/bodhi/bodhi/tests/views/test_views.py | 9 ++++++++-
pyramid/bodhi/bodhi/views.py | 1 -
6 files changed, 13 insertions(+), 17 deletions(-)
New commits:
commit 68dfb2839a3391109120805c322e620dd4866992
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 12:41:55 2011 -0400
Add a functional test for our view_model
diff --git a/pyramid/bodhi/bodhi/tests/models/__init__.py b/pyramid/bodhi/bodhi/tests/models/__init__.py
index 2a40c9a..fe75486 100644
--- a/pyramid/bodhi/bodhi/tests/models/__init__.py
+++ b/pyramid/bodhi/bodhi/tests/models/__init__.py
@@ -10,7 +10,9 @@ from bodhi.tests import setup_db, teardown_db
def setup():
"""Function called by nose on module load"""
- setup_db()
+ # Doesn't appear to be necessary as long as our functional test suite
+ # runs first (which sets up the DBSession)
+ #setup_db()
def teardown():
"""Function called by nose after all tests in this module ran"""
diff --git a/pyramid/bodhi/bodhi/tests/views/test_views.py b/pyramid/bodhi/bodhi/tests/views/test_views.py
index b397a2e..f7477c7 100644
--- a/pyramid/bodhi/bodhi/tests/views/test_views.py
+++ b/pyramid/bodhi/bodhi/tests/views/test_views.py
@@ -11,9 +11,16 @@ class ViewTests(unittest.TestCase):
def tearDown(self):
testing.tearDown()
- def test_view_model(self):
+ def test_view_model_instance(self):
from bodhi.views import view_model_instance
request = testing.DummyRequest()
context = DBSession.query(Release).first()
info = view_model_instance(context, request)
self.assertEqual(info['context'], context.__json__())
+
+ def test_view_model(self):
+ from bodhi.resources import ReleaseResource
+ from bodhi.views import view_model
+ request = testing.DummyRequest()
+ info = view_model(ReleaseResource, request)
+ self.assertEqual(len(info['entries']), 2)
diff --git a/pyramid/bodhi/bodhi/views.py b/pyramid/bodhi/bodhi/views.py
index 1921c47..b0b70dc 100644
--- a/pyramid/bodhi/bodhi/views.py
+++ b/pyramid/bodhi/bodhi/views.py
@@ -7,7 +7,6 @@ def view_model_instance(context, request):
return {'context': context.__json__()}
def view_model(context, request):
- print "view_model(%s)" % context
session = DBSession()
# TODO: pagination
entries = session.query(context.__model__).all()
commit f04584fbdbecec4e0a84dbe1fc1c1dcae2642eaf
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 12:41:28 2011 -0400
Remove some unnecessary methods from our root resource
diff --git a/pyramid/bodhi/bodhi/resources.py b/pyramid/bodhi/bodhi/resources.py
index eb08470..ece7056 100644
--- a/pyramid/bodhi/bodhi/resources.py
+++ b/pyramid/bodhi/bodhi/resources.py
@@ -19,18 +19,6 @@ class BodhiRoot(object):
resource.__name__ = key
return resource
- def get(self, key, default=None):
- try:
- item = self.__getitem__(key)
- except KeyError:
- item = default
- return item
-
- def __iter__(self):
- session = DBSession()
- query = session.query(self.__model__)
- return iter(query)
-
class BodhiResource(object):
__name__ = None
commit d28c2d009a33b9e9ff1dedb7a086bf60fde57c06
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 12:41:19 2011 -0400
No need to config.scan until we use the @view_config decorator
diff --git a/pyramid/bodhi/bodhi/__init__.py b/pyramid/bodhi/bodhi/__init__.py
index c0a696c..2f0099f 100644
--- a/pyramid/bodhi/bodhi/__init__.py
+++ b/pyramid/bodhi/bodhi/__init__.py
@@ -34,5 +34,5 @@ def main(global_config, **settings):
config.add_view('bodhi.views.view_model',
context='bodhi.resources.BodhiResource',
renderer='json')
- config.scan()
+ #config.scan()
return config.make_wsgi_app()
commit cda947c8b8a22845b82956840bb7e6fde2dd0d12
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 12:41:06 2011 -0400
notes are mandatory now
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index a947e1b..0cefdf0 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -995,7 +995,7 @@ def populate():
session.add(pkg)
build = Build(nvr=u'bodhi-2.0-1.fc15', release=release)
session.add(build)
- update = Update(builds=[build], user=user)
+ update = Update(builds=[build], user=user, notes=u'Useful details!')
update.type = UpdateType.bugfix
session.add(update)
session.commit()
12 years, 11 months
Branch 'pyramid' - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/models/models.py | 26 +++++++++++++++++++-----
pyramid/bodhi/bodhi/resources.py | 10 +++------
pyramid/bodhi/bodhi/tests/models/test_models.py | 11 +++++++---
3 files changed, 33 insertions(+), 14 deletions(-)
New commits:
commit 9ad279c25541ecb211f6e8132fead2f44bf50bca
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 11:27:39 2011 -0400
Add a User model
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index df1036f..a947e1b 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -263,9 +263,9 @@ class Update(Base):
id = Column(Integer, primary_key=True)
_title = Column('title', UnicodeText)
- submitter = Column(Unicode(32), nullable=False)
+ # TODO: more flexible karma schema
karma = Column(Integer, default=0)
- notes = Column(UnicodeText)
+ notes = Column(UnicodeText, nullable=False) # Mandatory notes
# Enumerated types
type = Column(UpdateType.db_type(), nullable=False)
@@ -317,6 +317,8 @@ class Update(Base):
#releases = relation('Release', secondary=update_release_table,
# backref='updates', lazy=False)
+ user_id = Column(Integer, ForeignKey('users.id'))
+
@synonym_for('_title')
@property
def title(self, show_nvrs=True, delim=' '):
@@ -584,7 +586,7 @@ class Update(Base):
val += u"\n Notes: %s" % '\n'.join(notes)
val += u"""
Submitter: %s
- Submitted: %s\n""" % (self.submitter, self.date_submitted)
+ Submitted: %s\n""" % (self.user.name, self.date_submitted)
if len(self.comments):
val += u" Comments: "
comments = []
@@ -821,7 +823,8 @@ class Comment(Base):
anonymous = Column(Boolean, default=False)
timestamp = Column(DateTime, default=datetime.utcnow)
- update_id = Column('update_id', Integer, ForeignKey('updates.id'))
+ update_id = Column(Integer, ForeignKey('updates.id'))
+ user_id = Column(Integer, ForeignKey('users.id'))
def __str__(self):
karma = '0'
@@ -961,6 +964,17 @@ class Bug(Base):
return "%s/show_bug.cgi?id=%s" % (config.get('bz_baseurl'), self.bug_id)
+class User(Base):
+ __tablename__ = 'users'
+
+ id = Column(Integer, primary_key=True)
+ name = Column(Unicode(32), unique=True, nullable=False)
+
+ # One-to-many relationships
+ comments = relation(Comment, backref='user', lazy=False)
+ updates = relation(Update, backref='user', lazy=False)
+
+
#class Stack(Base):
# """
# A Stack in bodhi represents a group of packages that are commonly pushed
@@ -973,13 +987,15 @@ class Bug(Base):
def populate():
session = DBSession()
+ user = User(name=u'bodhi')
+ session.add(user)
release = Release(name=u'F15', long_name=u'Fedora 15', id_prefix=u'FEDORA', dist_tag=u'dist-f15')
session.add(release)
pkg = Package(name=u'bodhi')
session.add(pkg)
build = Build(nvr=u'bodhi-2.0-1.fc15', release=release)
session.add(build)
- update = Update(builds=[build], submitter=u'bodhi')
+ update = Update(builds=[build], user=user)
update.type = UpdateType.bugfix
session.add(update)
session.commit()
diff --git a/pyramid/bodhi/bodhi/resources.py b/pyramid/bodhi/bodhi/resources.py
index e01f935..eb08470 100644
--- a/pyramid/bodhi/bodhi/resources.py
+++ b/pyramid/bodhi/bodhi/resources.py
@@ -3,7 +3,7 @@ import logging
from sqlalchemy.orm.exc import NoResultFound
from bodhi.models import initialize_sql, DBSession
-from bodhi.models import Update, Package, Build, Release #, User
+from bodhi.models import Update, Package, Build, Release, User
log = logging.getLogger(__name__)
@@ -76,11 +76,9 @@ class ReleaseResource(BodhiResource):
__model__ = Release
__column__ = u'name'
-
-# TODO: proper User model?
-#class UserResource(BodhiResource):
-# __model__ = Update
-# __keys__ = (u'submitter')
+class UserResource(BodhiResource):
+ __model__ = User
+ __keys__ = u'name'
root = BodhiRoot()
diff --git a/pyramid/bodhi/bodhi/tests/models/test_models.py b/pyramid/bodhi/bodhi/tests/models/test_models.py
index 63f82d9..03d91a1 100644
--- a/pyramid/bodhi/bodhi/tests/models/test_models.py
+++ b/pyramid/bodhi/bodhi/tests/models/test_models.py
@@ -107,7 +107,6 @@ class TestUpdate(ModelTest):
type=UpdateType.security,
status=UpdateStatus.pending,
request=UpdateRequest.testing,
- submitter=u'lmacken',
close_bugs=True,
notes=u'foobar',
karma=0,
@@ -117,11 +116,12 @@ class TestUpdate(ModelTest):
release = model.Release(**TestRelease.attrs)
return dict(
builds = [model.Build(nvr=u'TurboGears-1.0.8-3.fc11',
- package=model.Package(**TestPackage.attrs),
- release = release)],
+ package=model.Package(**TestPackage.attrs),
+ release = release)],
bugs = [model.Bug(bug_id=1), model.Bug(bug_id=2)],
cves = [model.CVE(cve_id=u'CVE-2009-0001')],
release = release,
+ user = model.User(name=u'lmacken')
)
def get_update(self, name=u'TurboGears-1.0.8-3.fc11'):
@@ -331,3 +331,8 @@ class TestUpdate(ModelTest):
eq_(self.obj.get_build_tag(), u'dist-f11-updates-testing')
self.obj.status = UpdateStatus.stable
eq_(self.obj.get_build_tag(), u'dist-f11-updates')
+
+
+class TestUser(ModelTest):
+ klass = model.User
+ attrs = dict(name=u'Bob Vila')
12 years, 11 months
Branch 'pyramid' - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/tests/views/test_views.py | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
New commits:
commit 8f510361bfdc065fe14de5101d3cc5dff6c0233a
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 10:36:14 2011 -0400
Fix the test_view_model unit test
diff --git a/pyramid/bodhi/bodhi/tests/views/test_views.py b/pyramid/bodhi/bodhi/tests/views/test_views.py
index b08ce28..b397a2e 100644
--- a/pyramid/bodhi/bodhi/tests/views/test_views.py
+++ b/pyramid/bodhi/bodhi/tests/views/test_views.py
@@ -16,16 +16,4 @@ class ViewTests(unittest.TestCase):
request = testing.DummyRequest()
context = DBSession.query(Release).first()
info = view_model_instance(context, request)
- self.assertEqual(info['context'], {
- 'candidate_tag': u'dist-f11-updates-candidate',
- 'dist_tag': u'dist-f11',
- 'id': 1,
- 'id_prefix': u'FEDORA',
- 'locked': False,
- 'long_name': u'Fedora 11',
- 'metrics': {'test_metric': [0, 1, 2, 3, 4]},
- 'name': u'F11',
- 'stable_tag': u'dist-f11-updates',
- 'testing_tag': u'dist-f11-updates-testing',
- 'version': 11
- })
+ self.assertEqual(info['context'], context.__json__())
12 years, 11 months
Branch 'pyramid' - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/models/models.py | 3 ++-
pyramid/bodhi/bodhi/tests/models/__init__.py | 11 ++++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
New commits:
commit e1fd8ee21eff5532e5ae63dc2beaa2f4896edd82
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sat May 14 10:33:46 2011 -0400
Add a test_json method to each model test, and fix a bug that it found
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index ea52a10..df1036f 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -47,7 +47,8 @@ class BodhiBase(object):
continue
prop = getattr(self, col.name)
if isinstance(prop, list):
- prop = [child.__json__() for child in prop]
+ prop = [child.__json__() for child in prop
+ if hasattr(child, '__json__')]
elif hasattr(prop, '__json__'):
prop = prop.__json__()
elif isinstance(prop, datetime):
diff --git a/pyramid/bodhi/bodhi/tests/models/__init__.py b/pyramid/bodhi/bodhi/tests/models/__init__.py
index e99caaa..2a40c9a 100644
--- a/pyramid/bodhi/bodhi/tests/models/__init__.py
+++ b/pyramid/bodhi/bodhi/tests/models/__init__.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
"""Unit test suite for the models of the application."""
-from nose.tools import assert_equals
+import json
+
+from nose.tools import assert_equals, eq_
from bodhi.models import DBSession
from bodhi.tests import setup_db, teardown_db
@@ -44,6 +46,9 @@ class ModelTest(object):
pass
def test_query_obj(self):
- obj = DBSession.query(self.klass).one()
for key, value in self.attrs.iteritems():
- assert_equals(getattr(obj, key), value)
+ assert_equals(getattr(self.obj, key), value)
+
+ def test_json(self):
+ """ Ensure our models can return valid JSON """
+ assert json.dumps(self.obj.__json__())
12 years, 11 months
Branch 'pyramid' - 5 commits - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/__init__.py | 18 ++--
pyramid/bodhi/bodhi/models/enum.py | 4 -
pyramid/bodhi/bodhi/models/models.py | 85 ++++++++--------------
pyramid/bodhi/bodhi/resources.py | 100 ++++++++++++++++++++++++++
pyramid/bodhi/bodhi/tests/views/test_views.py | 24 ++++--
pyramid/bodhi/bodhi/views.py | 15 +++
6 files changed, 178 insertions(+), 68 deletions(-)
New commits:
commit 6f190d735b7b71f3a39280ba0608c6e0a7afeca1
Author: Luke Macken <lmacken(a)redhat.com>
Date: Fri May 13 01:49:21 2011 -0400
Typo
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index 47aed4d..ea52a10 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -669,7 +669,7 @@ class Update(Base):
except: # TODO: catch sqlalchemy's not found exception!
log.debug("Creating new CVE: %s" % cve_id)
cve = CVE(cve_id=cve_id)
- ession.save(cve)
+ Session.save(cve)
self.cves.append(cve)
Session.commit()
commit 2e99e7c4d35f467c8e781c0d3d9eb051a4db3b5e
Author: Luke Macken <lmacken(a)redhat.com>
Date: Fri May 13 01:49:07 2011 -0400
Some model constraints/defaults
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index ad1cbe6..47aed4d 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -267,8 +267,10 @@ class Update(Base):
notes = Column(UnicodeText)
# Enumerated types
- type = Column(UpdateType.db_type())
- status = Column(UpdateStatus.db_type())
+ type = Column(UpdateType.db_type(), nullable=False)
+ status = Column(UpdateStatus.db_type(),
+ default=UpdateStatus.pending,
+ nullable=False)
request = Column(UpdateRequest.db_type())
# Flags
commit 451d302e8d158846d4f8d118e349577f5b8f7329
Author: Luke Macken <lmacken(a)redhat.com>
Date: Fri May 13 01:48:49 2011 -0400
Add a __json__ to our BodhiBase and EnumSymbol
diff --git a/pyramid/bodhi/bodhi/models/enum.py b/pyramid/bodhi/bodhi/models/enum.py
index 508540a..329713d 100644
--- a/pyramid/bodhi/bodhi/models/enum.py
+++ b/pyramid/bodhi/bodhi/models/enum.py
@@ -24,6 +24,9 @@ class EnumSymbol(object):
def __repr__(self):
return "<%s>" % self.name
+ def __json__(self):
+ return self.description
+
class EnumMeta(type):
"""Generate new DeclEnum classes."""
@@ -64,7 +67,6 @@ class DeclEnum(object):
def db_type(cls):
return DeclEnumType(cls)
-
class DeclEnumType(SchemaType, TypeDecorator):
def __init__(self, enum):
self.enum = enum
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index 8da71ea..ad1cbe6 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -32,12 +32,29 @@ identity = Bunch(current=Bunch(user_name=u'Bob'))
class BodhiBase(object):
""" Our custom model base class """
+ __exclude_columns___ = None # List of columns to exclude from JSON
def __init__(self, **kw):
""" Automatically mapping attributes """
for key, value in kw.iteritems():
setattr(self, key, value)
+ def __json__(self):
+ items = []
+ exclude = getattr(self, '__exclude_columns__', [])
+ for col in self.__table__.columns:
+ if col.name in exclude:
+ continue
+ prop = getattr(self, col.name)
+ if isinstance(prop, list):
+ prop = [child.__json__() for child in prop]
+ elif hasattr(prop, '__json__'):
+ prop = prop.__json__()
+ elif isinstance(prop, datetime):
+ prop = prop.strftime('%Y-%m-%d %H:%M:%S')
+ items.append((col.name, prop))
+ return dict(items)
+
Base = declarative_base(cls=BodhiBase)
metadata = Base.metadata
DBSession = scoped_session(sessionmaker())
commit e555a4404aaf4b0fe1a2e9b0abdf80545c5eec3a
Author: Luke Macken <lmacken(a)redhat.com>
Date: Fri May 13 01:48:12 2011 -0400
Setup our basic views
diff --git a/pyramid/bodhi/bodhi/__init__.py b/pyramid/bodhi/bodhi/__init__.py
index f8cbaa3..c0a696c 100644
--- a/pyramid/bodhi/bodhi/__init__.py
+++ b/pyramid/bodhi/bodhi/__init__.py
@@ -5,7 +5,7 @@ from pyramid.request import Request
from pyramid.security import unauthenticated_userid
from pyramid.config import Configurator
-from bodhi.models import appmaker
+from bodhi.resources import appmaker
class BodhiRequest(Request):
@reify
@@ -25,12 +25,14 @@ def main(global_config, **settings):
engine = engine_from_config(settings, 'sqlalchemy.')
get_root = appmaker(engine)
config = Configurator(settings=settings, root_factory=get_root)
- config.set_request_factory(BodhiRequest)
+ #config.set_request_factory(BodhiRequest)
config.add_static_view('static', 'bodhi:static')
- config.add_view('bodhi.views.view_root',
- context='bodhi.models.Release',
- renderer="templates/root.pt")
- #config.add_view('bodhi.views.view_model',
- # context='bodhi.models.MyModel',
- # renderer="templates/model.pt")
+
+ config.add_view('bodhi.views.view_model_instance',
+ context='bodhi.models.Base',
+ renderer='json')
+ config.add_view('bodhi.views.view_model',
+ context='bodhi.resources.BodhiResource',
+ renderer='json')
+ config.scan()
return config.make_wsgi_app()
diff --git a/pyramid/bodhi/bodhi/tests/views/test_views.py b/pyramid/bodhi/bodhi/tests/views/test_views.py
index 32a84df..b08ce28 100644
--- a/pyramid/bodhi/bodhi/tests/views/test_views.py
+++ b/pyramid/bodhi/bodhi/tests/views/test_views.py
@@ -2,6 +2,8 @@ import unittest
from pyramid import testing
+from bodhi.models import DBSession, Release
+
class ViewTests(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
@@ -9,9 +11,21 @@ class ViewTests(unittest.TestCase):
def tearDown(self):
testing.tearDown()
- def test_my_view(self):
- from bodhi.views import view_root
+ def test_view_model(self):
+ from bodhi.views import view_model_instance
request = testing.DummyRequest()
- context = []
- info = view_root(context, request)
- self.assertEqual(info['project'], 'bodhi')
+ context = DBSession.query(Release).first()
+ info = view_model_instance(context, request)
+ self.assertEqual(info['context'], {
+ 'candidate_tag': u'dist-f11-updates-candidate',
+ 'dist_tag': u'dist-f11',
+ 'id': 1,
+ 'id_prefix': u'FEDORA',
+ 'locked': False,
+ 'long_name': u'Fedora 11',
+ 'metrics': {'test_metric': [0, 1, 2, 3, 4]},
+ 'name': u'F11',
+ 'stable_tag': u'dist-f11-updates',
+ 'testing_tag': u'dist-f11-updates-testing',
+ 'version': 11
+ })
diff --git a/pyramid/bodhi/bodhi/views.py b/pyramid/bodhi/bodhi/views.py
index 2fd492b..1921c47 100644
--- a/pyramid/bodhi/bodhi/views.py
+++ b/pyramid/bodhi/bodhi/views.py
@@ -1,5 +1,14 @@
-def view_root(context, request):
- return {'items':list(context), 'project':'bodhi'}
+#from pyramid.view import view_config
+from pyramid.response import Response
+
+from bodhi.models import Update, Package, Build, Release, DBSession
+
+def view_model_instance(context, request):
+ return {'context': context.__json__()}
def view_model(context, request):
- return {'item':context, 'project':'bodhi'}
+ print "view_model(%s)" % context
+ session = DBSession()
+ # TODO: pagination
+ entries = session.query(context.__model__).all()
+ return {'entries': [entry.__json__() for entry in entries]}
commit c9cd6930097ef1528643a3c660d3d9beffa44504
Author: Luke Macken <lmacken(a)redhat.com>
Date: Fri May 13 01:46:58 2011 -0400
Add a new resources.py module
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index 2622dc7..8da71ea 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -951,52 +951,20 @@ class Bug(Base):
# # updates
-
-
-class MyApp(object):
- __name__ = None
- __parent__ = None
-
- def __getitem__(self, key):
- session = DBSession()
- try:
- id = int(key)
- except (ValueError, TypeError):
- raise KeyError(key)
-
- query = session.query(Release).filter_by(id=id)
-
- try:
- item = query.one()
- item.__parent__ = self
- item.__name__ = key
- return item
- except NoResultFound:
- raise KeyError(key)
-
- def get(self, key, default=None):
- try:
- item = self.__getitem__(key)
- except KeyError:
- item = default
- return item
-
- def __iter__(self):
- session= DBSession()
- query = session.query(Release)
- return iter(query)
-
-root = MyApp()
-
-def default_get_root(request):
- return root
-
def populate():
session = DBSession()
- model = Release(name=u'F15')
- session.add(model)
- session.flush()
- transaction.commit()
+ release = Release(name=u'F15', long_name=u'Fedora 15', id_prefix=u'FEDORA', dist_tag=u'dist-f15')
+ session.add(release)
+ pkg = Package(name=u'bodhi')
+ session.add(pkg)
+ build = Build(nvr=u'bodhi-2.0-1.fc15', release=release)
+ session.add(build)
+ update = Update(builds=[build], submitter=u'bodhi')
+ update.type = UpdateType.bugfix
+ session.add(update)
+ session.commit()
+ #session.flush()
+ #transaction.commit()
def initialize_sql(engine):
DBSession.configure(bind=engine)
@@ -1006,7 +974,3 @@ def initialize_sql(engine):
populate()
except IntegrityError:
DBSession.rollback()
-
-def appmaker(engine):
- initialize_sql(engine)
- return default_get_root
diff --git a/pyramid/bodhi/bodhi/resources.py b/pyramid/bodhi/bodhi/resources.py
new file mode 100644
index 0000000..e01f935
--- /dev/null
+++ b/pyramid/bodhi/bodhi/resources.py
@@ -0,0 +1,100 @@
+import logging
+
+from sqlalchemy.orm.exc import NoResultFound
+
+from bodhi.models import initialize_sql, DBSession
+from bodhi.models import Update, Package, Build, Release #, User
+
+log = logging.getLogger(__name__)
+
+resources = {}
+
+class BodhiRoot(object):
+ __name__ = None
+ __parent__ = None
+
+ def __getitem__(self, key):
+ resource = resources[key]()
+ resource.__parent__ = self
+ resource.__name__ = key
+ return resource
+
+ def get(self, key, default=None):
+ try:
+ item = self.__getitem__(key)
+ except KeyError:
+ item = default
+ return item
+
+ def __iter__(self):
+ session = DBSession()
+ query = session.query(self.__model__)
+ return iter(query)
+
+
+class BodhiResource(object):
+ __name__ = None
+ __parent__ = None
+ __model__ = None
+ __column__ = None
+
+ def __getitem__(self, key):
+ session = DBSession()
+ log.debug('%s(%r)'% (self.__class__.__name__, key))
+ try:
+ return session.query(self.__model__).filter_by(**{self.__column__: key}).one()
+ except NoResultFound:
+ log.debug('NoResultsFound')
+ raise KeyError(key)
+
+ def get(self, key, default=None):
+ try:
+ item = self.__getitem__(key)
+ except KeyError:
+ item = default
+ return item
+
+ def __iter__(self):
+ session = DBSession()
+ query = session.query(self.__model__)
+ return iter(query)
+
+
+class PackageResource(BodhiResource):
+ __model__ = Package
+ __column__ = u'name'
+
+class BuildResource(BodhiResource):
+ __model__ = Build
+ __column__ = u'nvr'
+
+class UpdateResource(BodhiResource):
+ __model__ = Update
+ __column__ = u'title'
+
+class ReleaseResource(BodhiResource):
+ __model__ = Release
+ __column__ = u'name'
+
+
+# TODO: proper User model?
+#class UserResource(BodhiResource):
+# __model__ = Update
+# __keys__ = (u'submitter')
+
+root = BodhiRoot()
+
+def default_get_root(request):
+ global resources
+ resources.update({
+ u'updates': UpdateResource,
+ u'builds': BuildResource,
+ u'packages': PackageResource,
+ u'releases': ReleaseResource,
+ #'users': UserResource,
+ })
+ return root
+
+def appmaker(engine):
+ initialize_sql(engine)
+ return default_get_root
12 years, 12 months
Branch 'pyramid' - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/models/enum.py | 1 +
pyramid/bodhi/bodhi/models/models.py | 12 ++++++++++++
2 files changed, 13 insertions(+)
New commits:
commit baac10a489dac3256bb9569469bbf8427dab5b9e
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 13:47:49 2011 -0400
basics of a Stack
diff --git a/pyramid/bodhi/bodhi/models/enum.py b/pyramid/bodhi/bodhi/models/enum.py
index f113c57..508540a 100644
--- a/pyramid/bodhi/bodhi/models/enum.py
+++ b/pyramid/bodhi/bodhi/models/enum.py
@@ -24,6 +24,7 @@ class EnumSymbol(object):
def __repr__(self):
return "<%s>" % self.name
+
class EnumMeta(type):
"""Generate new DeclEnum classes."""
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index e2674ac..2622dc7 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -941,6 +941,18 @@ class Bug(Base):
return "%s/show_bug.cgi?id=%s" % (config.get('bz_baseurl'), self.bug_id)
+#class Stack(Base):
+# """
+# A Stack in bodhi represents a group of packages that are commonly pushed
+# together as a group.
+# """
+# # name
+# # packages = Many to many?
+# # updates
+
+
+
+
class MyApp(object):
__name__ = None
__parent__ = None
12 years, 12 months
Branch 'pyramid' - 4 commits - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/__init__.py | 20 +++++++++++++++-
pyramid/bodhi/bodhi/models/models.py | 6 ++--
pyramid/bodhi/bodhi/tests/models/test_models.py | 29 ++++++++++++++++++++++--
pyramid/bodhi/development.ini | 7 ++---
pyramid/bodhi/production.ini | 7 ++---
pyramid/bodhi/setup.py | 4 +--
6 files changed, 57 insertions(+), 16 deletions(-)
New commits:
commit e917e4d23003c2837480781ffe10d7d05f68d050
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 13:47:25 2011 -0400
Disable repoze.tm2 and zope.sqlalchemy
diff --git a/pyramid/bodhi/development.ini b/pyramid/bodhi/development.ini
index 6cc0610..bef0deb 100644
--- a/pyramid/bodhi/development.ini
+++ b/pyramid/bodhi/development.ini
@@ -11,12 +11,11 @@ sqlalchemy.url = sqlite:///%(here)s/bodhi.db
[pipeline:main]
pipeline =
egg:WebError#evalerror
- tm
bodhi
-[filter:tm]
-use = egg:repoze.tm2#tm
-commit_veto = repoze.tm:default_commit_veto
+#[filter:tm]
+#use = egg:repoze.tm2#tm
+#commit_veto = repoze.tm:default_commit_veto
[server:main]
use = egg:Paste#http
diff --git a/pyramid/bodhi/production.ini b/pyramid/bodhi/production.ini
index 9b46a3d..9590eb6 100644
--- a/pyramid/bodhi/production.ini
+++ b/pyramid/bodhi/production.ini
@@ -22,14 +22,13 @@ debug = false
;smtp_use_tls =
;error_message =
-[filter:tm]
-use = egg:repoze.tm2#tm
-commit_veto = repoze.tm:default_commit_veto
+#[filter:tm]
+#use = egg:repoze.tm2#tm
+#commit_veto = repoze.tm:default_commit_veto
[pipeline:main]
pipeline =
weberror
- tm
bodhi
[server:main]
diff --git a/pyramid/bodhi/setup.py b/pyramid/bodhi/setup.py
index d1f27b0..114fcfa 100644
--- a/pyramid/bodhi/setup.py
+++ b/pyramid/bodhi/setup.py
@@ -9,9 +9,9 @@ CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
requires = [
'pyramid',
- 'repoze.tm2>=1.0b1', # default_commit_veto
+ #'repoze.tm2>=1.0b1', # default_commit_veto
'sqlalchemy',
- 'zope.sqlalchemy',
+ #'zope.sqlalchemy',
'WebError',
]
commit 0296b0230ead0f49789dec91dbe4dff4890a335c
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 13:47:08 2011 -0400
More unit tests
diff --git a/pyramid/bodhi/bodhi/tests/models/test_models.py b/pyramid/bodhi/bodhi/tests/models/test_models.py
index 359695f..63f82d9 100644
--- a/pyramid/bodhi/bodhi/tests/models/test_models.py
+++ b/pyramid/bodhi/bodhi/tests/models/test_models.py
@@ -300,9 +300,34 @@ class TestUpdate(ModelTest):
eq_(self.obj.status, UpdateStatus.obsolete)
def test_request_complete(self):
- eq_(self.obj.pushed, False)
+ self.obj.request = None
eq_(self.obj.date_pushed, None)
+ self.obj.set_request('T')
+ self.obj.request_complete()
eq_(self.obj.pushed, True)
assert self.obj.date_pushed
+ eq_(self.obj.status, UpdateStatus.testing)
-# test multibuild update
+ def test_status_comment(self):
+ self.obj.status = UpdateStatus.testing
+ self.obj.status_comment()
+ eq_(len(self.obj.comments), 1)
+ eq_(self.obj.comments[0].author, u'bodhi')
+ eq_(self.obj.comments[0].text, u'This update has been pushed to testing')
+ self.obj.status = UpdateStatus.stable
+ self.obj.status_comment()
+ eq_(len(self.obj.comments), 2)
+ eq_(self.obj.comments[1].author, u'bodhi')
+ eq_(self.obj.comments[1].text, u'This update has been pushed to stable')
+
+ def test_get_url(self):
+ eq_(self.obj.get_url(), u'/TurboGears-1.0.8-3.fc11')
+ self.obj.assign_alias()
+ eq_(self.obj.get_url(), u'/F11/FEDORA-%s-0001' % time.localtime()[0])
+
+ def test_get_build_tag(self):
+ eq_(self.obj.get_build_tag(), u'dist-f11-updates-candidate')
+ self.obj.status = UpdateStatus.testing
+ eq_(self.obj.get_build_tag(), u'dist-f11-updates-testing')
+ self.obj.status = UpdateStatus.stable
+ eq_(self.obj.get_build_tag(), u'dist-f11-updates')
commit d58e1d2750c04706ab04809253af5f5f96037c20
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 13:46:44 2011 -0400
Add a custom BodhiRequest object so we can throw the 'user' on it, eventually.
diff --git a/pyramid/bodhi/bodhi/__init__.py b/pyramid/bodhi/bodhi/__init__.py
index 44189ca..f8cbaa3 100644
--- a/pyramid/bodhi/bodhi/__init__.py
+++ b/pyramid/bodhi/bodhi/__init__.py
@@ -1,13 +1,31 @@
-from pyramid.config import Configurator
from sqlalchemy import engine_from_config
+from pyramid.decorator import reify
+from pyramid.request import Request
+from pyramid.security import unauthenticated_userid
+from pyramid.config import Configurator
+
from bodhi.models import appmaker
+class BodhiRequest(Request):
+ @reify
+ def user(self):
+ # <your database connection, however you get it, the below line
+ # is just an example>
+ dbconn = self.registry.settings['dbconn']
+ userid = unauthenticated_userid(self)
+ if userid is not None:
+ # this should return None if the user doesn't exist
+ # in the database
+ return dbconn['users'].query({'id':userid})
+
+
def main(global_config, **settings):
""" This function returns a WSGI application """
engine = engine_from_config(settings, 'sqlalchemy.')
get_root = appmaker(engine)
config = Configurator(settings=settings, root_factory=get_root)
+ config.set_request_factory(BodhiRequest)
config.add_static_view('static', 'bodhi:static')
config.add_view('bodhi.views.view_root',
context='bodhi.models.Release',
commit a72186e9a6994554eff3fe55255df0833e0d6686
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 13:46:38 2011 -0400
Fix a few SQLAlchemy warnings
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index b5dccbc..e2674ac 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -495,12 +495,12 @@ class Update(Base):
"""
if self.status is UpdateStatus.stable:
self.comment(u'This update has been pushed to stable',
- author='bodhi')
+ author=u'bodhi')
elif self.status is UpdateStatus.testing:
self.comment(u'This update has been pushed to testing',
- author='bodhi')
+ author=u'bodhi')
elif self.status is UpdateStatus.obsolete:
- self.comment(u'This update has been obsoleted', author='bodhi')
+ self.comment(u'This update has been obsoleted', author=u'bodhi')
def send_update_notice(self):
log.debug("Sending update notice for %s" % self.title)
12 years, 12 months
Branch 'pyramid' - 3 commits - pyramid/bodhi
by Luke Macken
pyramid/bodhi/bodhi/models/models.py | 90 +++++++++---------------
pyramid/bodhi/bodhi/tests/models/test_models.py | 30 +++++++-
pyramid/bodhi/bodhi/util.py | 5 +
3 files changed, 70 insertions(+), 55 deletions(-)
New commits:
commit 6f9a376bee1f92a5b4bffa4dfe71cd2a0374410d
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 02:11:15 2011 -0400
Refactor and clean up our Update.set_request method.
Remove a lot of unnecessary code that [poorly] checks for broken
upgrade paths, now that we can rely on AutoQA for that.
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index 4f6ceb8..b5dccbc 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -379,23 +379,19 @@ class Update(Base):
DBSession.flush()
- def set_request(self, action, pathcheck=True):
+ def set_request(self, action):
""" Attempt to request an action for this update.
This method either sets the given request on this update, or raises
an InvalidRequest exception.
At the moment, this method cannot be called outside of a request.
-
- @param pathcheck: Check for broken update paths for stable requests
"""
if not authorized_user(self, identity):
raise InvalidRequest("Unauthorized to perform action on %s" %
self.title)
action = UpdateRequest.from_string(action)
- #if action not in ('testing', 'stable', 'obsolete', 'unpush'):
- # raise InvalidRequest("Unknown request: %s" % action)
- if action.description == self.status.description:
+ if action is self.status:
raise InvalidRequest("%s already %s" % (self.title,
action.description))
if action is self.request:
@@ -411,30 +407,17 @@ class Update(Base):
self.obsolete()
flash_log("%s has been obsoleted" % self.title)
return
- elif self.type is UpdateType.security and not self.approved:
- flash_log("%s is awaiting approval of the Security Team" %
- self.title)
- self.request = action
- return
- elif action is UpdateRequest.stable and pathcheck:
- # Make sure we don't break update paths by trying to push out
- # an update that is older than than the latest.
- koji = buildsys.get_session()
- for build in self.builds:
- mybuild = koji.getBuild(build.nvr)
- mybuild['nvr'] = "%s-%s-%s" % (mybuild['name'],
- mybuild['version'],
- mybuild['release'])
- kojiBuilds = koji.listTagged(self.release.dist_tag + '-updates',
- package=build.package.name,
- latest=True)
- for oldBuild in kojiBuilds:
- if rpm.labelCompare(build_evr(mybuild),
- build_evr(oldBuild)) < 0:
- raise InvalidRequest("Broken update path: %s is "
- "already released, and is newer "
- "than %s" % (oldBuild['nvr'],
- mybuild['nvr']))
+ # TODO:
+ # Make it so that we can optionally configure bodhi to require mandatory
+ # signoff from a specific group before an update can hit stable:
+ # eg: Security Team (for security updates)
+ # or
+ # AutoQA (for all updates)
+ #elif self.type is UpdateType.security and not self.date_approved:
+ # flash_log("%s is awaiting approval of the Security Team" %
+ # self.title)
+ # self.request = action
+ # return
self.request = action
self.pushed = False
self.date_pushed = None
@@ -449,19 +432,13 @@ class Update(Base):
Perform post-request actions.
"""
if self.request is UpdateRequest.testing:
- self.pushed = True
- self.date_pushed = datetime.utcnow()
- self.status = UpdateType.testing
- self.assign_alias()
- elif self.request is UpdateRequest.obsolete:
- self.pushed = False
- self.status = UpdateStatus.obsolete
+ self.status = UpdateStatus.testing
elif self.request is UpdateRequest.stable:
- self.pushed = True
- self.date_pushed = datetime.utcnow()
self.status = UpdateStatus.stable
- self.assign_alias()
self.request = None
+ self.pushed = True
+ self.date_pushed = datetime.utcnow()
+ self.assign_alias()
def modify_bugs(self):
"""
commit 3daa1164c6430f887f60317ebff93e1b6086da29
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 02:10:45 2011 -0400
More porting fixes and hacks
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index feec273..4f6ceb8 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -1,6 +1,7 @@
import os
import time
import logging
+import bugzilla
import xmlrpclib
import transaction
@@ -17,13 +18,17 @@ from sqlalchemy.ext.declarative import declarative_base, synonym_for
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound
-from bodhi.util import header, build_evr
from bodhi import buildsys, mail
+from bodhi.util import header, build_evr, authorized_user, rpm_fileheader, get_nvr, flash_log, get_age
+from bodhi.util import get_age_in_days # TODO: move these methods into the model
from bodhi.models.enum import DeclEnum
+from bodhi.exceptions import InvalidRequest, RPMNotFound
log = logging.getLogger(__name__)
config = {} # FIXME!
+from bunch import Bunch
+identity = Bunch(current=Bunch(user_name=u'Bob'))
class BodhiBase(object):
""" Our custom model base class """
@@ -39,6 +44,8 @@ DBSession = scoped_session(sessionmaker())
##
## Enumerated type declarations
+## Note: We're using single-letter names at the moment for compatiblity with
+## sqlite dbs
##
class UpdateStatus(DeclEnum):
@@ -292,8 +299,8 @@ class Update(Base):
@synonym_for('_title')
@property
- def title(self, delim=' '):
- title = ', '.join([build.package.name for build in self.builds])
+ def title(self, show_nvrs=True, delim=' '):
+ title = ', '.join([build.nvr for build in self.builds])
return title + ' %s update' % self.type.description
def get_title(self, delim=' '):
@@ -477,7 +484,7 @@ class Update(Base):
# Now, close our parents bugs as long as nothing else
# depends on them, and they are not in a NEW state
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
for bug in self.bugs:
if bug.parent:
parent = bz.getbug(bug.bug_id)
@@ -653,11 +660,11 @@ class Update(Base):
Create any new CVES, and remove any missing ones. Destroy removed CVES
that are no longer referenced anymore.
"""
+ Session = DBSession()
for cve in self.cves:
if cve.cve_id not in cves and len(cve.updates) == 0:
log.debug("Destroying stray CVE #%s" % cve.cve_id)
- session.delete(cve)
- session.flush()
+ Session.delete(cve)
for cve_id in cves:
try:
cve = CVE.query.filter_by(cve_id=cve_id).one()
@@ -666,9 +673,9 @@ class Update(Base):
except: # TODO: catch sqlalchemy's not found exception!
log.debug("Creating new CVE: %s" % cve_id)
cve = CVE(cve_id=cve_id)
- session.save(cve)
+ ession.save(cve)
self.cves.append(cve)
- session.flush()
+ Session.commit()
def get_pushed_age(self):
return get_age(self.date_pushed)
@@ -759,7 +766,7 @@ class Update(Base):
self.pushed = False
self.status = UpdateStatus.unpushed
mail.send_admin('unpushed', self)
- session.flush()
+ #DBSession.flush()
def untag(self):
""" Untag all of the builds in this update """
@@ -887,7 +894,7 @@ class Bug(Base):
def fetch_details(self, bug=None):
if not bug:
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
try:
bug = bz.getbug(self.bug_id)
except xmlrpclib.Fault, f:
@@ -919,7 +926,7 @@ class Bug(Base):
if not config.get('bodhi_email'):
log.warning("No bodhi_email defined; skipping bug comment")
return
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
if not comment:
comment = self._default_message(update)
log.debug("Adding comment to Bug #%d: %s" % (self.bug_id, comment))
@@ -935,7 +942,7 @@ class Bug(Base):
Change the status of this bug to ON_QA, and comment on the bug with
some details on how to test and provide feedback for this update.
"""
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
comment = self._default_message(update)
log.debug("Setting Bug #%d to ON_QA" % self.bug_id)
try:
@@ -945,7 +952,7 @@ class Bug(Base):
log.error("Unable to alter bug #%d\n%s" % (self.bug_id, str(e)))
def close_bug(self, update):
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
try:
ver = '-'.join(get_nvr(update.builds[0].nvr)[-2:])
bug = bz.getbug(self.bug_id)
diff --git a/pyramid/bodhi/bodhi/util.py b/pyramid/bodhi/bodhi/util.py
index 77d2ac2..ba18d05 100644
--- a/pyramid/bodhi/bodhi/util.py
+++ b/pyramid/bodhi/bodhi/util.py
@@ -123,6 +123,8 @@ def synchronized(lock):
return wrap
def authorized_user(update, identity):
+ # FIXME: port to pyramid auth
+ return True
return 'releng' in identity.current.groups or \
'cvsadmin' in identity.current.groups or \
'security_respons' in identity.current.groups or \
@@ -183,7 +185,8 @@ def get_age_in_days(date):
def flash_log(msg):
""" Flash and log a given message """
- flash(msg)
+ # FIXME: request.session.flash()
+ #flash(msg)
log.debug(msg)
def get_release_names():
commit 0c1babe14513dbf5fa44fdd68c7890864b31b119
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 02:09:53 2011 -0400
More model tests
diff --git a/pyramid/bodhi/bodhi/tests/models/test_models.py b/pyramid/bodhi/bodhi/tests/models/test_models.py
index 7d694b0..359695f 100644
--- a/pyramid/bodhi/bodhi/tests/models/test_models.py
+++ b/pyramid/bodhi/bodhi/tests/models/test_models.py
@@ -11,6 +11,7 @@ from sqlalchemy.exc import IntegrityError
from bodhi import models as model
from bodhi.models import UpdateStatus, UpdateType, UpdateRequest
from bodhi.tests.models import ModelTest
+from bodhi.exceptions import InvalidRequest
class TestRelease(ModelTest):
"""Unit test case for the ``Release`` model."""
@@ -140,7 +141,7 @@ class TestUpdate(ModelTest):
eq_(self.obj.builds[0].package.name, u'TurboGears')
def test_title(self):
- eq_(self.obj.title, u'TurboGears security update')
+ eq_(self.obj.title, u'TurboGears-1.0.8-3.fc11 security update')
def test_pkg_str(self):
""" Ensure str(pkg) is correct """
@@ -277,4 +278,31 @@ class TestUpdate(ModelTest):
assert update.bugs[0].bug_id == 4321
eq_(model.DBSession.query(model.Bug).filter_by(bug_id=1234).first(), None)
+ def test_set_request_unpush(self):
+ eq_(self.obj.status, UpdateStatus.pending)
+ self.obj.status = UpdateStatus.testing
+ self.obj.set_request('U')
+ eq_(self.obj.status, UpdateStatus.unpushed)
+
+ @raises(InvalidRequest)
+ def test_set_request_testing(self):
+ self.obj.set_request('T')
+
+ def test_set_request_stable(self):
+ eq_(self.obj.status, UpdateStatus.pending)
+ self.obj.set_request('S')
+ eq_(self.obj.status, UpdateStatus.pending)
+ # TODO: verify results (via session flash?)
+
+ def test_set_request_obsolete(self):
+ eq_(self.obj.status, UpdateStatus.pending)
+ self.obj.set_request('O')
+ eq_(self.obj.status, UpdateStatus.obsolete)
+
+ def test_request_complete(self):
+ eq_(self.obj.pushed, False)
+ eq_(self.obj.date_pushed, None)
+ eq_(self.obj.pushed, True)
+ assert self.obj.date_pushed
+
# test multibuild update
12 years, 12 months
bodhi/tests
by Luke Macken
bodhi/tests/test_controllers.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit 736ba0b90e3050cd82c0fd9e2a6c0908fb675500
Author: Luke Macken <lmacken(a)redhat.com>
Date: Wed May 11 23:22:03 2011 -0400
Fix a busted test case
diff --git a/bodhi/tests/test_controllers.py b/bodhi/tests/test_controllers.py
index 26ff015..e368025 100644
--- a/bodhi/tests/test_controllers.py
+++ b/bodhi/tests/test_controllers.py
@@ -967,7 +967,7 @@ class TestControllers(testutil.DBTest):
self.save_update(newparams, session)
newupdate = PackageUpdate.byTitle(newparams['builds'])
assert newupdate.status == 'pending'
- assert newupdate.notes in ('', None), newupdate.notes
+ assert newupdate.notes == 'foobar', newupdate.notes
update = PackageUpdate.byTitle(','.join(params['builds'].split()))
assert update.status == 'testing', update.status
12 years, 12 months