2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # 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 (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
21 from copy
import deepcopy
23 from django
.test
.client
import Client
24 from django
.core
.urlresolvers
import reverse
26 from mygpo
.api
.advanced
import episodes
27 from mygpo
.users
.models
import User
28 from mygpo
.test
import create_auth_string
29 from mygpo
.core
.json
import json
32 class LegacyAPITests(unittest
.TestCase
):
36 class AdvancedAPITests(unittest
.TestCase
):
39 self
.password
= 'asdf'
40 self
.username
= 'user'
41 self
.user
= User(username
=self
.username
, email
='user@example.com')
42 self
.user
.set_password(self
.password
)
44 self
.user
.is_active
= True
45 self
.client
= Client()
48 'HTTP_AUTHORIZATION': create_auth_string(self
.username
, self
.password
)
53 "podcast": "http://example.com/feed.rss",
54 "episode": "http://example.com/files/s01e20.mp3",
55 "device": "gpodder_abcdef123",
57 "timestamp": "2009-12-12T09:00:00"
60 "podcast": "http://example.org/podcast.php",
61 "episode": "http://ftp.example.org/foo.ogg",
75 def test_episode_actions(self
):
76 url
= reverse(episodes
, kwargs
=dict(version
='2', username
=self
.user
.username
))
79 response
= self
.client
.post(url
, json
.dumps(self
.action_data
),
80 content_type
="application/json", **self
.extra
)
81 self
.assertEqual(response
.status_code
, 200, response
.content
)
85 extra
= deepcopy(self
.extra
)
88 response
= self
.client
.get(url
, **extra
)
89 self
.assertEqual(response
.status_code
, 200, response
.content
)
90 response_obj
= json
.loads(response
.content
)
91 actions
= response_obj
['actions']
92 self
.assertTrue(self
.compare_action_list(self
.action_data
, actions
))
95 def compare_action_list(self
, as1
, as2
):
99 if self
.compare_actions(a1
, a2
):
103 raise ValueError('%s not found in %s' % (a1
, as2
))
109 def compare_actions(self
, a1
, a2
):
110 for key
, val
in a1
.items():
111 if a2
.get(key
, None) != val
:
116 suite
= unittest
.TestSuite()
117 suite
.addTest(unittest
.TestLoader().loadTestsFromTestCase(AdvancedAPITests
))