Skip to content

Commit

Permalink
Merge 68e2959 into 2b6bfd3
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkykh committed Feb 15, 2017
2 parents 2b6bfd3 + 68e2959 commit 645178e
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 2 deletions.
48 changes: 48 additions & 0 deletions tests/fixtures/sync/playback/delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[
{
"progress": 10,
"paused_at": "2015-01-25T22:01:32.000Z",
"id": 13,
"type": "movie",
"movie": {
"title": "Batman Begins",
"year": 2005,
"ids": {
"trakt": 1,
"slug": "batman-begins-2005",
"imdb": "tt0372784",
"tmdb": 272
}
}
},
{
"progress": 65.5,
"paused_at": "2015-01-25T22:01:32.000Z",
"id": 37,
"type": "episode",
"episode": {
"season": 0,
"number": 1,
"title": "Good Cop Bad Cop",
"ids": {
"trakt": 1,
"tvdb": 3859781,
"imdb": "",
"tmdb": 62131,
"tvrage": null
}
},
"show": {
"title": "Breaking Bad",
"year": 2008,
"ids": {
"trakt": 1,
"slug": "breaking-bad",
"tvdb": 81189,
"imdb": "tt0903747",
"tmdb": 1396,
"tvrage": 18164
}
}
}
]
72 changes: 72 additions & 0 deletions tests/sync/playback/test_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from tests.core.helpers import authenticated_response

from datetime import datetime
from dateutil.tz import tzutc
from hamcrest import *
from trakt import Trakt
from trakt.objects import Movie, Show, Episode
import responses


@responses.activate
def test_basic():
responses.add_callback(
responses.GET, 'http://mock/sync/playback',
callback=authenticated_response('fixtures/sync/playback/delete.json'),
content_type='application/json'
)

Trakt.base_url = 'http://mock'

with Trakt.configuration.auth('mock', 'mock'):
collection = Trakt['sync/playback'].get()

# Ensure collection is valid
assert_that(collection, not_none())

# Batman Begins (2005)
assert_that(collection[('imdb', 'tt0372784')], has_properties({
'id': 13
}))

# Breaking Bad (2008)
assert_that(collection[('tvdb', '81189')], has_properties({

# Seasons
'seasons': all_of(
has_length(1),

# Seasons
has_entry(0, has_properties({
'episodes': all_of(
has_length(1),

# Episodes
has_entry(1, has_properties({
'id': 37
}))
)
}))
),
}))

# Batman Begins (2005)
responses.add_callback(
responses.DELETE, 'http://mock/sync/playback/13', # 13 = collection[('imdb', 'tt0372784')].id
callback=authenticated_response(data='{"mock": "mock"}'),
content_type='application/json'
)

# Breaking Bad (2008) - S00E01 - Good Cop Bad Cop
responses.add_callback(
responses.DELETE, 'http://mock/sync/playback/37', # 37 = collection[('tvdb', '81189')].seasons[0].episodes[1].id
callback=authenticated_response(data='{"mock": "mock"}'),
content_type='application/json'
)

with Trakt.configuration.auth('mock', 'mock'):
success_movie = Trakt['sync/playback'].delete(13)
success_episode = Trakt['sync/playback'].delete(37)

assert success_movie is True
assert success_episode is True
14 changes: 14 additions & 0 deletions trakt/interfaces/sync/core/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,17 @@ def remove(self, items, **kwargs):
)

return self.get_data(response, **kwargs)


class Delete(Interface):
@authenticated
def delete(self, playbackid, **kwargs):
response = self.http.delete(
path=str(playbackid),
**popitems(kwargs, [
'authenticated',
'validate_token'
])
)

return 200 <= response.status_code < 300
4 changes: 2 additions & 2 deletions trakt/interfaces/sync/playback.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from trakt.interfaces.base import authenticated
from trakt.interfaces.sync.core.mixins import Get
from trakt.interfaces.sync.core.mixins import Get, Delete


class SyncPlaybackInterface(Get):
class SyncPlaybackInterface(Get, Delete):
path = 'sync/playback'

@authenticated
Expand Down

0 comments on commit 645178e

Please sign in to comment.