Skip to content

Commit

Permalink
Tests working once more. Patched request.get now iterates through var…
Browse files Browse the repository at this point in the history
…ious return values. Not a good solution, but will suffice for now.
  • Loading branch information
ahaith committed Mar 10, 2015
1 parent 89472a0 commit 40f0ce5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
30 changes: 13 additions & 17 deletions talks/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
PAST_DATE_STRING = "2011-01-01 20:00"

TOPIC_1429860_MOCK_RESPONSE = {"_links":{"self":{"href":"/search?uri=http://id.worldcat.org/fast/1429860"}},"_embedded":{"concepts":[{"uri":"http://id.worldcat.org/fast/1429860","prefLabel":"Biodiversity","altLabels":["Biotic diversity","Diversification, Biological","Diversity, Biotic","Biological diversity","Diversity, Biological","Biological diversification"],"related":[{"label":"Biology","uri":"http://id.worldcat.org/fast/832383"},{"label":"Ecological heterogeneity","uri":"http://id.worldcat.org/fast/901453"}]}]}}
LOC_40002001_MOCK_RESPONSE = {"_embedded": {"pois": [{"_embedded": {"files": [{"location": "oxpoints/40002001/depiction/original/primary.jpg","primary": True,"type": "depiction","url": "//mox-static-files.oucs.ox.ac.uk/oxpoints/40002001/depiction/original/primary.jpg"},{"location": "oxpoints/40002001/depiction/original/primary.jpg","type": "depiction","url": "//mox-static-files.oucs.ox.ac.uk/oxpoints/40002001/depiction/original/primary.jpg"}]},"_links": {"child": [{"href": "/places/oxpoints:23233603"},{"href": "/places/oxpoints:23233671","title": "11-13 Banbury Road","type": ["/university/building"],"type_name": ["Building"]},{"href": "/places/oxpoints:23233670","title": "7-9 Banbury Road","type": ["/university/building"],"type_name": ["Building"]},{"href": "/places/oxpoints:23233669","title": "15-19 Banbury Road","type": ["/university/building"],"type_name": ["Building"]}],"parent": {"href": "/places/oxpoints:31337175","title": "IT Services","type": ["/university/department"],"type_name": ["Department"]},"self": {"href": "/places/oxpoints:40002001"}},"address": "7-19 Banbury Road OX2 6NN","alternative_names": ["IT Services, Banbury Road"],"distance": 0,"id": "oxpoints:40002001","identifiers": ["osm:99933769-way","oxpoints:40002001"],"lat": "51.76001","lon": "-1.26035","name": "7-19 Banbury Road","name_sort": "7-19 Banbury Road","shape": "POLYGON ((-1.2604547 51.7597247,-1.2604524 51.759703600000002,-1.2606225 51.759693400000003,-1.2606263 51.759717899999998,-1.2606718 51.759715200000002,-1.2606742 51.759729900000004,-1.260875 51.759717299999998,-1.2609002 51.759870900000003,-1.2609514 51.7598677,-1.2609628 51.759937299999997,-1.2609819 51.759936099999997,-1.2610376 51.760275399999998,-1.2606854 51.760297899999998,-1.260475 51.760310799999999,-1.2604334 51.7600865,-1.2605216 51.760081800000002,-1.2605182 51.760061299999997,-1.2605157 51.760043799999998,-1.2604056 51.760051799999999,-1.2603867 51.759929399999997,-1.2604979 51.759923100000002,-1.2604921 51.7598805,-1.2604867 51.759852799999997,-1.2603628 51.759858199999996,-1.2603454 51.759729800000002,-1.2604547 51.7597247))","type": ["/university/site"],"type_name": ["Site"]}]},"_links": {"self": {"href": "/places/oxpoints:40002001%2C"}},"count": 1}
DEP_23232503_MOCK_RESPONSE = {"_embedded": {"pois": [{"_links": {"child": [{"href": "/places/oxpoints:23232548"}],"parent": {"href": "/places/oxpoints:23232546","title": "Department of Chemistry","type": ["/university/department"],"type_name": ["Department"]},"primary_place": {"href": "/places/oxpoints:23232548"},"self": {"href": "/places/oxpoints:23232503"}},"address": "off South Parks Road OX1 3TA","alternative_names": ["Bayley Group"],"distance": 0,"id": "oxpoints:23232503","identifiers": ["oxpoints:23232503","finance:DQ"],"lat": "51.757797","lon": "-1.253332","name": "Chemical Biology","name_sort": "Chemical Biology","shape": "POLYGON ((-1.252908 51.758493199999997 0,-1.2525447 51.758077800000002 0,-1.252753 51.758007999999997 0,-1.2527069 51.757955299999999 0,-1.2532898 51.757759999999998 0,-1.2533847 51.7578685 0,-1.2532655 51.757908399999998 0,-1.2532846 51.757930299999998 0,-1.2533138 51.757963699999998 0,-1.2533718 51.757944299999998 0,-1.253638 51.758248700000003 0,-1.252908 51.758493199999997 0))","social_twitter": ["https://www.twitter.com/bayley_lab"],"type": ["/university/department"],"type_name": ["Department"],"website": "http://bayley.chem.ox.ac.uk/"}]},"_links": {"self": {"href": "/places/oxpoints:23232503%2C"}},"count": 1}


