Use urljoin to create proper feed media URLs
[larjonas-mediagoblin.git] / mediagoblin / tests / __init__.py
blob651dac24284c3a94e915df22db072daffe3314b3
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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.
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.
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/>.
17 import pytest
19 from mediagoblin.db.models import User, LocalUser
20 from mediagoblin.tests.tools import fixture_add_user
21 from mediagoblin.tools import template
24 def setup_package():
26 import warnings
27 from sqlalchemy.exc import SAWarning
28 warnings.simplefilter("error", SAWarning)
31 class MGClientTestCase:
33 usernames = None
35 @pytest.fixture(autouse=True)
36 def setup(self, test_app):
37 self.test_app = test_app
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)
46 def user(self, username):
47 return LocalUser.query.filter(LocalUser.username==username).first()
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
57 def do_get(self, url, *context_keys, **kwargs):
58 kwargs['method'] = 'GET'
59 return self._do_request(url, *context_keys, **kwargs)
61 def do_post(self, url, *context_keys, **kwargs):
62 kwargs['method'] = 'POST'
63 return self._do_request(url, *context_keys, **kwargs)