def test_record_order(): query = build_query(URLS, "article") query_old = copy.deepcopy(query) new_query = record_order(query) assert query == query_old assert [q['meta'] for q in new_query] == ['0', '1', '2'] assert [q['url'] for q in new_query] == URLS assert [q['pageType'] for q in new_query] == ['article'] * len(URLS)
def test_sync_request_error(): responses.add(responses.POST, API_ENDPOINT, json={'error': 'true'}, status=429) query = build_query(urls=['http://example.com'], page_type='article') try: request_raw(query, 'secret_key') except Exception as err: assert err.response.status_code == 429 assert 'User-Agent' in err.request.headers
def test_build_query(): query = build_query(urls=['http://example.com', 'http://example.org'], page_type='article') assert query == [ { 'url': 'http://example.com', 'pageType': 'article' }, { 'url': 'http://example.org', 'pageType': 'article' }, ]
def test_sync_request_success(): responses.add(responses.POST, API_ENDPOINT, json={'success': 'true'}) query = build_query(urls=['http://example.com'], page_type='article') resp = request_raw(query, 'secret_key') assert resp == {'success': 'true'}
def test_build_query_too_many(): urls = URLS * 100 with pytest.raises(ValueError): build_query(urls, "article")