diff --git a/mediagoblin/db/base.py b/mediagoblin/db/base.py
index 699a503..bd4738b 100644
a
|
b
|
class GMGTableBase(object):
|
29 | 29 | return cls.query.filter_by(**query_dict) |
30 | 30 | |
31 | 31 | @classmethod |
32 | | def find_one(cls, query_dict): |
33 | | return cls.query.filter_by(**query_dict).first() |
34 | | |
35 | | @classmethod |
36 | 32 | def one(cls, query_dict): |
37 | 33 | return cls.find(query_dict).one() |
38 | 34 | |
diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py
index ece222f..ca7be53 100644
a
|
b
|
def user_may_alter_collection(controller):
|
87 | 87 | """ |
88 | 88 | @wraps(controller) |
89 | 89 | def wrapper(request, *args, **kwargs): |
90 | | creator_id = request.db.User.find_one( |
91 | | {'username': request.matchdict['user']}).id |
| 90 | creator_id = request.db.User.query.filter_by( |
| 91 | username=request.matchdict['user']).first().id |
92 | 92 | if not (request.user.is_admin or |
93 | 93 | request.user.id == creator_id): |
94 | 94 | raise Forbidden() |
… |
… |
def get_user_collection(controller):
|
162 | 162 | """ |
163 | 163 | @wraps(controller) |
164 | 164 | def wrapper(request, *args, **kwargs): |
165 | | user = request.db.User.find_one( |
166 | | {'username': request.matchdict['user']}) |
| 165 | user = request.db.User.query.filter_by( |
| 166 | username=request.matchdict['user']).first() |
167 | 167 | |
168 | 168 | if not user: |
169 | 169 | return render_404(request) |
170 | 170 | |
171 | | collection = request.db.Collection.find_one( |
172 | | {'slug': request.matchdict['collection'], |
173 | | 'creator': user.id}) |
| 171 | collection = request.db.Collection.query.filter_by( |
| 172 | slug=request.matchdict['collection'], |
| 173 | creator=user.id).first() |
174 | 174 | |
175 | 175 | # Still no collection? Okay, 404. |
176 | 176 | if not collection: |
… |
… |
def get_user_collection_item(controller):
|
187 | 187 | """ |
188 | 188 | @wraps(controller) |
189 | 189 | def wrapper(request, *args, **kwargs): |
190 | | user = request.db.User.find_one( |
191 | | {'username': request.matchdict['user']}) |
| 190 | user = request.db.User.query.filter_by( |
| 191 | username=request.matchdict['user']).first() |
192 | 192 | |
193 | 193 | if not user: |
194 | 194 | return render_404(request) |
195 | 195 | |
196 | | collection_item = request.db.CollectionItem.find_one( |
197 | | {'id': request.matchdict['collection_item'] }) |
| 196 | collection_item = request.db.CollectionItem.query.filter_by( |
| 197 | id=request.matchdict['collection_item']).first() |
198 | 198 | |
199 | 199 | # Still no collection item? Okay, 404. |
200 | 200 | if not collection_item: |
diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py
index 7a8d618..6aa2acd 100644
a
|
b
|
def edit_collection(request, collection):
|
305 | 305 | form.slug.data, collection.id) |
306 | 306 | |
307 | 307 | # Make sure there isn't already a Collection with this title |
308 | | existing_collection = request.db.Collection.find_one({ |
309 | | 'creator': request.user.id, |
310 | | 'title':form.title.data}) |
| 308 | existing_collection = request.db.Collection.query.filter_by( |
| 309 | creator=request.user.id, |
| 310 | title=form.title.data).first() |
311 | 311 | |
312 | 312 | if existing_collection and existing_collection.id != collection.id: |
313 | 313 | messages.add_message( |
diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py
index 64e6791..11d0d06 100644
a
|
b
|
def add_collection(request, media=None):
|
133 | 133 | collection.generate_slug() |
134 | 134 | |
135 | 135 | # Make sure this user isn't duplicating an existing collection |
136 | | existing_collection = request.db.Collection.find_one({ |
137 | | 'creator': request.user.id, |
138 | | 'title':collection.title}) |
| 136 | existing_collection = request.db.Collection.query.filter_by( |
| 137 | creator=request.user.id, |
| 138 | title=collection.title).first() |
139 | 139 | |
140 | 140 | if existing_collection: |
141 | 141 | add_message(request, messages.ERROR, |
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py
index 5bd8bf2..61503d3 100644
a
|
b
|
def test_register_views(test_app):
|
93 | 93 | assert 'mediagoblin/user_pages/user.html' in template.TEMPLATE_TEST_CONTEXT |
94 | 94 | |
95 | 95 | ## Make sure user is in place |
96 | | new_user = mg_globals.database.User.find_one( |
97 | | {'username': u'happygirl'}) |
| 96 | new_user = mg_globals.database.User.query.filter_by( |
| 97 | username=u'happygirl').first() |
98 | 98 | assert new_user |
99 | 99 | assert new_user.status == u'needs_email_verification' |
100 | 100 | assert new_user.email_verified == False |
… |
… |
def test_register_views(test_app):
|
128 | 128 | |
129 | 129 | # assert context['verification_successful'] == True |
130 | 130 | # TODO: Would be good to test messages here when we can do so... |
131 | | new_user = mg_globals.database.User.find_one( |
132 | | {'username': u'happygirl'}) |
| 131 | new_user = mg_globals.database.User.query.filter_by( |
| 132 | username=u'happygirl').first() |
133 | 133 | assert new_user |
134 | 134 | assert new_user.status == u'needs_email_verification' |
135 | 135 | assert new_user.email_verified == False |
… |
… |
def test_register_views(test_app):
|
142 | 142 | 'mediagoblin/user_pages/user.html'] |
143 | 143 | # assert context['verification_successful'] == True |
144 | 144 | # TODO: Would be good to test messages here when we can do so... |
145 | | new_user = mg_globals.database.User.find_one( |
146 | | {'username': u'happygirl'}) |
| 145 | new_user = mg_globals.database.User.query.filter_by( |
| 146 | username=u'happygirl').first() |
147 | 147 | assert new_user |
148 | 148 | assert new_user.status == u'active' |
149 | 149 | assert new_user.email_verified == True |
diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py
index acc638d..d70d047 100644
a
|
b
|
class TestUserEdit(object):
|
190 | 190 | assert urlparse.urlsplit(res.location)[2] == '/' |
191 | 191 | |
192 | 192 | # Email shouldn't be saved |
193 | | email_in_db = mg_globals.database.User.find_one( |
194 | | {'email': 'new@example.com'}) |
| 193 | email_in_db = mg_globals.database.User.query.filter_by( |
| 194 | email='new@example.com').first() |
195 | 195 | email = User.query.filter_by(username='chris').first().email |
196 | 196 | assert email_in_db is None |
197 | 197 | assert email == 'chris@example.com' |
diff --git a/mediagoblin/tests/test_openid.py b/mediagoblin/tests/test_openid.py
index c85f631..bba46db 100644
a
|
b
|
class TestOpenIDPlugin(object):
|
186 | 186 | openid_plugin_app.get('/auth/logout') |
187 | 187 | |
188 | 188 | # Get user and detach from session |
189 | | test_user = mg_globals.database.User.find_one({ |
190 | | 'username': u'chris'}) |
| 189 | test_user = mg_globals.database.User.query.filter_by( |
| 190 | username=u'chris').first() |
191 | 191 | Session.expunge(test_user) |
192 | 192 | |
193 | 193 | # Log back in |
… |
… |
class TestOpenIDPlugin(object):
|
314 | 314 | assert 'mediagoblin/edit/edit_account.html' in template.TEMPLATE_TEST_CONTEXT |
315 | 315 | |
316 | 316 | # OpenID Added? |
317 | | new_openid = mg_globals.database.OpenIDUserURL.find_one( |
318 | | {'openid_url': u'http://add.myopenid.com'}) |
| 317 | new_openid = mg_globals.database.OpenIDUserURL.query.filter_by( |
| 318 | openid_url=u'http://add.myopenid.com').first() |
319 | 319 | assert new_openid |
320 | 320 | |
321 | 321 | _test_add() |
… |
… |
class TestOpenIDPlugin(object):
|
365 | 365 | assert 'mediagoblin/edit/edit_account.html' in template.TEMPLATE_TEST_CONTEXT |
366 | 366 | |
367 | 367 | # OpenID deleted? |
368 | | new_openid = mg_globals.database.OpenIDUserURL.find_one( |
369 | | {'openid_url': u'http://add.myopenid.com'}) |
| 368 | new_openid = mg_globals.database.OpenIDUserURL.query.filter_by( |
| 369 | openid_url=u'http://add.myopenid.com').first() |
370 | 370 | assert not new_openid |
371 | 371 | |
372 | 372 | _test_delete(self, test_user) |
diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
index 162b2d1..45678a4 100644
a
|
b
|
class TestSubmission:
|
240 | 240 | |
241 | 241 | request = context['request'] |
242 | 242 | |
243 | | media = request.db.MediaEntry.find_one({ |
244 | | u'title': u'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE'}) |
| 243 | media = request.db.MediaEntry.query.filter_by( |
| 244 | title=u'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE').first() |
245 | 245 | |
246 | 246 | assert media.media_type == 'mediagoblin.media_types.image' |
247 | 247 | |
… |
… |
class TestSubmission:
|
252 | 252 | response, context = self.do_post({'title': title}, do_follow=True, |
253 | 253 | **self.upload_data(filename)) |
254 | 254 | self.check_url(response, '/u/{0}/'.format(self.test_user.username)) |
255 | | entry = mg_globals.database.MediaEntry.find_one({'title': title}) |
| 255 | entry = mg_globals.database.MediaEntry.query.filter_by(title=title).first() |
256 | 256 | assert entry.state == 'failed' |
257 | 257 | assert entry.fail_error == u'mediagoblin.processing:BadMediaFail' |
258 | 258 | |
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 2584c62..98361ad 100644
a
|
b
|
def assert_db_meets_expected(db, expected):
|
164 | 164 | for collection_name, collection_data in expected.iteritems(): |
165 | 165 | collection = db[collection_name] |
166 | 166 | for expected_document in collection_data: |
167 | | document = collection.find_one({'id': expected_document['id']}) |
| 167 | document = collection.query.filter_by(id=expected_document['id']).first() |
168 | 168 | assert document is not None # make sure it exists |
169 | 169 | assert document == expected_document # make sure it matches |
170 | 170 | |