示例#1
0
def test_api_url():
    assert api._api_url("https://moz.blog/", "posts",
                        4) == "https://moz.blog/wp-json/wp/v2/posts/4"
    assert api._api_url("https://moz.blog/", "tags",
                        None) == "https://moz.blog/wp-json/wp/v2/tags/"
    assert api._api_url("https://moz.blog", "media",
                        55) == "https://moz.blog/wp-json/wp/v2/media/55"
示例#2
0
def test_api_url():
    assert (api._api_url('https://moz.blog/', 'posts',
                         4) == 'https://moz.blog/wp-json/wp/v2/posts/4')
    assert (api._api_url('https://moz.blog/', 'tags',
                         None) == 'https://moz.blog/wp-json/wp/v2/tags/')
    assert (api._api_url('https://moz.blog', 'media',
                         55) == 'https://moz.blog/wp-json/wp/v2/media/55')
示例#3
0
def setup_responses(blog='firefox'):
    posts_url = api._api_url(TEST_WP_BLOGS[blog]['url'], 'posts', None)
    tags_url = api._api_url(TEST_WP_BLOGS[blog]['url'], 'tags', None)
    media_url = api._api_url(TEST_WP_BLOGS[blog]['url'], 'media', 75)
    responses.add(responses.GET, posts_url, body=get_test_file_content('posts.json'))
    responses.add(responses.GET, tags_url, body=get_test_file_content('tags.json'))
    responses.add(responses.GET, media_url, body=get_test_file_content('media_75.json'))
示例#4
0
def test_api_url():
    assert (api._api_url('https://moz.blog/', 'posts', 4) ==
            'https://moz.blog/wp-json/wp/v2/posts/4')
    assert (api._api_url('https://moz.blog/', 'tags', None) ==
            'https://moz.blog/wp-json/wp/v2/tags/')
    assert (api._api_url('https://moz.blog', 'media', 55) ==
            'https://moz.blog/wp-json/wp/v2/media/55')
示例#5
0
def test_get_wp_data(req_mock):
    api.get_wp_data('firefox', 'posts')
    api_url = api._api_url(TEST_WP_BLOGS['firefox']['url'], 'posts', None)
    req_mock.assert_called_with(api_url, limit=10)

    api.get_wp_data('firefox', 'media', 75)
    api_url = api._api_url(TEST_WP_BLOGS['firefox']['url'], 'media', 75)
    req_mock.assert_called_with(api_url, limit=1)

    api.get_wp_data('firefox', 'tags')
    api_url = api._api_url(TEST_WP_BLOGS['firefox']['url'], 'tags', None)
    req_mock.assert_called_with(api_url, limit=None)
示例#6
0
def test_get_wp_data(req_mock):
    api.get_wp_data("firefox", "posts")
    api_url = api._api_url(TEST_WP_BLOGS["firefox"]["url"], "posts", None)
    req_mock.assert_called_with(api_url, limit=10)

    api.get_wp_data("firefox", "media", 75)
    api_url = api._api_url(TEST_WP_BLOGS["firefox"]["url"], "media", 75)
    req_mock.assert_called_with(api_url, limit=1)

    api.get_wp_data("firefox", "tags")
    api_url = api._api_url(TEST_WP_BLOGS["firefox"]["url"], "tags", None)
    req_mock.assert_called_with(api_url, limit=None)
示例#7
0
def test_get_wp_data(req_mock):
    api.get_wp_data('firefox', 'posts')
    api_url = api._api_url(TEST_WP_BLOGS['firefox']['url'], 'posts', None)
    req_mock.assert_called_with(api_url, limit=10)

    api.get_wp_data('firefox', 'media', 75)
    api_url = api._api_url(TEST_WP_BLOGS['firefox']['url'], 'media', 75)
    req_mock.assert_called_with(api_url, limit=1)

    api.get_wp_data('firefox', 'tags')
    api_url = api._api_url(TEST_WP_BLOGS['firefox']['url'], 'tags', None)
    req_mock.assert_called_with(api_url, limit=None)
