forked from shelfworthy/flixpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
104 lines (85 loc) · 3.29 KB
/
test.py
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
# Sample code to use the Netflix python client
import unittest, os
import simplejson
from netflix import *
APP_NAME = ''
API_KEY = ''
API_SECRET = ''
CALLBACK = ''
MOVIE_TITLE = "Foo Fighters"
EXAMPLE_USER = {
'request': {
'key': '',
'secret': ''
},
'access': {
'key': '',
'secret': ''
}
}
EMPTY_USER = {
'request': {
'key': '',
'secret': ''
},
'access': {
'key': '',
'secret': ''
}
}
class TestQuery(unittest.TestCase):
def test_base(self):
netflixClient = NetflixClient(APP_NAME, API_KEY, API_SECRET, CALLBACK)
# def test_token_functions(self):
# netflixClient = NetflixClient(APP_NAME, API_KEY, API_SECRET, CALLBACK)
# netflixUser = NetflixUser(EMPTY_USER,netflixClient)
# I'd love to test the token functions, but unfortunately running these
# invalidates the existing tokens. Foo.
def test_catalog_functions(self):
netflixClient = NetflixClient(APP_NAME, API_KEY, API_SECRET, CALLBACK)
data = netflixClient.catalog.autocomplete('Foo')
for info in data:
assert re.search('Foo',info)
data = netflixClient.catalog.search_titles(MOVIE_TITLE)
assert isinstance(data[0].title,str)
# API reads that it returns "all titles in the catalog"
# meaing every movie that Netflix has? Let's not call
# this every time then
# movie = netflixClient.catalog.index()
# assert isinstance(movie['catalog_title']['title']['regular'],str)
people = netflixClient.catalog.search_people('Flip Wilson',maxResults=1)
assert isinstance(people[0],NetflixPerson)
# DISC TESTS
def test_disc_functions(self):
netflixClient = NetflixClient(APP_NAME, API_KEY, API_SECRET, CALLBACK)
titles = netflixClient.catalog.search_titles('Cocoon',1,2)
formats = titles[0].formats()
assert isinstance(formats,list)
synopsis = titles[0].synopsis
assert isinstance(synopsis,str)
def test_user_functions(self):
netflixClient = NetflixClient(APP_NAME, API_KEY, API_SECRET, CALLBACK)
netflixUser = NetflixUser(EXAMPLE_USER,netflixClient)
username = netflixUser.name
assert isinstance(username,str)
data = netflixClient.catalog.search_titles('Cocoon',1,2)
ratings = netflixUser.getRatings(data)
history = netflixUser.getRentalHistory('shipped',updatedMin=1219775019,maxResults=4)
# 45 is how many times it had been rented when I wrote the test
assert int(history['rental_history']['number_of_results']) >= 45
# yeah, these fail with Unauthorized, imagine that
queue = NetflixUserQueue(netflixUser)
response = queue.addTitle( urls=["http://api.netflix.com/catalog/titles/movies/60010242"] )
response = queue.addTitle( urls=["http://api.netflix.com/catalog/titles/movies/60020242"], position=1)
response = queue.removeTitle( id="60010242")
discAvailable = queue.getAvailable('disc')
instantAvailable = queue.getAvailable('instant')
discSaved = queue.getSaved('disc')
instantSaved = queue.getSaved('instant')
if __name__ == '__main__':
EXAMPLE_USER = simplejson.load(open("user.json"))
appinfo = simplejson.load(open("app.json"))
APP_NAME = appinfo["app_name"]
API_KEY = appinfo["api_key"]
API_SECRET = appinfo["api_secret"]
unittest.main()