diff options
Diffstat (limited to 'mediagoblin/tests/test_api.py')
-rw-r--r-- | mediagoblin/tests/test_api.py | 43 |
1 files changed, 7 insertions, 36 deletions
diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index 55228edc..88d86053 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -14,22 +14,16 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import json -import datetime import mock -import pytz import pytest from webtest import AppError -from werkzeug.datastructures import FileStorage from .resources import GOOD_JPG from mediagoblin import mg_globals -from mediagoblin.media_types import sniff_media from mediagoblin.db.models import User, MediaEntry -from mediagoblin.submit.lib import new_upload_entry from mediagoblin.tests.tools import fixture_add_user -from mediagoblin.federation.task import collect_garbage from mediagoblin.moderation.tools import take_away_privileges class TestAPI(object): @@ -40,7 +34,7 @@ class TestAPI(object): self.test_app = test_app self.db = mg_globals.database - self.user = fixture_add_user(privileges=[u'active', u'uploader']) + self.user = fixture_add_user(privileges=[u'active', u'uploader', u'commenter']) def _activity_to_feed(self, test_app, activity, headers=None): """ Posts an activity to the user's feed """ @@ -265,32 +259,9 @@ class TestAPI(object): assert "links" in profile - def test_garbage_collection_task(self, test_app): - """ Test old media entry are removed by GC task """ - # Create a media entry that's unprocessed and over an hour old. - entry_id = 72 - now = datetime.datetime.now(pytz.UTC) - file_data = FileStorage( - stream=open(GOOD_JPG, "rb"), - filename="mah_test.jpg", - content_type="image/jpeg" - ) - - # Find media manager - media_type, media_manager = sniff_media(file_data, "mah_test.jpg") - entry = new_upload_entry(self.user) - entry.id = entry_id - entry.title = "Mah Image" - entry.slug = "slugy-slug-slug" - entry.media_type = 'image' - entry.uploaded = now - datetime.timedelta(days=2) - entry.save() - - # Validate the model exists - assert MediaEntry.query.filter_by(id=entry_id).first() is not None - - # Call the garbage collection task - collect_garbage() - - # Now validate the image has been deleted - assert MediaEntry.query.filter_by(id=entry_id).first() is None + def test_whoami_without_login(self, test_app): + """ Test that whoami endpoint returns error when not logged in """ + with pytest.raises(AppError) as excinfo: + response = test_app.get("/api/whoami") + + assert "401 UNAUTHORIZED" in excinfo.value.message |