This file is indexed.

/usr/share/pyshared/mygpoclient/api_test.py is in python-mygpoclient 1.7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# -*- coding: utf-8 -*-
# gpodder.net API Client
# Copyright (C) 2009-2013 Thomas Perl and the gPodder Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import mygpoclient

from mygpoclient import api
from mygpoclient import testing

import unittest

# Example data for testing purposes
FEED_URL_1 = 'http://example.com/test.rss'
FEED_URL_2 = 'http://feeds.example.org/1/feed.atom'
FEED_URL_3 = 'http://example.co.uk/episodes.xml'
FEED_URL_4 = 'http://pod.cast/test.xml'

EPISODE_URL_1 = 'http://dl.example.net/episodes/one.mp3'
EPISODE_URL_2 = 'http://pod.cast.invalid/downloads/s02e04.ogg'
EPISODE_URL_3 = 'http://example.org/05-skylarking.m4v'
EPISODE_URL_4 = 'http://www.example.com/test/me_now.avi'

DEVICE_ID_1 = 'gpodder.on.my.phone'
DEVICE_ID_2 = '95dce59cf340123fa'

class Test_SubscriptionChanges(unittest.TestCase):
    ADD = [
            FEED_URL_1,
            FEED_URL_3,
    ]
    REMOVE = [
            FEED_URL_2,
            FEED_URL_4,
    ]
    SINCE = 1262101867

    def test_initSetsCorrectAttributes(self):
        changes = api.SubscriptionChanges(self.ADD, self.REMOVE, self.SINCE)
        self.assertEquals(changes.add, self.ADD)
        self.assertEquals(changes.remove, self.REMOVE)
        self.assertEquals(changes.since, self.SINCE)


class Test_EpisodeActionChanges(unittest.TestCase):
    ACTIONS = [
            api.EpisodeAction(FEED_URL_1, EPISODE_URL_1, 'download'),
            api.EpisodeAction(FEED_URL_2, EPISODE_URL_3, 'play'),
            api.EpisodeAction(FEED_URL_2, EPISODE_URL_4, 'delete'),
    ]
    SINCE = 1262102013

    def test_initSetsCorrectAttributes(self):
        changes = api.EpisodeActionChanges(self.ACTIONS, self.SINCE)
        self.assertEquals(changes.actions, self.ACTIONS)
        self.assertEquals(changes.since, self.SINCE)


class Test_PodcastDevice(unittest.TestCase):
    CAPTION = 'My Nice Device'

    def test_initSetsCorrectAttributes(self):
        device = api.PodcastDevice(DEVICE_ID_1, self.CAPTION, 'mobile', 42)
        self.assertEquals(device.device_id, DEVICE_ID_1)
        self.assertEquals(device.caption, self.CAPTION)
        self.assertEquals(device.type, 'mobile')
        self.assertEquals(device.subscriptions, 42)

    def test_invalidDeviceType_raisesValueError(self):
        self.assertRaises(ValueError,
                api.PodcastDevice, DEVICE_ID_2, self.CAPTION,
                'does-not-exist', 1337)

    def test_nonNumericSubscriptions_raisesValueError(self):
        self.assertRaises(ValueError,
                api.PodcastDevice, DEVICE_ID_1, self.CAPTION,
                'laptop', 'notanumber')


