Пример #1
0
    def test_opensearch_itemsPerPage(self, rf):
        factories.EventFactory.create_batch(10)
        request = rf.get('/')
        response = views.json_event_search(request)
        data = json.loads(response.content)

        assert data['feed']['opensearch:itemsPerPage'] == self.RESULTS_PER_PAGE
Пример #2
0
    def test_opensearch_startIndex(self, rf):
        factories.EventFactory.create_batch(10)
        request = rf.get('/')
        response = views.json_event_search(request)
        data = json.loads(response.content)

        assert data['feed']['opensearch:startIndex'] == '1'
 def test_results_per_page(self, rf):
     per_page = self.RESULTS_PER_PAGE
     factories.EventFactory.create_batch(per_page*4)
     request = rf.get('/')
     response = views.json_event_search(request)
     data = json.loads(response.content)
     assert len(data['feed']['entry']) == per_page
Пример #4
0
    def test_opensearch_query(self, rf):
        factories.EventFactory.create_batch(10)
        request = rf.get('/fakefield=true')
        response = views.json_event_search(request)
        data = json.loads(response.content)

        assert data['feed']['opensearch:Query'] == request.GET
Пример #5
0
    def test_opensearch_totalResults(self, rf):
        num_events = 100
        factories.EventFactory.create_batch(num_events)
        request = rf.get('/')
        response = views.json_event_search(request)
        data = json.loads(response.content)

        assert data['feed']['opensearch:totalResults'] == num_events
Пример #6
0
    def test_filter_by_event_type(self, rf):
        event_type = 'Test Event Type'
        factories.EventFactory.create_batch(30)
        event = factories.EventFactory.create(event_type=event_type)

        request = rf.get('/?type={0}'.format(event_type))
        response = views.json_event_search(request)

        assert self.response_has_entry(response, event)
Пример #7
0
    def test_filter_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.json_event_search(request)

        assert self.response_has_entry(response, event)
Пример #8
0
 def test_no_results(self, rf):
     """Check that response content when there are no Events
     in the database.
     """
     request = rf.get('/')
     response = views.json_event_search(request)
     data = json.loads(response.content)
     assert len(data) == 0
     assert response.status_code == 200
    def test_filter_by_event_type(self, rf):
        event_type = random.choice(EVENT_TYPE_CHOICES)[0]
        factories.EventFactory.create_batch(10)
        event = factories.EventFactory.create(event_type=event_type)

        request = rf.get('/?event_type={0}'.format(urlquote(event_type)))
        response = views.json_event_search(request)

        assert self.response_includes_event(response, event)
Пример #10
0
    def test_filter_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 = '/?linked_object_id={0}'.format(linking_object.object_identifier)
        request = rf.get(url)
        response = views.json_event_search(request)

        assert self.response_has_entry(response, event)
 def test_no_results(self, rf):
     """Check the response content when there are no Events
     in the database.
     """
     request = rf.get('/')
     response = views.json_event_search(request)
     data = json.loads(response.content)
     assert data.get('feed') is not None
     assert data.get('feed', {}).get('entry') is not None
     assert not len(data.get('feed', {}).get('entry'))
     assert response.status_code == 200
Пример #12
0
    def test_pagination_links(self, rf):
        num_events = self.RESULTS_PER_PAGE * 3
        factories.EventFactory.create_batch(num_events)
        request = rf.get('/?page=2')
        response = views.json_event_search(request)
        data = json.loads(response.content)

        assert len(data['feed']['link']) == 5

        for link in data['feed']['link']:
            if link['rel'] == self.REL_SELF:
                assert 'page=2' in link['href']
            elif link['rel'] == self.REL_PREVIOUS:
                assert 'page=1' in link['href']
            elif link['rel'] == self.REL_FIRST:
                assert 'page=1' in link['href']
            elif link['rel'] == self.REL_NEXT:
                assert 'page=3' in link['href']
            elif link['rel'] == self.REL_LAST:
                assert 'page=3' in link['href']
Пример #13
0
 def test_response_content_type(self, rf):
     request = rf.get('/')
     response = views.json_event_search(request)
     assert response.get('Content-Type') == self.CONTENT_TYPE
Пример #14
0
 def test_returns_ok(self, rf):
     request = rf.get('/')
     response = views.json_event_search(request)
     assert response.status_code == 200