Exemplo n.º 1
0
    def test_get_fails_no_such_place(self):
        inmate_url = 'http://idbvf3ruvfr3ubububufvubeuvdvd2uvuevvgud2bewhde.duucuvcryvgrfvyv'
        http = Http()
        okay, fetched_contents = http.get(inmate_url)

        assert not okay
        assert fetched_contents == BAD_URL_NETWORK_PROBLEM
Exemplo n.º 2
0
    def test_get_succeeds(self):
        number_of_attempts = 2
        expected_text = 'it worked'
        ccj_api_requests = {
            'succeed-attempt': randint(1, number_of_attempts),
            'current-attempt': 0
        }

        def fulfill_ccj_api_request(_, uri, headers):
            assert uri == INMATE_URL
            ccj_api_requests['current-attempt'] += 1
            if ccj_api_requests['current-attempt'] == ccj_api_requests[
                    'succeed-attempt']:
                return 200, headers, expected_text
            return 500, headers, 'did not work'

        httpretty.register_uri(httpretty.GET,
                               COOK_COUNTY_JAIL_INMATE_DETAILS_URL,
                               body=fulfill_ccj_api_request)

        http = Http()
        okay, fetched_contents = http.get(INMATE_URL, number_of_attempts)

        assert okay
        assert ccj_api_requests['current-attempt'] == ccj_api_requests[
            'succeed-attempt']
        assert fetched_contents == expected_text
Exemplo n.º 3
0
    def test_get_fails_no_such_place(self):
        inmate_url = "http://idbvf3ruvfr3ubububufvubeuvdvd2uvuevvgud2bewhde.duucuvcryvgrfvyv"
        http = Http()
        okay, fetched_contents = http.get(inmate_url)

        assert not okay
        assert fetched_contents == BAD_URL_NETWORK_PROBLEM
Exemplo n.º 4
0
    def test_get_fails_500(self):
        number_of_attempts = 2
        expected_text = "did not work"
        ccj_api_requests = {"succeed-attempt": number_of_attempts, "current-attempt": 0}

        def fulfill_ccj_api_request(_, uri, headers):
            assert uri == INMATE_URL
            ccj_api_requests["current-attempt"] += 1
            return 500, headers, expected_text

        httpretty.register_uri(httpretty.GET, COOK_COUNTY_JAIL_INMATE_DETAILS_URL, body=fulfill_ccj_api_request)

        http = Http()
        okay, fetched_contents = http.get(INMATE_URL, number_of_attempts)

        assert not okay
        assert ccj_api_requests["current-attempt"] == ccj_api_requests["succeed-attempt"]
        assert fetched_contents["status-code"] == 500
Exemplo n.º 5
0
    def test_get_succeeds(self):
        number_of_attempts = 2
        expected_text = "it worked"
        ccj_api_requests = {"succeed-attempt": randint(1, number_of_attempts), "current-attempt": 0}

        def fulfill_ccj_api_request(_, uri, headers):
            assert uri == INMATE_URL
            ccj_api_requests["current-attempt"] += 1
            if ccj_api_requests["current-attempt"] == ccj_api_requests["succeed-attempt"]:
                return 200, headers, expected_text
            return 500, headers, "did not work"

        httpretty.register_uri(httpretty.GET, COOK_COUNTY_JAIL_INMATE_DETAILS_URL, body=fulfill_ccj_api_request)

        http = Http()
        okay, fetched_contents = http.get(INMATE_URL, number_of_attempts)

        assert okay
        assert ccj_api_requests["current-attempt"] == ccj_api_requests["succeed-attempt"]
        assert fetched_contents == expected_text
Exemplo n.º 6
0
    def test_get_fails_500(self):
        number_of_attempts = 2
        expected_text = 'did not work'
        ccj_api_requests = {
            'succeed-attempt': number_of_attempts,
            'current-attempt': 0
        }

        def fulfill_ccj_api_request(_, uri, headers):
            assert uri == INMATE_URL
            ccj_api_requests['current-attempt'] += 1
            return 500, headers, expected_text

        httpretty.register_uri(httpretty.GET,
                               COOK_COUNTY_JAIL_INMATE_DETAILS_URL,
                               body=fulfill_ccj_api_request)

        http = Http()
        okay, fetched_contents = http.get(INMATE_URL, number_of_attempts)

        assert not okay
        assert ccj_api_requests['current-attempt'] == ccj_api_requests[
            'succeed-attempt']
        assert fetched_contents['status-code'] == 500