Rename test_joarapi.py => test_legacy_api.py
[mediagoblin.git] / mediagoblin / tests / test_api.py
CommitLineData
57c6473a
JW
1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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/>.
16
247a3b78 17import urllib
57c6473a 18
5c2ece74 19import pytest
247a3b78 20import mock
21
22from oauthlib.oauth1 import Client
5c2ece74 23
57c6473a 24from mediagoblin import mg_globals
5c2ece74 25from mediagoblin.tests.tools import fixture_add_user
247a3b78 26from .resources import GOOD_JPG
57c6473a
JW
27
28class TestAPI(object):
247a3b78 29
958080be 30 def setup(self):
57c6473a 31 self.db = mg_globals.database
247a3b78 32 self.user = fixture_add_user()
33
34 def test_profile_endpoint(self, test_app):
35 """ Test that you can successfully get the profile of a user """
36 @mock.patch("mediagoblin.decorators.oauth_required")
37 def _real_test(*args, **kwargs):
38 profile = test_app.get(
39 "/api/user/{0}/profile".format(self.user.username)
40 ).json
41
42 assert profile["preferredUsername"] == self.user.username
43 assert profile["objectType"] == "person"
44
45 _real_test()
46
47 def test_upload_file(self, test_app):
48 """ Test that i can upload a file """
49 context = {
50 "title": "Rel",
51 "description": "ayRel sunu oeru",
52 "qqfile": "my_picture.jpg",
53 }
54 encoded_context = urllib.urlencode(context)
55 response = test_app.post(
56 "/api/user/{0}/uploads?{1}".format(
57 self.user.username,
58 encoded_context[1:]
59 )
60 )
61
62 picture = self.db.MediaEntry.query.filter_by(title=context["title"])
63 picture = picture.first()
57c6473a
JW
64
65 assert response.status_int == 200
247a3b78 66 assert picture
67 raise Exception(str(dir(picture)))
68 assert picture.description == context["description"]
69
57c6473a 70