Example #1
0
    def test_edition_url(self):

        api_key = "test"
        edition = theguardian_edition.Edition(api_key)
        edition_request_content = edition.get_request_response()

        self.assertEqual(edition.base_url,
                         edition_request_content.url.split("?")[0])
Example #2
0
    def test_edition_get_result_without_exception(self):

        api_key = "test"
        edition = theguardian_edition.Edition(api_key)
        edition_content = edition.get_content_response()
        results = edition.get_results(edition_content)

        self.assertIs(type(results), list)
Example #3
0
    def test_edition_get_response_section_count(self):

        api_key = "test"
        edition = theguardian_edition.Edition(api_key)
        edition_content = edition.get_content_response()
        total = edition_content['response']['total']
        result_len = len(edition_content['response']['results'])

        self.assertEqual(total, result_len)
Example #4
0
    def test_edition_get_indirect_content(self):

        api_key = "test"
        edition = theguardian_edition.Edition(api_key)
        res = edition.get_request_response()
        edition_content = edition.get_content_response()

        self.assertEqual(res.status_code, 200)
        self.assertIn("response", edition_content.keys())
Example #5
0
    def test_edition_get_indirect_content_invalid_credentials(self):

        api_key = "tests"
        edition = theguardian_edition.Edition(api_key)
        res = edition.get_request_response()
        edition_content = edition.get_content_response()

        self.assertEqual(res.status_code, 403)
        self.assertIn("message", edition_content.keys())
        self.assertEqual("Invalid authentication credentials",
                         edition_content["message"])
Example #6
0
from theguardian import theguardian_edition

# create edition
edition = theguardian_edition.Edition(api='test')

# gets raw_response
raw_content = edition.get_request_response()
print("Request Response status code {status}.".format(
    status=raw_content.status_code))
print("Request Response headers {header}.".format(header=raw_content.headers))

# content
print("Content Response headers {}.".format(edition.response_headers()))

# get all results of a page
json_content = edition.get_content_response()
all_results = edition.get_results(json_content)
print("All results {}.".format(all_results))

# actual response
print("Response {response}".format(response=json_content))

# get all the sections webUrl
for result in all_results:
    print("{id} - {url}".format(id=result["id"], url=result["webUrl"]))
Example #7
0
    def test_edition_get_result_with_exception(self):

        api_key = "test"
        edition = theguardian_edition.Edition(api_key)

        self.assertRaises(TypeError, edition.get_results, "some random text")
Example #8
0
    def test_edition_get_direct_content(self):

        api_key = "test"
        res = theguardian_edition.Edition(api_key).get_content_response()

        self.assertIn("response", res.keys())
Example #9
0
    def test_edition_response_failure_incorrect_api_key(self):

        api_key = "tests"
        res = theguardian_edition.Edition(api_key).get_request_response()

        self.assertEqual(res.status_code, 403)
Example #10
0
    def test_edition_response_success_correct_details(self):

        api_key = "test"
        res = theguardian_edition.Edition(api_key).get_request_response()

        self.assertEqual(res.status_code, 200)