Beispiel #1
0
    def test_post_creates_event(self, event_xml, rf):
        assert models.Event.objects.count() == 0
        request = rf.post(
            '/',
            event_xml.entry_xml,
            content_type='application/xml',
            HTTP_HOST='example.com')

        views.app_event(request)
        assert models.Event.objects.count() == 1
Beispiel #2
0
    def test_head_and_get_headers_match_without_identifier(self, rf):
        head_request, get_request = rf.head('/'), rf.get('/')

        head_response = views.app_event(head_request)
        get_response = views.app_event(get_request)

        expected_headers = get_response.serialize_headers()
        actual_headers = head_response.serialize_headers()

        assert expected_headers == actual_headers, 'The response headers do not match.'
Beispiel #3
0
    def test_head_and_get_headers_match_with_identifier(self, rf):
        event = factories.EventFactory.create()

        head_request = rf.head('/', HTTP_HOST='example.com')
        get_request = rf.get('/', HTTP_HOST='example.com')

        head_response = views.app_event(head_request, event.event_identifier)
        get_response = views.app_event(get_request, event.event_identifier)

        expected_headers = get_response.serialize_headers()
        actual_headers = head_response.serialize_headers()

        assert expected_headers == actual_headers, 'The response headers do not match.'
Beispiel #4
0
    def test_list_number_of_events(self, rf):
        factories.EventFactory.create_batch(self.RESULTS_PER_PAGE * 2)
        request = rf.get('/')
        response = views.app_event(request)
        xml = objectify.fromstring(response.content)

        assert len(xml.entry) == self.RESULTS_PER_PAGE
Beispiel #5
0
    def test_list_filtering_by_end_date(self, rf):
        datetime_obj = timezone.now().replace(2015, 1, 1)
        factories.EventFactory.create_batch(30, event_date_time=timezone.now())
        event = factories.EventFactory.create(event_date_time=datetime_obj)

        request = rf.get('/?end_date=01/31/2015')
        response = views.app_event(request)
        assert self.response_has_event(response, event)
Beispiel #6
0
    def test_post_response_content_type(self, event_xml, rf):
        request = rf.post(
            '/',
            event_xml.entry_xml,
            content_type='application/xml',
            HTTP_HOST='example.com')

        response = views.app_event(request)
        assert response.get('Content-Type') == self.CONTENT_TYPE
Beispiel #7
0
    def test_list_filtering_by_event_type(self, rf):
        factories.EventFactory.create_batch(30)

        event_type = 'Test Type'
        event = factories.EventFactory.create(event_type=event_type)

        request = rf.get('?type={0}'.format(event_type))
        response = views.app_event(request)
        assert self.response_has_event(response, event)
    def test_list_filtering_by_event_type(self, rf):
        factories.EventFactory.create_batch(10)

        event_type = random.choice(EVENT_TYPE_CHOICES)
        event = factories.EventFactory.create(event_type=event_type)

        request = rf.get('?event_type={0}'.format(urlquote(event_type)))
        response = views.app_event(request)
        assert self.response_includes_event(response, event)
Beispiel #9
0
    def test_post_returns_created(self, event_xml, rf):
        request = rf.post(
            '/',
            event_xml.entry_xml,
            content_type='application/xml',
            HTTP_HOST='example.com')

        response = views.app_event(request)
        assert response.status_code == 201
Beispiel #10
0
    def test_post_response_content(self, event_xml, rf):
        request = rf.post(
            '/',
            event_xml.entry_xml,
            content_type='application/xml',
            HTTP_HOST='example.com')

        response = views.app_event(request)
        identifier = event_xml.identifier
        assert identifier in response.content
Beispiel #11
0
    def test_list_filtering_by_linking_object_id(self, rf):
        factories.EventFactory.create_batch(30)
        event = factories.EventFactory.create(linking_objects=True)
        linking_object = event.linking_objects.first()

        url = '/?link_object_id={0}'.format(linking_object.object_identifier)
        request = rf.get(url)
        response = views.app_event(request)

        assert self.response_has_event(response, event)
Beispiel #12
0
    def test_put_returns_ok(self, event_xml, rf):
        identifier = event_xml.identifier
        factories.EventFactory.create(event_identifier=identifier)

        request = rf.put(
            '/',
            event_xml.entry_xml,
            content_type='application/xml',
            HTTP_HOST='example.com')

        response = views.app_event(request, identifier)

        assert response.status_code == 200
Beispiel #13
0
    def test_put_response_content_type(self, event_xml, rf):
        identifier = event_xml.identifier
        factories.EventFactory.create(event_identifier=identifier)

        request = rf.put(
            '/',
            event_xml.entry_xml,
            content_type='application/xml',
            HTTP_HOST='example.com')

        response = views.app_event(request, identifier)

        assert response.get('Content-Type') == self.CONTENT_TYPE
Beispiel #14
0
    def test_list_ordering_descending(self, rf):
        events = factories.EventFactory.create_batch(3)
        events.sort(key=lambda e: e.event_identifier, reverse=True)

        # Order by the Event identifier because the values are globally unique.
        # Pure Python vs the Django ORM sort items with matching keys differently.
        request = rf.get('?orderby=event_identifier&orderdir=descending')
        response = views.app_event(request)

        list_events = objectify.fromstring(response.content).entry
        ordered_event_ids = [f.title for f in list_events]
        event_ids = [f.event_identifier for f in events]

        assert ordered_event_ids == event_ids
Beispiel #15
0
 def test_head_with_identifier(self, rf):
     event = factories.EventFactory.create()
     request = rf.head('/')
     response = views.app_event(request, event.event_identifier)
     assert response.content == '', 'The message body must be empty'
     assert response.status_code == 200
Beispiel #16
0
 def test_head_without_identifier(self, rf):
     request = rf.head('/')
     response = views.app_event(request)
     assert response.content == '', 'The message body must be empty'
     assert response.status_code == 200
Beispiel #17
0
 def test_delete_removes_event(self, rf):
     event = factories.EventFactory.create()
     request = rf.delete('/', HTTP_HOST='example.com')
     views.app_event(request, event.event_identifier)
     assert models.Agent.objects.count() == 0
Beispiel #18
0
 def test_delete_response_content(self, rf):
     event = factories.EventFactory.create()
     request = rf.delete('/', HTTP_HOST='example.com')
     response = views.app_event(request, event.event_identifier)
     assert event.event_identifier in response.content
Beispiel #19
0
 def test_delete_response_content_type(self, rf):
     event = factories.EventFactory.create()
     request = rf.delete('/', HTTP_HOST='example.com')
     response = views.app_event(request, event.event_identifier)
     assert response.get('Content-Type') == self.CONTENT_TYPE
Beispiel #20
0
 def test_delete_with_invalid_identifier_returns_not_found(self, rf):
     request = rf.delete('/', HTTP_HOST='example.com')
     response = views.app_event(request, 'ark:/00001/dne')
     assert response.status_code == 404
Beispiel #21
0
 def test_delete_returns_ok(self, rf):
     event = factories.EventFactory.create()
     request = rf.delete('/', HTTP_HOST='example.com')
     response = views.app_event(request, event.event_identifier)
     assert response.status_code == 200
Beispiel #22
0
 def test_list_ordering_with_unknown_attribute_returns_ok(self, rf):
     factories.EventFactory.create_batch(3)
     request = rf.get('?orderby=fake_attribute')
     response = views.app_event(request)
     assert response.status_code == 200
Beispiel #23
0
 def test_list_returns_ok(self, rf):
     factories.EventFactory.create_batch(30)
     request = rf.get('/')
     response = views.app_event(request)
     assert response.status_code == 200