class TestAPI(TestCase):
Expand Down Expand Up @@ -74,23 +76,19 @@ def setUp(self):
role=ROLES_SPEAKER,
)
ct = ContentType.objects.get_for_model(models.Event)
print ct
ti = factories.TopicItemFactory_noSubFactory.create(
uri=self.topic1_uri,
content_type=ct,
object_id=future_event.id,
)
# ti = models.TopicItem.objects.get_or_create(uri=self.topic1_uri,
# content_type=ct,
# object_id=future_event.id)
ti.save()
future_event.save()
self.req_factory = APIRequestFactory()
self.client = APIClient()

@mock.patch('requests.get', autospec=True)
def test_retrieve_event_happy(self, requests_get):
requests_get.return_value.json.return_value = TOPIC_1429860_MOCK_RESPONSE
requests_get.return_value.json.side_effect = [LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE]
response = self.client.get('/api/talks/' + self.event1_slug)
self.assertEquals(response.status_code, 200)
self.assertContains(response, "_links")
Expand All @@ -103,7 +101,7 @@ def test_retrieve_event_404(self):

@mock.patch('requests.get', autospec=True)
def test_retrieve_series_happy(self, requests_get):
requests_get.return_value.json.return_value = TOPIC_1429860_MOCK_RESPONSE
requests_get.return_value.json.side_effect = [LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE]
response = self.client.get('/api/series/' + self.group1_slug)
self.assertEquals(response.status_code, 200)
self.assertContains(response, "talks conference")
Expand All @@ -127,51 +125,49 @@ def test_search_no_results(self):
def test_search_from_to(self, requests_get):
#test the from and to search fields
#expect only the future search
requests_get.return_value.json.return_value = TOPIC_1429860_MOCK_RESPONSE
requests_get.return_value.json.side_effect = [LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE]
response = self.client.get('/api/talks/search?from=01/01/15&to=01/01/20')
self.assertEquals(response.status_code, 200)
self.assertContains(response, "_links")
self.assertContains(response, "_embedded")
self.assertContains(response, "A future event")
#expect 2 results for this search
response = self.client.get('/api/talks/search?from=01/01/01')
self.assertContains(response, "title", 2)
# self.assertContains(response, "title", 2)
# No longer a valid test, as there are further titles within embedded data

@mock.patch('requests.get', autospec=True)
def test_search_speaker(self, requests_get):
requests_get.return_value.json.return_value = TOPIC_1429860_MOCK_RESPONSE
requests_get.return_value.json.side_effect = [LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE]
response = self.client.get('/api/talks/search?from=01/01/01&speaker=' + self.speaker1_slug )
self.assertEquals(response.status_code, 200)
self.assertContains(response, "_links")
self.assertContains(response, "_embedded")

# Note = currently failing since we don't yet embed speakers in event response
self.assertContains(response, "James Bond")
self.assertContains(response, "A future event")

@mock.patch('requests.get', autospec=True)
def test_search_venue(self, requests_get):
requests_get.return_value.json.return_value = TOPIC_1429860_MOCK_RESPONSE
requests_get.return_value.json.side_effect = [LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE]
response = self.client.get('/api/talks/search?from=01/01/01&venue=' + self.location1)
self.assertEquals(response.status_code, 200)
self.assertContains(response, "_links")
self.assertContains(response, "_embedded")
# TODO expose venue in response, will need further mockup
#self.assertContains(response, "Banbury Road")
self.assertContains(response, "Banbury Road")

@mock.patch('requests.get', autospec=True)
def test_search_organising_department(self, requests_get):
requests_get.return_value.json.return_value = TOPIC_1429860_MOCK_RESPONSE
requests_get.return_value.json.side_effect = [LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, DEP_23232503_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE]
response = self.client.get('/api/talks/search?from=01/01/01&organising_department=' + self.department1)
self.assertEquals(response.status_code, 200)
self.assertContains(response, "_links")
self.assertContains(response, "_embedded")
# TODO expose dept in response, will need further mockup
#self.assertContains(response, "Chemical Biology")
self.assertContains(response, "Chemical Biology")

@mock.patch('requests.get', autospec=True)
def test_search_topic(self, requests_get):
requests_get.return_value.json.return_value = TOPIC_1429860_MOCK_RESPONSE
requests_get.return_value.json.side_effect = [LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE, LOC_40002001_MOCK_RESPONSE, TOPIC_1429860_MOCK_RESPONSE]
response = self.client.get('/api/talks/search?from=01/01/01&topic=' + self.topic1_uri)
self.assertEquals(response.status_code, 200)
self.assertContains(response, "_links")
Expand Down
3 changes: 3 additions & 0 deletions talks/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
'topics': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
},
'department_descendant': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}

DEBUG = True
Expand Down

0 comments on commit 40f0ce5

Please sign in to comment.