class Test_EpisodeAction(unittest.TestCase):
    XML_TIMESTAMP = '2009-12-12T09:00:00'
    VALID_STARTED = 100
    VALID_POSITION = 123
    VALID_TOTAL = 321

    def test_initSetsCorrectAttributes(self):
        action = api.EpisodeAction(FEED_URL_1, EPISODE_URL_1, 'play',
                DEVICE_ID_1, self.XML_TIMESTAMP, self.VALID_STARTED,
                self.VALID_POSITION, self.VALID_TOTAL)
        self.assertEquals(action.podcast, FEED_URL_1)
        self.assertEquals(action.episode, EPISODE_URL_1)
        self.assertEquals(action.action, 'play')
        self.assertEquals(action.device, DEVICE_ID_1)
        self.assertEquals(action.timestamp, self.XML_TIMESTAMP)
        self.assertEquals(action.started, self.VALID_STARTED)
        self.assertEquals(action.position, self.VALID_POSITION)
        self.assertEquals(action.total, self.VALID_TOTAL)

    def test_invalidAction_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_2, EPISODE_URL_3, 'invalidaction',
                DEVICE_ID_2, self.XML_TIMESTAMP)

    def test_startedIsSetWithNoPlayAction_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_4, EPISODE_URL_2, 'download',
                DEVICE_ID_1, self.XML_TIMESTAMP, self.VALID_STARTED)
        
    def test_positionIsSetWithNoPlayAction_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_4, EPISODE_URL_2, 'download',
                DEVICE_ID_1, self.XML_TIMESTAMP, None, self.VALID_POSITION)
    
    def test_totalIsSetWithNoPlayAction_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_4, EPISODE_URL_2, 'download',
                DEVICE_ID_1, self.XML_TIMESTAMP, None, None, self.VALID_TOTAL)
        
    def test_invalidTimestampFormat_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_3, EPISODE_URL_3, 'delete',
                DEVICE_ID_2, 'today')

    def test_onlyStartedSet_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_1, EPISODE_URL_4, 'play',
                DEVICE_ID_1, self.XML_TIMESTAMP, self.VALID_STARTED)

    def test_invalidStartedFormat_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_1, EPISODE_URL_4, 'play',
                DEVICE_ID_1, self.XML_TIMESTAMP, '10 minutes into the show', self.VALID_POSITION)
        
    def test_invalidPositionFormat_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_1, EPISODE_URL_4, 'play',
                DEVICE_ID_1, self.XML_TIMESTAMP, self.VALID_STARTED, '15 minutes later')

    def test_invalidTotalFormat_raisesValueError(self):
        self.assertRaises(ValueError,
                api.EpisodeAction, FEED_URL_1, EPISODE_URL_4, 'play',
                DEVICE_ID_1, self.XML_TIMESTAMP, None, self.VALID_POSITION, '30 minutes total')

    def test_toDictionary_containsMandatoryAttributes(self):
        action = api.EpisodeAction(FEED_URL_1, EPISODE_URL_1, 'play')
        dictionary = action.to_dictionary()
        self.assertEquals(len(dictionary.keys()), 3)
        self.assert_('podcast' in dictionary)
        self.assert_('episode' in dictionary)
        self.assert_('action' in dictionary)
        self.assertEquals(dictionary['podcast'], FEED_URL_1)
        self.assertEquals(dictionary['episode'], EPISODE_URL_1)
        self.assertEquals(dictionary['action'], 'play')

    def test_toDictionary_containsAllAttributes(self):
        action = api.EpisodeAction(FEED_URL_3, EPISODE_URL_4, 'play',
                DEVICE_ID_1, self.XML_TIMESTAMP, self.VALID_STARTED,
                self.VALID_POSITION, self.VALID_TOTAL)
        dictionary = action.to_dictionary()
        self.assertEquals(len(dictionary.keys()), 8)
        self.assert_('podcast' in dictionary)
        self.assert_('episode' in dictionary)
        self.assert_('action' in dictionary)
        self.assert_('device' in dictionary)
        self.assert_('timestamp' in dictionary)
        self.assert_('started' in dictionary)
        self.assert_('position' in dictionary)
        self.assert_('total' in dictionary)
        self.assertEquals(dictionary['podcast'], FEED_URL_3)
        self.assertEquals(dictionary['episode'], EPISODE_URL_4)
        self.assertEquals(dictionary['action'], 'play')
        self.assertEquals(dictionary['device'], DEVICE_ID_1)
        self.assertEquals(dictionary['timestamp'], self.XML_TIMESTAMP)
        self.assertEquals(dictionary['started'], self.VALID_STARTED)
        self.assertEquals(dictionary['position'], self.VALID_POSITION)
        self.assertEquals(dictionary['total'], self.VALID_TOTAL)


