def test_get_all(mock_urlopen): mock_urlopen.side_effect = urlopen_side_effect({ 'https://example.com/api?limit=2': FakeResponse( b'{' b' "values":["page1_1", "page1_2"],' b' "nextPageStart":3,' b' "isLastPage":false' b'}', ), 'https://example.com/api?limit=2&start=3': FakeResponse( b'{' b' "values":["page2_1", "page2_2"],' b' "nextPageStart":7,' b' "isLastPage":false' b'}', ), 'https://example.com/api?limit=2&start=7': FakeResponse(b'{"values":["page3_1", "page3_2"],"isLastPage":true}', ), }) ret = get_all('https://example.com/api?limit=2') expected = [ 'page1_1', 'page1_2', 'page2_1', 'page2_2', 'page3_1', 'page3_2', ] assert ret == expected
def test_get_all(mock_urlopen): mock_urlopen.side_effect = urlopen_side_effect({ 'https://example.com/api': FakeResponse( b'{' b' "values":["page1_1", "page1_2"],' b' "next":"https://example.com/api?page=2"' b'}', ), 'https://example.com/api?page=2': FakeResponse( b'{' b' "values":["page2_1", "page2_2"],' b' "next":"https://example.com/api?page=3"' b'}', ), 'https://example.com/api?page=3': FakeResponse( b'{"values":["page3_1", "page3_2"]}', ), }) ret = get_all('https://example.com/api') expected = [ 'page1_1', 'page1_2', 'page2_1', 'page2_2', 'page3_1', 'page3_2', ] assert ret == expected
def repos_response(mock_urlopen): asottile_url = 'repos/asottile/reorder_python_imports/forks?per_page=100' asottile_forks = _resource_bytes('asottile-reorder-python-imports-forks') asottile_resp = FakeResponse(asottile_forks) mxr_url = 'repos/mxr/reorder_python_imports/forks?per_page=100' mxr_forks = _resource_bytes('mxr-reorder-python-imports-forks') mxr_resp = FakeResponse(mxr_forks) mock_urlopen.side_effect = urlopen_side_effect({ f'https://api.github.com/{asottile_url}': asottile_resp, f'https://api.github.com/{mxr_url}': mxr_resp, })
def repos_project_response(mock_urlopen): url = 'https://bitbucket.domain.com/' \ 'rest/api/1.0/projects/PRJ/repos?limit=100&permission=REPO_READ' mock_urlopen.side_effect = urlopen_side_effect({ url: FakeResponse(json.dumps(_resource_json()).encode()), })
def repos_response(mock_urlopen): mock_urlopen.side_effect = urlopen_side_effect({ 'https://gitlab.com/api/v4/groups/ronny-test/' 'projects?with_shared=False': FakeResponse( json.dumps(_resource_json('org-listing')).encode(), ), })
def test_get_all(mock_urlopen): mock_urlopen.side_effect = urlopen_side_effect({ 'https://example.com/api': FakeResponse( b'["page1_1", "page1_2"]', next_link='https://example.com/api?page=2', ), 'https://example.com/api?page=2': FakeResponse( b'["page2_1", "page2_2"]', next_link='https://example.com/api?page=3', ), 'https://example.com/api?page=3': FakeResponse( b'["page3_1"]', ), }) ret = get_all('https://example.com/api') assert ret == ['page1_1', 'page1_2', 'page2_1', 'page2_2', 'page3_1']
def repos_response(mock_urlopen): repos = [ # full permissions _resource_json('git-code-debt'), # A contributor repo _resource_json('libsass-python'), # A fork _resource_json('tox'), # A private repo _resource_json('eecs381-p4'), ] mock_urlopen.side_effect = urlopen_side_effect({ 'https://api.github.com/user/repos?per_page=100': FakeResponse(json.dumps(repos).encode(), ), }) return repos
def repos_response(mock_urlopen): mock_urlopen.side_effect = urlopen_side_effect({ 'https://api.github.com/orgs/sass/repos?per_page=100': FakeResponse( json.dumps([_resource_json('libsass-python')]).encode(), ), })
def repos_response(mock_urlopen): url = 'https://api.bitbucket.org/2.0/repositories?pagelen=100&role=member' mock_urlopen.side_effect = urlopen_side_effect({ url: FakeResponse(json.dumps(_resource_json()).encode()), })