def test_movie(cin, rr): stub_get(**rr['movie']) mov = cin.movie.get(68675) assert str(mov) == '<Movie 68675 Henry\'s Crime>' assert mov.country == [Country(name=u('США'))] assert mov.genre == [Genre(name=u('комедия'))] assert mov.director == [cin.person(163239, name=u('Малькольм Венвилль'))] actors = ( 2624, 1219, 2856, 112, 2243, 9803, 13257, 39646, 9040, 5933, 67860, 108757, 190286, 148348, 190285, ) assert mov.cast == list(map(cin.person, actors)) assert mov.url == 'http://cinemate.cc/movie/68675/' stub_get(**rr['movie_one_person']) mov = cin.movie.get(147668) assert isinstance(mov.cast, list)
def test_new(cin, rr): stub_get(**rr['stats.new']) stats = cin.stats.new() assert stats == { 'users_count': 4, 'reviews_count': 0, 'comments_count': 2, 'movies_count': 7, }
def test_person_movies(cin, rr): stub_get(**rr['person.movies']) movies = cin.person(43083).movies() assert isinstance(movies, dict) director_movies = movies['director'] lst = 79144, 4974, 31965, 4703, 5509 assert director_movies == list(map(cin.movie, lst)) actor_movies = movies['actor'] lst = 79144, 4974 assert actor_movies == list(map(cin.movie, lst))
def test_watchlist(cin, rr): stub_get(**rr['account.watchlist']) wlst = cin.account.watchlist() assert isinstance(wlst, dict) assert 'movie' in wlst assert 'person' in wlst assert isinstance(wlst['movie'], list) assert isinstance(wlst['person'], list) assert len(wlst['movie']) == 2 assert len(wlst['person']) == 2 movie = wlst['movie'][0] assert isinstance(movie, cin.movie) person = wlst['person'][0] assert isinstance(person, cin.person)
def test_updatelist(cin, rr): stub_get(**rr['account.updatelist']) lst = cin.account.updatelist() first = lst[0] assert isinstance(lst, list) assert len(lst) == 4 assert isinstance(first, dict) assert first['date'] == datetime(2011, 4, 9, 15, 38, 30) assert isinstance(first['for_object'], cin.movie) assert first['description'] == u('Новая раздача') assert first['url'] == ( 'http://cinemate.cc/watchlist/' 'a415ef22a4b7ebf24bc54d7ad9a92fa4612cb49f/read/400813/') assert first['new'] == 1
def test_no_prompt_good_cookies(tmpdir): JIRA.COOKIE_CACHE_FILE_PATH = str(tmpdir.join('.jira_session_json')) _save_cookies(JIRA.COOKIE_CACHE_FILE_PATH, dict(JSESSIONID='ABC123')) stub_get(re.compile('.*/serverInfo'), body='{"versionNumbers":[6,4,0]}') stub_get(re.compile('.*/session'), body='{}', status=200) with JIRA(prompt_for_credentials=False) as j: assert 'JSESSIONID=ABC123' == last_request().headers['Cookie'] assert j.ABORTED_BY_USER is False assert j.authentication_failed is False assert getattr(j, '_JIRA__authenticated_with_cookies') is True assert getattr(j, '_JIRA__authenticated_with_password') is False assert dict(JSESSIONID='ABC123') == _load_cookies(JIRA.COOKIE_CACHE_FILE_PATH)
def test_updatelist(cin, rr): stub_get(**rr['account.updatelist']) lst = cin.account.updatelist() first = lst[0] assert isinstance(lst, list) assert len(lst) == 4 assert isinstance(first, dict) assert first['date'] == datetime(2011, 4, 9, 15, 38, 30) assert isinstance(first['for_object'], cin.movie) assert first['description'] == u('Новая раздача') assert first['url'] == ( 'http://cinemate.cc/watchlist/' 'a415ef22a4b7ebf24bc54d7ad9a92fa4612cb49f/read/400813/' ) assert first['new'] == 1
def test_profile(cin, rr): stub_get(**rr['account.profile']) profile = cin.account.profile() assert isinstance(profile, dict) assert profile == { 'username': '******', 'reputation': 125, 'review_count': 11, 'gold_badges': 2, 'silver_badges': 14, 'bronze_badges': 21, 'unread_pm_count': 3, 'unread_forum_count': 7, 'unread_updatelist_count': 2, 'subscription_count': 96, }
def test_movie_list(cin, rr): stub_get(**rr['movie.list']) movies = ( 131001, 131657, 109767, 83460, 66450, 135826, 105524, 122874, 133159, 52036, ) assert cin.movie.list() == list(map(cin.movie, movies)) stub_get(**rr['movie.list_with_params']) lst = cin.movie.list(order_from=date(1988, 7, 4), order_to=datetime(1989, 7, 4), order_by='release_date') movies = ( 24424, 6685, 114718, 32660, 117681, 38105, 18319, 7139, 14832, 19272, ) assert lst == list(map(cin.movie, movies)) with pytest.raises(ValueError): cin.movie.list(order_from=date(1988, 7, 4), order_to=datetime(1989, 7, 4))
def test_api_get(cin, rr): correct_url = 'stats.new' incorect_url = 'stats.wtf' wrong_status_url = 'account.wrong_status_code' stub_get(**rr[correct_url]) stub_get(**rr[incorect_url]) stub_get(**rr[wrong_status_url]) req = cin.api_get(correct_url) assert req.status_code == codes.ok assert 'error' not in req.json() with pytest.raises(RuntimeError): cin.api_get(incorect_url) not_found_url = rr[wrong_status_url]['uri'] with pytest.raises(RuntimeError): cin.api_get(not_found_url)
def test_person(cin, rr): stub_get(**rr['person']) person = cin.person.get(3971) assert str(person) == '<Person 3971 Jake Gyllenhaal>'
def test_person_search(cin, rr): stub_get(**rr['person.search']) lst = cin.person.search(u('гиленхол')) persons = 3971, 1685, 79826, 76362, 361603, 303647, 333519 assert lst == list(map(cin.person, persons))
def test_auth(cin, rr): stub_get(**rr['account.auth']) cin.account.auth() assert cin.passkey == 'of3k4oasd9498dfvjh5hthhgfgdfy'
def test_movie_search(cin, rr): stub_get(**rr['movie.search']) lst = cin.movie.search(u('Пираты кариб')) movies = 120787, 68669, 1787, 2194, 15869, 7412 assert lst == list(map(cin.movie, movies))
def test_stub_get(dummy): stub_get('http://example.com/', body='World!') assert requests.get('http://example.com').text == 'World!'