diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-04-04 19:23:04 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-04-04 19:23:04 -0500 |
commit | 5c2ece7401723486d76ea0fcd2f99ba4d1002504 (patch) | |
tree | a71a2bf9b15bd2805e344362e0bd265d7a124910 /mediagoblin/tests/test_api.py | |
parent | e11c62a0efeb053f71f8ab0793c7399ce8b0758d (diff) | |
download | mediagoblin-5c2ece7401723486d76ea0fcd2f99ba4d1002504.tar.lz mediagoblin-5c2ece7401723486d76ea0fcd2f99ba4d1002504.tar.xz mediagoblin-5c2ece7401723486d76ea0fcd2f99ba4d1002504.zip |
Switch test_app generation over to use py.test fixtures.
By doing this, we can take advantage of py.test's ability to create
temporary directories that are then cleaned up later during testing.
This helps for sandboxing things.
This also involves a ton of changes:
- Changing the get_app stuff appropriately, getting rid of the
setup_fresh_app decorator
- Making said fixture
- Switching over a billion tests to use it
Diffstat (limited to 'mediagoblin/tests/test_api.py')
-rw-r--r-- | mediagoblin/tests/test_api.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index 294cc4ef..25ce852b 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -20,9 +20,11 @@ import base64 from pkg_resources import resource_filename +import pytest + from mediagoblin import mg_globals from mediagoblin.tools import template, pluginapi -from mediagoblin.tests.tools import get_app, fixture_add_user +from mediagoblin.tests.tools import fixture_add_user _log = logging.getLogger(__name__) @@ -42,16 +44,16 @@ EVIL_PNG = resource('evil.png') BIG_BLUE = resource('bigblue.png') +@pytest.mark.usefixtures("test_app") class TestAPI(object): def setup(self): - self.app = get_app(dump_old_app=False) self.db = mg_globals.database self.user_password = u'4cc355_70k3N' self.user = fixture_add_user(u'joapi', self.user_password) - def login(self): - self.app.post( + def login(self, test_app): + test_app.post( '/auth/login/', { 'username': self.user.username, 'password': self.user_password}) @@ -65,14 +67,14 @@ class TestAPI(object): self.user.username, self.user_password])))} - def do_post(self, data, **kwargs): + def do_post(self, data, test_app, **kwargs): url = kwargs.pop('url', '/api/submit') do_follow = kwargs.pop('do_follow', False) if not 'headers' in kwargs.keys(): kwargs['headers'] = self.http_auth_headers() - response = self.app.post(url, data, **kwargs) + response = test_app.post(url, data, **kwargs) if do_follow: response.follow() @@ -82,21 +84,22 @@ class TestAPI(object): def upload_data(self, filename): return {'upload_files': [('file', filename)]} - def test_1_test_test_view(self): - self.login() + def test_1_test_test_view(self, test_app): + self.login(test_app) - response = self.app.get( + response = test_app.get( '/api/test', headers=self.http_auth_headers()) assert response.body == \ '{"username": "joapi", "email": "joapi@example.com"}' - def test_2_test_submission(self): - self.login() + def test_2_test_submission(self, test_app): + self.login(test_app) response = self.do_post( {'title': 'Great JPG!'}, + test_app, **self.upload_data(GOOD_JPG)) assert response.status_int == 200 |