def test_get_zip_codes(self, limit, logger): limit.return_value = fakedata.get_many_zip_codes(how_many=10) response = self.test_app.get('/zipcode/', data={'limit': 10}) self.assertEquals(response.status_code, 200) expected = [zipcode.to_dict() for zipcode in limit.return_value] response_decoded = decode(response.data) self.assertEquals(json.loads(response_decoded), expected) limit.assert_called_with(10) logger.assert_called_with("Listing 10 zip_codes")
def test_get_zip_codes_with_a_big_limit(self, limit, logger): limit.return_value = fakedata.get_many_zip_codes(5) response = self.test_app.get('/zipcode/', data={'limit': 20}) self.assertEquals(response.status_code, 200) expected = [zipcode.to_dict() for zipcode in limit.return_value] response_decoded = decode(response.data) self.assertEquals(json.loads(response_decoded), expected) limit.assert_called_with(20) logger.assert_has_calls([ call("Received option to list 20 zipcodes but only 5 were found"), call("Listing 5 zip_codes") ])