Remove mongodb-related stuff
[mediagoblin.git] / mediagoblin / tests / __init__.py
CommitLineData
8e1e744d 1# GNU MediaGoblin -- federated, autonomous media hosting
cf29e8a8 2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
5698a579
WKG
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
12c55944 16
de6a313c
BP
17import pytest
18
d88fcb03 19from mediagoblin.db.models import User, LocalUser
de6a313c
BP
20from mediagoblin.tests.tools import fixture_add_user
21from mediagoblin.tools import template
22
12c55944
E
23
24def setup_package():
29f1333e 25
601e6e0c
E
26 import warnings
27 from sqlalchemy.exc import SAWarning
28 warnings.simplefilter("error", SAWarning)
de6a313c
BP
29
30
31class MGClientTestCase:
32
33 usernames = None
34
35 @pytest.fixture(autouse=True)
36 def setup(self, test_app):
37 self.test_app = test_app
38
39 if self.usernames is None:
40 msg = ('The usernames attribute should be overridden '
41 'in the subclass')
42 raise pytest.skip(msg)
43 for username, options in self.usernames:
44 fixture_add_user(username, **options)
45
46 def user(self, username):
b4997540 47 return LocalUser.query.filter(LocalUser.username==username).first()
de6a313c
BP
48
49 def _do_request(self, url, *context_keys, **kwargs):
50 template.clear_test_template_context()
51 response = self.test_app.request(url, **kwargs)
52 context_data = template.TEMPLATE_TEST_CONTEXT
53 for key in context_keys:
54 context_data = context_data[key]
55 return response, context_data
56
57 def do_get(self, url, *context_keys, **kwargs):
58 kwargs['method'] = 'GET'
59 return self._do_request(url, *context_keys, **kwargs)
60
61 def do_post(self, url, *context_keys, **kwargs):
62 kwargs['method'] = 'POST'
63 return self._do_request(url, *context_keys, **kwargs)