From f871196fd52334d7b9a8f7510a56554c759e957d Mon Sep 17 00:00:00 2001 From: higs4281 Date: Sat, 16 Dec 2017 00:42:40 -0500 Subject: [PATCH] --amend --- countylimits/tests.py | 28 +++++++--------------------- countylimits/views.py | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/countylimits/tests.py b/countylimits/tests.py index 153eabe..034b840 100644 --- a/countylimits/tests.py +++ b/countylimits/tests.py @@ -12,7 +12,6 @@ from django.core.management import call_command from django.core.management.base import CommandError from django.test import Client -from django.core.urlresolvers import reverse from django.utils.six import StringIO from countylimits.models import County, CountyLimit, State @@ -287,7 +286,6 @@ def setUp(self): county=County.objects.get(county_name='Accomack County')) url = '/oah-api/county/' - reverse_url = reverse('county_limits') def test_county_limits_by_state__no_args(self): """ ... when state is blank """ @@ -308,26 +306,14 @@ def test_county_limit_by_state__invalid_arg(self): def test_county_limit_by_state__valid_arg(self): """ ... when state has a valid arg """ - self.AL.save() - self.VA.save() - self.DC.save() response_01 = client.get(self.url, {'state': '01'}) - print("url is {}".format(self.url)) - print("reverse_url is {}".format(self.reverse_url)) - print("request status text is {}".format(response_01.status_text)) - print("request path is {}".format(response_01.wsgi_request.path)) - print("request container is {}\n\n".format(response_01._container)) - print("\n\nAlabama is {}".format(self.AL)) - print("Virginia is {}".format(self.VA)) - print("DC is {}".format(self.DC)) - print("Accomack is {}".format(self.VACO)) - # self.assertEqual(response_01.status_code, 200) - # self.assertEqual('Autauga County', - # response_01.data['data'][0]['county']) - # response_AL = client.get(self.url, {'state': 'AL'}) - # self.assertTrue(response_01.data['data'] == response_AL.data['data']) - # response_DC = client.get(self.url, {'state': 'DC'}) - # self.assertEqual(len(response_DC.data['data']), 1) + self.assertEqual(response_01.status_code, 200) + self.assertEqual('Autauga County', + response_01.data['data'][0]['county']) + response_AL = client.get(self.url, {'state': 'AL'}) + self.assertTrue(response_01.data['data'] == response_AL.data['data']) + response_DC = client.get(self.url, {'state': 'DC'}) + self.assertEqual(len(response_DC.data['data']), 1) response_VA = client.get(self.url, {'state': 'VA'}) self.assertEqual(len(response_VA.data['data']), 1) self.assertEqual('Accomack County', diff --git a/countylimits/views.py b/countylimits/views.py index c25587e..275f447 100644 --- a/countylimits/views.py +++ b/countylimits/views.py @@ -1,13 +1,21 @@ +from __future__ import unicode_literals + from rest_framework import status from rest_framework.decorators import api_view from rest_framework.response import Response -from countylimits.models import CountyLimit, State +from countylimits.models import CountyLimit -SAFE_STATE_LIST = ( # states can be specified by abbreviation or FIPS code - list(State.objects.values_list('state_abbr', flat=True)) + - list(State.objects.values_list('state_fips', flat=True)) - ) +SAFE_STATE_LIST = [ # A static whitelist of abbreviations and FIPS codes + 'AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', + 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', + 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', + 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY', 'AS', + 'GU', 'MP', 'PR', 'VI', '01', '02', '04', '05', '06', '08', '09', '10', '11', + '12', '13', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', + '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', + '39', '40', '41', '42', '44', '45', '46', '47', '48', '49', '50', '51', '53', + '54', '55', '56', '60', '66', '69', '72', '78'] @api_view(['GET'])