def test_alert_api_put_cap12(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.cap_12, content_type='application/xml') force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # verify object created entry_result = list( Alert.objects.filter( cap_id__contains='tag:www.rfs.nsw.gov.au2011-10-06:40184') [:1])[0] self.assertEqual(entry_result.cap_scope, 'Public') info_result = entry_result.info_set.all()[0] self.assertEqual(info_result.cap_urgency, 'Expected') area_result = list(info_result.area_set.all()[:1])[0] # Get just one. self.assertIsNotNone(area_result.geom)
def test_alert_api_post_cap11(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.cap_11b, content_type='application/xml') force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # verify object created entry_result = list( Alert.objects.filter( cap_sender__contains='*****@*****.**')[:1])[0] self.assertEqual(entry_result.cap_status, 'Actual') info_result = entry_result.info_set.get() self.assertEqual(info_result.cap_category, 'Met') area_result = list(info_result.area_set.all()[:1])[0] # Get just one. self.assertIsNotNone(area_result.area_description)
def test_alert_api_post_cap11_atom(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.cap_11_atom, content_type='application/xml') force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # verify object created entry_result = list( Alert.objects.filter( cap_id__contains='http://doj.dc.gov/amber12345')[:1])[0] self.assertEqual(entry_result.cap_status, 'Actual') info_result = entry_result.info_set.get() self.assertEqual(info_result.cap_language, 'en-US') area_result = list(info_result.area_set.all()[:1])[0] # Get just one. self.assertIsNotNone(area_result.area_description)
def test_alert_api_put_ph_cap12(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.ph_cap_12, content_type='application/xml') force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # verify object created
def test_subpub_hub_challenge_api(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/?hub.challenge="kelvin"' view = AlertListAPI.as_view() request = factory.get(url) force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_duplicate_alerts(self): # After an alert is created, I can't think of it as needing to be updated again user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.cap_11, content_type='application/xml') force_authenticate(request, user=user) response = view(request) request2 = factory.post(url, self.cap_11, content_type='application/xml') force_authenticate(request2, user=user) response2 = view(request2) self.assertEqual(response2.status_code, status.HTTP_400_BAD_REQUEST) # verify we got back a response OK
def test_alert_api_query_by_coord_within_filterby_date_invalid(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/?lng=-66.64760&lat=18.42070&cap_date_received=2015-02-17T08:03:21.156421' # Swap expired date so alert is inactive info_set = Info.objects.all() for info in info_set: info.cap_expires = datetime.datetime(2015, 2, 14, 12, 30) info.save() view = AlertListAPI.as_view() request = factory.get(url) force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) # verify we got back a response OK
def test_alert_api_query_by_coord_within_filterby_date_invalid(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/?lng=-66.64760&lat=18.42070&cap_date_received=2015-02-17T08:03:21.156421' # Swap expired date so alert is inactive info_set = Info.objects.all() for info in info_set: info.cap_expires = datetime.datetime(2015, 2, 14, 12, 30) info.save() view = AlertListAPI.as_view() request = factory.get(url) force_authenticate(request, user=user) response = view(request) self.assertEqual( response.status_code, status.HTTP_404_NOT_FOUND) # verify we got back a response OK
def test_alert_api_query_by_coord_within_filterby_date(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/?lng=-66.71266&lat=18.47906&cap_date_received=2010-01-17T08:03:21.156421' # Swap expired date so alert is active info_set = Info.objects.all() for info in info_set: info.cap_expires = datetime.date.today() + datetime.timedelta(days=1) info.save() view = AlertListAPI.as_view() request = factory.get(url) force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_200_OK) # verify we got back a response OK cap_sender = response.data[0]['cap_sender'] self.assertEqual(cap_sender, '*****@*****.**') # test to sender
def test_alert_api_put_cap12(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.cap_12, content_type='application/xml') force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # verify object created entry_result = list(Alert.objects.filter(cap_id__contains='tag:www.rfs.nsw.gov.au2011-10-06:40184')[:1])[0] self.assertEqual(entry_result.cap_scope, 'Public') info_result = entry_result.info_set.all()[0] self.assertEqual(info_result.cap_urgency, 'Expected') area_result = list(info_result.area_set.all()[:1])[0] # Get just one. self.assertIsNotNone(area_result.geom)
def test_alert_api_post_cap11_atom(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.cap_11_atom, content_type='application/xml') force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # verify object created entry_result = list(Alert.objects.filter(cap_id__contains='http://doj.dc.gov/amber12345')[:1])[0] self.assertEqual(entry_result.cap_status, 'Actual') info_result = entry_result.info_set.get() self.assertEqual(info_result.cap_language, 'en-US') area_result = list(info_result.area_set.all()[:1])[0] # Get just one. self.assertIsNotNone(area_result.area_description)
def test_duplicate_alerts(self): # After an alert is created, I can't think of it as needing to be updated again user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.cap_11, content_type='application/xml') force_authenticate(request, user=user) response = view(request) request2 = factory.post(url, self.cap_11, content_type='application/xml') force_authenticate(request2, user=user) response2 = view(request2) self.assertEqual( response2.status_code, status.HTTP_400_BAD_REQUEST) # verify we got back a response OK
def test_alert_api_post_cap11(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/' view = AlertListAPI.as_view() request = factory.post(url, self.cap_11b, content_type='application/xml') force_authenticate(request, user=user) response = view(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # verify object created entry_result = list(Alert.objects.filter(cap_sender__contains='*****@*****.**')[:1])[0] self.assertEqual(entry_result.cap_status, 'Actual') info_result = entry_result.info_set.get() self.assertEqual(info_result.cap_category, 'Met') area_result = list(info_result.area_set.all()[:1])[0] # Get just one. self.assertIsNotNone(area_result.area_description)
def test_alert_api_query_by_coord_within_filterby_date(self): user, created = User.objects.get_or_create(username='******') url = '/api/v1/alerts/?lng=-66.71266&lat=18.47906&cap_date_received=2010-01-17T08:03:21.156421' # Swap expired date so alert is active info_set = Info.objects.all() for info in info_set: info.cap_expires = datetime.date.today() + datetime.timedelta( days=1) info.save() view = AlertListAPI.as_view() request = factory.get(url) force_authenticate(request, user=user) response = view(request) self.assertEqual( response.status_code, status.HTTP_200_OK) # verify we got back a response OK cap_sender = response.data[0]['cap_sender'] self.assertEqual(cap_sender, '*****@*****.**') # test to sender
private_apis = patterns('', url(r'^api-token-auth/', 'rest_framework.authtoken.views.obtain_auth_token'), url(r'^api/v1/users/$', UserList.as_view()), url(r'^api/v1/users/(?P<pk>[0-9]+)/$', UserDetail.as_view()), url(r'^api/v1/users/profiles/$', UserDetail.as_view()), url(r'^api/v1/users/profiles/(?P<pk>[0-9]+)/$', UserDetail.as_view()), url(r'^api/v1/users/locations/$', LocationList.as_view()), url(r'^api/v1/users/locations/(?P<pk>[0-9]+)/$', LocationDetail.as_view()), ) # A section for APIs (goes first) # Private APIs are given a namespace in case we want to use Swagger to do API documentation urlpatterns = [ url(r'^', include(private_apis, namespace="private_apis")), url(r'^api/v1/alerts/$', AlertListAPI.as_view()), url(r'^api/v1/alerts/(?P<cap_slug>\w+)/$', cache_page(60*60)(AlertDetailAPI.as_view())), url(r'^api/v1/alerts/(?P<cap_slug>\w+)/areas/$', AlertAreaAPI.as_view()), ] # The rest of stuff urlpatterns = urlpatterns + [ url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'), url(r'^dashboard/$', login_required(SettingsView.as_view()), name='settings-view'), url(r'^dashboard/locations/$', login_required(LocationView.as_view()), name='location-view'), url(r'^dashboard/settings/$', login_required(SettingsView.as_view()), name='settings-view'), url(r'^alerts/(?P<cap_slug>\w+)/$', cache_page(60)(AlertDetailView.as_view()), name='alert-details-view'), url(r'^accounts/', include('allauth.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), ]
'', url(r'^api-token-auth/', 'rest_framework.authtoken.views.obtain_auth_token'), url(r'^api/v1/users/$', UserList.as_view()), url(r'^api/v1/users/(?P<pk>[0-9]+)/$', UserDetail.as_view()), url(r'^api/v1/users/profiles/$', UserDetail.as_view()), url(r'^api/v1/users/profiles/(?P<pk>[0-9]+)/$', UserDetail.as_view()), url(r'^api/v1/users/locations/$', LocationList.as_view()), url(r'^api/v1/users/locations/(?P<pk>[0-9]+)/$', LocationDetail.as_view()), ) # A section for APIs (goes first) # Private APIs are given a namespace in case we want to use Swagger to do API documentation urlpatterns = [ url(r'^', include(private_apis, namespace="private_apis")), url(r'^api/v1/alerts/$', AlertListAPI.as_view()), url(r'^api/v1/alerts/(?P<cap_slug>\w+)/$', cache_page(60 * 60)(AlertDetailAPI.as_view())), url(r'^api/v1/alerts/(?P<cap_slug>\w+)/areas/$', AlertAreaAPI.as_view()), ] # The rest of stuff urlpatterns = urlpatterns + [ url(r'^schema/$', schema_view), url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'), url(r'^dashboard/$', login_required(SettingsView.as_view()), name='settings-view'), url(r'^dashboard/locations/$', login_required(LocationView.as_view()), name='location-view'),