diff --git a/django_lostplaces/lostplaces/tests/views/test_place_views.py b/django_lostplaces/lostplaces/tests/views/test_place_views.py index 3f780f3..8bebd2d 100644 --- a/django_lostplaces/lostplaces/tests/views/test_place_views.py +++ b/django_lostplaces/lostplaces/tests/views/test_place_views.py @@ -48,7 +48,7 @@ class TestPlaceListView(GlobalTemplateTestCaseMixin, ViewTestCase): location='Test %d town' % i, latitude=50.5 + i/10, longitude=7.0 - i/10, - description='This is just a test, do not worry' + description='This is just a test, do not worry %d' % i ) place.tags.add('I a tag', 'testlocation') place.save() @@ -63,6 +63,21 @@ class TestPlaceListView(GlobalTemplateTestCaseMixin, ViewTestCase): self.assertContext(response, 'mapping_config') self.assertGlobal(response) + def test_first_places(self): + self.client.login(username='testpeter', password='Develop123') + response = self.client.get(reverse('place_list')) + + for i in range(1, 4): + place = Place.objects.get(id=i) + self.assertTrue( + place.name in response.content.decode(), + msg='Expecting the %dth place name to be on the first page of list' % i + ) + self.assertTrue( + place.description in response.content.decode(), + msg='Expecting the %dth place description to be on the first page of list' % i + ) + def test_pagination(self): self.client.login(username='testpeter', password='Develop123') response = self.client.get(reverse('place_list')) @@ -338,3 +353,131 @@ class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixi ) ) self.assertMapableContext(response.context['mapping_config']) + + def test_place_data(self): + self.client.login(username='testpeter', password='Develop123') + response = self.client.get(reverse('place_detail', kwargs={'pk': 1})) + place = Place.objects.get(id=1) + + self.assertTrue( + place.name in response.content.decode(), + msg='Expecting the places name to be on the page' + ) + self.assertTrue( + place.description in response.content.decode(), + msg='Expecting the places description to be on the page' + ) + self.assertTrue( + str(place.latitude) in response.content.decode(), + msg='Expecting the places latitude to be on the page' + ) + self.assertTrue( + str(place.longitude) in response.content.decode(), + msg='Expecting the places longitude to be on the page' + ) + + def test_favorite(self): + self.client.login(username='testpeter', password='Develop123') + response = self.client.get(reverse('place_detail', kwargs={'pk': 1})) + + user = User.objects.get(username='testpeter') + place = Place.objects.get(id=1) + + self.assertTrue( + reverse('place_favorite', kwargs={'place_id': 1}) in response.content.decode(), + msg='Expecting the (right) create favorite url to be on the page ' + ) + + response = self.client.get( + reverse('place_favorite', kwargs={'place_id': 1}), + follow=True + ) + self.assertHttpOK(response) + + self.assertTrue( + reverse('place_unfavorite', kwargs={'place_id': 1}) in response.content.decode(), + msg='Expecting the (right) delete favorite url to be on the page ' + ) + + self.assertTrue( + place in user.explorer.favorite_places.all(), + msg='Expecting the place to be in the explorers favorites' + ) + self.assertTrue( + user.explorer in place.explorer_favorites.all(), + msg='Expecting the explorere to be in the reverse list of favorites' + ) + + response = self.client.get( + reverse('place_unfavorite', kwargs={'place_id': 1}), + follow=True + ) + self.assertHttpOK(response) + self.assertTrue( + reverse('place_favorite', kwargs={'place_id': 1}) in response.content.decode(), + msg='Expecting the (right) create favorite url to be on the page after unfavorite' + ) + + self.assertTrue( + place not in user.explorer.favorite_places.all(), + msg='Expecting the place to not be in the explorers favorites after unfavorite' + ) + self.assertTrue( + user.explorer not in place.explorer_favorites.all(), + msg='Expecting the explorere to not be in the reverse list of favorites after unfavorite' + ) + + + def test_visit(self): + self.client.login(username='testpeter', password='Develop123') + response = self.client.get(reverse('place_detail', kwargs={'pk': 1})) + + user = User.objects.get(username='testpeter') + place = Place.objects.get(id=1) + + self.assertTrue( + reverse('place_visit_create', kwargs={'place_id': 1}) in response.content.decode(), + msg='Expecting the (right) create visit url to be on the page ' + ) + + response = self.client.get( + reverse('place_visit_create', kwargs={'place_id': 1}), + follow=True + ) + self.assertHttpOK(response) + + self.assertTrue( + reverse('place_visit_delete', kwargs={'place_id': 1}) in response.content.decode(), + msg='Expecting the (right) delete visist url to be on the page ' + ) + + self.assertTrue( + place in user.explorer.visited_places.all(), + msg='Expecting the place to be in the explorers visits' + ) + self.assertTrue( + user.explorer in place.explorer_visits.all(), + msg='Expecting the explorer to be in the reverse list of visits' + ) + + response = self.client.get( + reverse('place_visit_delete', kwargs={'place_id': 1}), + follow=True + ) + self.assertHttpOK(response) + self.assertTrue( + reverse('place_visit_create', kwargs={'place_id': 1}) in response.content.decode(), + msg='Expecting the (right) create favorite url to be on the page after deleting visit' + ) + + self.assertTrue( + place not in user.explorer.visited_places.all(), + msg='Expecting the place to not be in the explorers visits after deleting visit' + ) + self.assertTrue( + user.explorer not in place.explorer_visits.all(), + msg='Expecting the explorer to not be in the reverse list of visits after deleting visit' + ) + + + \ No newline at end of file