class Test_MygPodderClient(unittest.TestCase):
    ADD = [
            FEED_URL_1,
            FEED_URL_3,
    ]
    REMOVE = [
            FEED_URL_2,
            FEED_URL_4,
    ]
    ADD_REMOVE_AS_JSON_UPLOAD = {
            'add': [FEED_URL_1, FEED_URL_3],
            'remove': [FEED_URL_2, FEED_URL_4],
    }
    ACTIONS = [
            api.EpisodeAction(FEED_URL_1, EPISODE_URL_1, 'download'),
            api.EpisodeAction(FEED_URL_2, EPISODE_URL_3, 'play'),
            api.EpisodeAction(FEED_URL_2, EPISODE_URL_4, 'delete'),
    ]
    ACTIONS_AS_JSON_UPLOAD = [
            {'podcast': FEED_URL_1, 'episode': EPISODE_URL_1, 'action': 'download'},
            {'podcast': FEED_URL_2, 'episode': EPISODE_URL_3, 'action': 'play'},
            {'podcast': FEED_URL_2, 'episode': EPISODE_URL_4, 'action': 'delete'},
    ]
    USERNAME = 'user01'
    PASSWORD = 's3cret'
    SINCE = 1262103016

    def setUp(self):
        self.fake_client = testing.FakeJsonClient()
        self.client = api.MygPodderClient(self.USERNAME, self.PASSWORD,
                client_class=self.fake_client)

    def set_http_response_value(self, value):
        self.fake_client.response_value = value

    def assert_http_request_count(self, count):
        self.assertEquals(len(self.fake_client.requests), count)

    def has_put_json_data(self, data, required_method='PUT'):
        """Returns True if the FakeJsonClient has received the given data"""
        for method, uri, sent in self.fake_client.requests:
            if method == required_method:
                self.assertEquals(sent, data)
                return True

        return False

    def has_posted_json_data(self, data):
        """Same as has_put_json_data, but require a POST request"""
        return self.has_put_json_data(data, required_method='POST')

    def test_getSubscriptions_withPodcastDevice(self):
        self.set_http_response_value('[]')
        device = api.PodcastDevice('manatee', 'My Device', 'mobile', 20)
        self.assertEquals(self.client.get_subscriptions(device), [])
        self.assert_http_request_count(1)

    def test_putSubscriptions_withPodcastDevice(self):
        self.set_http_response_value('')
        device = api.PodcastDevice('manatee', 'My Device', 'mobile', 20)
        self.assertEquals(self.client.put_subscriptions(device, self.ADD), True)
        self.assert_http_request_count(1)
        self.assert_(self.has_put_json_data(self.ADD))

    def test_updateSubscriptions_raisesValueError_onInvalidAddList(self):
        self.assertRaises(ValueError,
                self.client.update_subscriptions, DEVICE_ID_2,
                [FEED_URL_1, 123, FEED_URL_3], self.REMOVE)

    def test_updateSubscriptions_raisesValueError_onInvalidRemoveList(self):
        self.assertRaises(ValueError,
                self.client.update_subscriptions, DEVICE_ID_2,
                self.ADD, [FEED_URL_2, FEED_URL_4, [1, 2, 3]])

    def test_updateSubscriptions_raisesInvalidResponse_onEmptyResponse(self):
        self.set_http_response_value('')
        self.assertRaises(api.InvalidResponse,
                self.client.update_subscriptions, DEVICE_ID_1,
                self.ADD, self.REMOVE)

    def test_updateSubscriptions_raisesInvalidResponse_onMissingTimestamp(self):
        self.set_http_response_value('{}')
        self.assertRaises(api.InvalidResponse,
                self.client.update_subscriptions, DEVICE_ID_1,
                self.ADD, self.REMOVE)

    def test_updateSubscriptions_raisesInvalidResponse_onInvalidTimestamp(self):
        self.set_http_response_value("""
        {"timestamp": "not gonna happen"}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.update_subscriptions, DEVICE_ID_1,
                self.ADD, self.REMOVE)

    def test_updateSubscriptions_raisesInvalidResponse_withoutUpdateUrls(self):
        self.set_http_response_value("""
        {"timestamp": 1262103016}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.update_subscriptions, DEVICE_ID_1,
                self.ADD, self.REMOVE)

    def test_updateSubscriptions_raisesInvalidResponse_withNonStringList(self):
        self.set_http_response_value("""
        {"timestamp": 1262103016, "update_urls": [
            ["http://example.com/", 2],
            [56, "http://example.org/"]
        ]}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.update_subscriptions, DEVICE_ID_2,
                self.ADD, self.REMOVE)

    def test_updateSubscriptions_raisesInvalidResponse_withInvalidList(self):
        self.set_http_response_value("""
        {"timestamp": 1262103016, "update_urls": [
            ["test", "test2", "test3"],
            ["test", "test2"]
        ]}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.update_subscriptions, DEVICE_ID_2,
                self.ADD, self.REMOVE)

    def test_updateSubscriptions_returnsUpdateResult(self):
        self.set_http_response_value("""
        {"timestamp": 1262103016, "update_urls": [
            ["http://test2.invalid/feed.rss",
             "http://test2.invalid/feed.rss"],
            ["http://x.invalid/episodes.xml?format=2",
             "http://x.invalid/episodes.xml"]
        ]}
        """)
        update_urls_expected = [
                ('http://test2.invalid/feed.rss',
                 'http://test2.invalid/feed.rss'),
                ('http://x.invalid/episodes.xml?format=2',
                 'http://x.invalid/episodes.xml'),
        ]

        result = self.client.update_subscriptions(DEVICE_ID_1,
                self.ADD, self.REMOVE)
        # result is a UpdateResult object
        self.assert_(hasattr(result, 'since'))
        self.assert_(hasattr(result, 'update_urls'))
        self.assertEquals(result.since, self.SINCE)
        self.assertEquals(result.update_urls, update_urls_expected)
        self.assert_http_request_count(1)
        self.assert_(self.has_posted_json_data(self.ADD_REMOVE_AS_JSON_UPLOAD))

    def test_pullSubscriptions_raisesInvalidResponse_onEmptyResponse(self):
        self.set_http_response_value('')
        self.assertRaises(api.InvalidResponse,
                self.client.pull_subscriptions, DEVICE_ID_2)

    def test_pullSubscriptions_raisesInvalidResponse_onMissingTimestamp(self):
        self.set_http_response_value("""
        {"add": [
            "http://example.com/test.rss",
            "http://feeds.example.org/1/feed.atom"
        ],
        "remove": [
            "http://example.co.uk/episodes.xml",
            "http://pod.cast/test.xml"
        ]}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.pull_subscriptions, DEVICE_ID_2)

    def test_pullSubscriptions_raisesInvalidResponse_onMissingAddList(self):
        self.set_http_response_value("""
        {"remove": [
            "http://example.co.uk/episodes.xml",
            "http://pod.cast/test.xml"
        ],
        "timestamp": 1262103016}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.pull_subscriptions, DEVICE_ID_2)

    def test_pullSubscriptions_raisesInvalidResponse_onMissingRemoveList(self):
        self.set_http_response_value("""
        {"add": [
            "http://example.com/test.rss",
            "http://feeds.example.org/1/feed.atom"
        ],
        "timestamp": 1262103016}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.pull_subscriptions, DEVICE_ID_2)

    def test_pullSubscriptions_raisesInvalidResponse_onInvalidTimestamp(self):
        self.set_http_response_value("""
        {"add": [
            "http://example.com/test.rss",
            "http://feeds.example.org/1/feed.atom"
        ],
        "remove": [
            "http://example.co.uk/episodes.xml",
            "http://pod.cast/test.xml"
        ],
        "timestamp": "should not work"}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.pull_subscriptions, DEVICE_ID_2)

    def test_pullSubscriptions_raisesInvalidResponse_onInvalidAddList(self):
        self.set_http_response_value("""
        {"add": [
            "http://example.com/test.rss",
            1234,
            "http://feeds.example.org/1/feed.atom"
        ],
        "remove": [
            "http://example.co.uk/episodes.xml",
            "http://pod.cast/test.xml"
        ],
        "timestamp": 1262103016}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.pull_subscriptions, DEVICE_ID_2)

    def test_pullSubscriptions_raisesInvalidResponse_onInvalidRemoveList(self):
        self.set_http_response_value("""
        {"add": [
            "http://example.com/test.rss",
            "http://feeds.example.org/1/feed.atom"
        ],
        "remove": [
            "http://example.co.uk/episodes.xml",
            ["should", "not", "work", "either"],
            "http://pod.cast/test.xml"
        ],
        "timestamp": 1262103016}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.pull_subscriptions, DEVICE_ID_2)

    def test_pullSubscriptions_returnsChangesListAndTimestamp(self):
        self.set_http_response_value("""
        {"add": [
            "http://example.com/test.rss",
            "http://feeds.example.org/1/feed.atom"
        ],
        "remove": [
            "http://example.co.uk/episodes.xml",
            "http://pod.cast/test.xml"
        ],
        "timestamp": 1262103016}
        """)
        changes = self.client.pull_subscriptions(DEVICE_ID_2)
        self.assertEquals(changes.add, [FEED_URL_1, FEED_URL_2])
        self.assertEquals(changes.remove, [FEED_URL_3, FEED_URL_4])
        self.assertEquals(changes.since, self.SINCE)
        self.assert_http_request_count(1)

    def test_uploadEpisodeActions_raisesInvalidResponse_onEmptyResponse(self):
        self.set_http_response_value('')
        self.assertRaises(api.InvalidResponse,
                self.client.upload_episode_actions, self.ACTIONS)

    def test_uploadEpisodeActions_raisesInvalidResponse_onMissingTimestamp(self):
        self.set_http_response_value('{}')
        self.assertRaises(api.InvalidResponse,
                self.client.upload_episode_actions, self.ACTIONS)

    def test_uploadEpisodeActions_raisesInvalidResponse_onInvalidTimestamp(self):
        self.set_http_response_value("""
        {"timestamp": "just nothin'.."}
        """)
        self.assertRaises(api.InvalidResponse,
                self.client.upload_episode_actions, self.ACTIONS)

    def test_uploadEpisodeActions_returnsTimestamp(self):
        self.set_http_response_value("""
        {"timestamp": 1262103016}
        """)
        result = self.client.upload_episode_actions(self.ACTIONS)
        self.assertEquals(result, self.SINCE)
        self.assert_http_request_count(1)
        self.assert_(self.has_posted_json_data(self.ACTIONS_AS_JSON_UPLOAD))

    def test_downloadEpisodeActions_raisesInvalidResponse_onEmptyResponse(self):
        self.set_http_response_value('')
        self.assertRaises(api.InvalidResponse, self.client.download_episode_actions)

    def test_downloadEpisodeActions_raisesInvalidResponse_onMissingActions(self):
        self.set_http_response_value("""
        {"timestamp": 1262103016}
        """)
        self.assertRaises(api.InvalidResponse, self.client.download_episode_actions)

    def test_downloadEpisodeActions_raisesInvalidResponse_onMissingTimestamp(self):
        self.set_http_response_value("""
        {"actions": [
            {"podcast": "a", "episode": "b", "action": "download"},
            {"podcast": "x", "episode": "y", "action": "play"}
        ]}
        """)
        self.assertRaises(api.InvalidResponse, self.client.download_episode_actions)

    def test_downloadEpisodeActions_raisesInvalidResponse_onInvalidTimestamp(self):
        self.set_http_response_value("""
        {"actions": [
            {"podcast": "a", "episode": "b", "action": "download"},
            {"podcast": "x", "episode": "y", "action": "play"}
        ], "timestamp": "right now"}
        """)
        self.assertRaises(api.InvalidResponse, self.client.download_episode_actions)

    def test_downloadEpisodeActions_raisesInvalidResponse_onIncompleteActions(self):
        self.set_http_response_value("""
        {"actions": [
            {"podcast": "a", "episode": "b", "action": "download"},
            {"podcast": "x", "episode": "y"}
        ], "timestamp": 1262103016}
        """)
        self.assertRaises(api.InvalidResponse, self.client.download_episode_actions)

    def test_downloadEpisodeActions_returnsActionList(self):
        self.set_http_response_value("""
        {"actions": [
            {"podcast": "a", "episode": "b", "action": "download"},
            {"podcast": "x", "episode": "y", "action": "play"}
        ], "timestamp": 1262103016}
        """)
        changes = self.client.download_episode_actions()
        self.assertEquals(len(changes.actions), 2)
        action1, action2 = changes.actions
        self.assertEquals(action1.podcast, 'a')
        self.assertEquals(action1.episode, 'b')
        self.assertEquals(action1.action, 'download')
        self.assertEquals(action2.podcast, 'x')
        self.assertEquals(action2.episode, 'y')
        self.assertEquals(action2.action, 'play')
        self.assertEquals(changes.since, self.SINCE)
        self.assert_http_request_count(1)

    def test_updateDeviceSettings_withNothing(self):
        self.set_http_response_value('')
        result = self.client.update_device_settings(DEVICE_ID_1)
        self.assertEquals(result, True)
        self.assert_http_request_count(1)
        self.assert_(self.has_posted_json_data({}))

    def test_updateDeviceSettings_withCaption(self):
        self.set_http_response_value('')
        result = self.client.update_device_settings(DEVICE_ID_1,
                caption='Poodonkis')
        self.assertEquals(result, True)
        self.assert_http_request_count(1)
        self.assert_(self.has_posted_json_data({'caption': 'Poodonkis'}))

    def test_updateDeviceSettings_withType(self):
        self.set_http_response_value('')
        result = self.client.update_device_settings(DEVICE_ID_1,
                type='desktop')
        self.assertEquals(result, True)
        self.assert_http_request_count(1)
        self.assert_(self.has_posted_json_data({'type': 'desktop'}))

    def test_updateDeviceSettings_withCaptionAndType(self):
        self.set_http_response_value('')
        result = self.client.update_device_settings(DEVICE_ID_1,
                'My Unit Testing Device', 'desktop')
        self.assertEquals(result, True)
        self.assert_http_request_count(1)
        self.assert_(self.has_posted_json_data({
            'caption': 'My Unit Testing Device',
            'type': 'desktop'}))

    def test_getDevices_raisesInvalidResponse_onEmptyResponse(self):
        self.set_http_response_value('')
        self.assertRaises(api.InvalidResponse, self.client.get_devices)

    def test_getDevices_raisesInvalidResponse_onMissingKeys(self):
        self.set_http_response_value("""
        [
            {"id": "gpodder.on.my.phone",
             "type": "mobile",
             "subscriptions": 42},
            {"id": "95dce59cf340123fa",
             "caption": "The Lappy",
             "subscriptions": 4711}
        ]
        """)
        self.assertRaises(api.InvalidResponse, self.client.get_devices)

    def test_getDevices_returnsDeviceList(self):
        self.set_http_response_value("""
        [
            {"id": "gpodder.on.my.phone",
             "caption": "Phone",
             "type": "mobile",
             "subscriptions": 42},
            {"id": "95dce59cf340123fa",
             "caption": "The Lappy",
             "type": "laptop",
             "subscriptions": 4711}
        ]
        """)
        devices = self.client.get_devices()
        self.assertEquals(len(devices), 2)
        device1, device2 = devices
        self.assertEquals(device1.device_id, DEVICE_ID_1)
        self.assertEquals(device1.caption, 'Phone')
        self.assertEquals(device1.type, 'mobile')
        self.assertEquals(device1.subscriptions, 42)
        self.assertEquals(device2.device_id, DEVICE_ID_2)
        self.assertEquals(device2.caption, 'The Lappy')
        self.assertEquals(device2.type, 'laptop')
        self.assertEquals(device2.subscriptions, 4711)
        self.assert_http_request_count(1)
        
    def test_getFavoriteEpisodes_returnsEpisodeList(self):
        self.set_http_response_value("""
        [
            {"title": "TWiT 245: No Hitler For You",
             "url": "http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3",
             "podcast_title": "this WEEK in TECH - MP3 Edition",
             "podcast_url": "http://leo.am/podcasts/twit", 
             "description": "[...]",
             "website": "http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3", 
             "released": "2010-12-25T00:30:00",
             "mygpo_link": "http://gpodder.net/episode/1046492"},
            {"website": "http://feedproxy.google.com/~r/coverville/~3/5UK8-PZmmMQ/", 
             "podcast_title": "Coverville", 
             "description": "Bob Dylan turned 70 this week. Bob Dylan has done a lot of songs. A lot of people have covered Bob&#8217;s songs. Did I mention Bob Dylan turned 70 this week? All this adds up to a Cover Story. Let me play you it. 59 minutes &#124; Featuring: Title Artist Album Original Artist 1 Blowin&#8217; [...]", 
             "title": "Coverville 774: The Bob Dylan Cover Story VI", 
             "url": "http://feedproxy.google.com/~r/coverville/~5/iV_RxVU1Jek/Coverville-110527.mp3", 
             "podcast_url": "http://feeds.feedburner.com/coverville", 
             "released": "2011-05-28T01:08:59", 
             "mygpo_link": "http://gpodder.net/episode/5329203"}
        ]
        """)
        favorites = self.client.get_favorite_episodes()
        self.assertEquals(len(favorites), 2)
        episode1, episode2 = favorites
        self.assertEquals(episode1.title, 'TWiT 245: No Hitler For You')
        self.assertEquals(episode1.url, 'http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3')
        self.assertEquals(episode1.podcast_title, 'this WEEK in TECH - MP3 Edition')
        self.assertEquals(episode1.podcast_url, 'http://leo.am/podcasts/twit')
        self.assertEquals(episode1.description, '[...]')
        self.assertEquals(episode1.website, 'http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3')
        self.assertEquals(episode1.released, '2010-12-25T00:30:00')
        self.assertEquals(episode1.mygpo_link, 'http://gpodder.net/episode/1046492')
        self.assertEquals(episode2.website, 'http://feedproxy.google.com/~r/coverville/~3/5UK8-PZmmMQ/')