-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
110 lines (91 loc) · 3.38 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
105
106
107
108
109
110
# 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': ''
}
}
APP_NAME = 'Movie browser'
API_KEY = 'nbf4kr594esg4af25qexwtnu'
API_SECRET = 'SSSeTdsPsM'
CALLBACK = 'http://www.synedra.org'
EXAMPLE_USER = {
'request': {
'key': 'guzwtx7epxmbder6dx5n2t7a',
'secret': 'D8HrxmaQ7YRr'
},
'access': {
'key': 'T1i0pqrkyEfVCl3NVbrSCMvFg0fPup3TsQ7bAQjN35XZcmuS9WDK7oVOkZdE6iGg8HkhEp4VQn7sSB.kILNu2HiQ--',
'secret': 'efMFPEPZ35f6'
}
}
class TestQuery():
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.searchStringTitles('Foo')
for info in data:
assert re.search('Foo',info['title']['short'])
data = netflixClient.catalog.searchTitles(MOVIE_TITLE)
assert isinstance(data[0]['title']['regular'],unicode)
movie = netflixClient.catalog.getTitle(data[0]['id'])
assert isinstance(movie['catalog_title']['title']['regular'],unicode)
people = netflixClient.catalog.searchPeople('Flip Wilson',maxResults=1)
assert isinstance(people,dict)
# DISC TESTS
def test_disc_functions(self):
netflixClient = NetflixClient(APP_NAME, API_KEY, API_SECRET, CALLBACK)
data = netflixClient.catalog.searchTitles('Cocoon',1,2)
testSubject = data[0]
disc = NetflixDisc(testSubject,netflixClient)
formats = disc.getInfo('formats')
assert isinstance(formats,dict)
synopsis = disc.getInfo('synopsis')
assert isinstance(synopsis,dict)
def test_user_functions(self):
netflixClient = NetflixClient(APP_NAME, API_KEY, API_SECRET, CALLBACK)
netflixUser = NetflixUser(EXAMPLE_USER,netflixClient)
user = netflixUser.getData()
assert isinstance(user['first_name'],unicode)
data = netflixClient.catalog.searchTitles('Cocoon',1,2)
ratings = netflixUser.getRatings(data)
history = netflixUser.getRentalHistory('shipped',updatedMin=1219775019,maxResults=4)
assert int(history['rental_history']['number_of_results']) <= 5
queue = NetflixUserQueue(netflixUser)
response = queue.addTitle( urls=["http://api.netflix.com/catalog/titles/movies/60002013"] )
response = queue.addTitle( urls=["http://api.netflix.com/catalog/titles/movies/60002013"], position=1 )
response = queue.removeTitle( id="60002013")
discAvailable = queue.getAvailable('disc')
instantAvailable = queue.getAvailable('instant')
discSaved = queue.getSaved('disc')
instantSaved = queue.getSaved('instant')
if __name__ == '__main__':
unittest.main()