示例#8
0
def setup_responses(blog='firefox'):
    posts_url = api._api_url(TEST_WP_BLOGS[blog]['url'], 'posts', None)
    tags_url = api._api_url(TEST_WP_BLOGS[blog]['url'], 'tags', None)
    media_url = api._api_url(TEST_WP_BLOGS[blog]['url'], 'media', 75)
    responses.add(responses.GET,
                  posts_url,
                  body=get_test_file_content('posts.json'))
    responses.add(responses.GET,
                  tags_url,
                  body=get_test_file_content('tags.json'))
    responses.add(responses.GET,
                  media_url,
                  body=get_test_file_content('media_75.json'))
示例#9
0
def setup_responses(blog="firefox"):
    posts_url = api._api_url(TEST_WP_BLOGS[blog]["url"], "posts", None)
    tags_url = api._api_url(TEST_WP_BLOGS[blog]["url"], "tags", None)
    media_url = api._api_url(TEST_WP_BLOGS[blog]["url"], "media", 75)
    media_url_404 = api._api_url(TEST_WP_BLOGS[blog]["url"], "media", 42)
    responses.add(responses.GET,
                  posts_url,
                  body=get_test_file_content("posts.json"))
    responses.add(responses.GET,
                  tags_url,
                  body=get_test_file_content("tags.json"))
    responses.add(responses.GET,
                  media_url,
                  body=get_test_file_content("media_75.json"))
    responses.add(responses.GET, media_url_404, status=404)
示例#10
0
def test_unlimited_request():
    api_url = api._api_url(TEST_WP_BLOGS['firefox']['url'], 'tags', None)
    responses.add(responses.GET,
                  api_url + '?per_page=100&page=1',
                  match_querystring=True,
                  json=[1],
                  adding_headers={'X-WP-TotalPages': '3'})
    responses.add(responses.GET,
                  api_url + '?per_page=100&page=2',
                  json=[2, 2],
                  match_querystring=True,
                  adding_headers={'X-WP-TotalPages': '3'})
    responses.add(responses.GET,
                  api_url + '?per_page=100&page=3',
                  json=[3, 3, 3],
                  match_querystring=True,
                  adding_headers={'X-WP-TotalPages': '3'})

    data = api._request(api_url, limit=None)
    assert data == [1, 2, 2, 3, 3, 3]
    assert len(responses.calls) == 3
示例#11
0
def test_unlimited_request():
    api_url = api._api_url(TEST_WP_BLOGS["firefox"]["url"], "tags", None)
    responses.add(responses.GET,
                  api_url + "?per_page=100&page=1",
                  match_querystring=True,
                  json=[1],
                  adding_headers={"X-WP-TotalPages": "3"})
    responses.add(responses.GET,
                  api_url + "?per_page=100&page=2",
                  json=[2, 2],
                  match_querystring=True,
                  adding_headers={"X-WP-TotalPages": "3"})
    responses.add(responses.GET,
                  api_url + "?per_page=100&page=3",
                  json=[3, 3, 3],
                  match_querystring=True,
                  adding_headers={"X-WP-TotalPages": "3"})

    data = api._request(api_url, limit=None)
    assert data == [1, 2, 2, 3, 3, 3]
    assert len(responses.calls) == 3
示例#12
0
def test_unlimited_request():
    api_url = api._api_url(TEST_WP_BLOGS['firefox']['url'], 'tags', None)
    responses.add(responses.GET,
                  api_url + '?per_page=100&page=1',
                  match_querystring=True,
                  json=[1],
                  adding_headers={'X-WP-TotalPages': '3'})
    responses.add(responses.GET,
                  api_url + '?per_page=100&page=2',
                  json=[2, 2],
                  match_querystring=True,
                  adding_headers={'X-WP-TotalPages': '3'})
    responses.add(responses.GET,
                  api_url + '?per_page=100&page=3',
                  json=[3, 3, 3],
                  match_querystring=True,
                  adding_headers={'X-WP-TotalPages': '3'})

    data = api._request(api_url, limit=None)
    assert data == [1, 2, 2, 3, 3, 3]
    assert len(responses.calls) == 3