Esempio n. 1
0
    def test_error(self, bot_helper, responses):
        num, url, content_type, fixture, _ = json_test_cases[0]  # Latest
        # Test if the comics are unavailable by making the latest return a 404
        responses.add(responses.GET, url, body="404 - Not Found",
                      content_type="text/html", status=404)
        with pytest.raises(bot_helper['xkcd'].XKCDError):
            bot_helper['xkcd']._xkcd("")
        responses.reset()

        # Now override the actual 404 page and the latest "properly"
        responses.add(responses.GET, url, body=read_fixture_file(fixture),
                      content_type=content_type)
        responses.add(responses.GET, "http://xkcd.com/404/info.0.json",
                      body="404 - Not Found", content_type="text/html",
                      status=404)

        error_cases = [
            "flibble",
            "404",      # Missing comic
            "-5",
            "1000000",  # Testing "latest"
        ]

        for case in error_cases:
            with pytest.raises(bot_helper['xkcd'].XKCDError):
                bot_helper['xkcd']._xkcd(case)
Esempio n. 2
0
def test_integration_nsfw(bot_helper, responses, url, api_url, status, content_type, fixture, title):
    responses.add(responses.GET, api_url, status=status,
                  body=read_fixture_file(fixture),
                  content_type=content_type)
    result = bot_helper['linkinfo'].get_link_info(url)
    if title is None:
        assert result.is_error
    else:
        assert not result.is_error
        assert title == result.text
Esempio n. 3
0
 def test_integration_nsfw(self):
     for url, api_url, status, content_type, fixture, title in nsfw_test_cases:
         with self.subTest(url=url), responses.RequestsMock() as rsps:
             rsps.add(responses.GET, api_url, status=status,
                      body=read_fixture_file(fixture),
                      content_type=content_type)
             result = self.linkinfo.get_link_info(url)
             if title is None:
                 self.assert_(result.is_error)
             else:
                 self.assert_(not result.is_error)
                 self.assertEqual(title, result.text)
Esempio n. 4
0
 def populate_responses(self, bot_helper, responses):
     """Populate all data into responses, don't assert that every request is fired."""
     responses.assert_all_requests_are_fired = False
     for num, url, content_type, fixture, expected in json_test_cases:
         responses.add(responses.GET, url, body=read_fixture_file(fixture),
                       content_type=content_type)
Esempio n. 5
0
 def payload_and_headers_from_fixture(fixture):
     payload = read_fixture_file(f'{fixture}.payload.json')
     headers = json.loads(read_fixture_file(f'{fixture}.headers.json'))
     return payload, headers
Esempio n. 6
0
def pre_irc_client(responses):
    # imgurpython calls this on init to get initial rate limits
    responses.add(responses.GET, 'https://api.imgur.com/3/credits',
                  status=200, body=read_fixture_file('imgur_credits.json'),
                  content_type='application/json')