Ejemplo n.º 1
0
    def test_get_queryset_long_lat_provided(self):
        """
        Test to check returns a LettingQuerySet when latitude and longitude provided
        """
        request = self.factory.get(reverse('lettings:search') + '?latitude=0&longitude=1')

        request.user = AnonymousUser()

        view = super(SearchPageViewTestCase, self).initialize(SearchPageView(), request)

        # Check that the get_queryset function returns a LettingQuerySet
        self.assertIsInstance(view.get_queryset(), LettingQuerySet)
Ejemplo n.º 2
0
    def test_template_name(self):
        """
        Test that the template name of the view is as expected
        """
        request = self.factory.get(reverse('lettings:search') + '?latitude=0&longitude=1')

        request.user = AnonymousUser()

        response = SearchPageView.as_view()(request)

        # Check that the homes-to-let-search.html template is used for this response
        self.assertIn('homes-to-let/search.html',response.template_name)
Ejemplo n.º 3
0
    def test_get_queryset_long_lat_missing(self):
        """
        Test to check throws 404 if long,lat missing
        """
        request = self.factory.get(reverse('lettings:search'))

        request.user = AnonymousUser()

        view = super(SearchPageViewTestCase, self).initialize(SearchPageView(), request)

        # Check if the view.get_queryset() raises a 404 - it should as get_point tries to form
        # a GEOSGeometry with insufficient data, catches initial exception, rethrows new 404
        with self.assertRaises(Http404):
            view.get_queryset()
Ejemplo n.º 4
0
    def test_get_context_keys_correct_type(self):
        """
        Test that the context contains required keys in context
        """
        request = self.factory.get(reverse('lettings:search'))
        request.user = AnonymousUser()

        view = super(SearchPageViewTestCase, self).initialize(SearchPageView(), request)
        view.object_list = []

        response = view.get_context_data()

        # Check contains distance as LettingDistanceForm and form as SearchForm
        self.assertIsInstance(response['distance'], LettingDistanceForm)
        self.assertIsInstance(response['form'], SearchForm)
Ejemplo n.º 5
0
    def test_get_context_unauthenticated_not_subscribed(self):
        """
        Test that on hitting the get_context function when anonymous returns
        false for subscribed value
        """
        request = self.factory.get(reverse('lettings:search'))
        request.user = AnonymousUser()

        view = super(SearchPageViewTestCase, self).initialize(SearchPageView(), request)
        view.object_list = []

        response = view.get_context_data()

        # Check that the subscribed key is in context data and that subscribed is false
        # as the user is not authenticated and not subscribed
        self.assertIn('subscribed', response)
        self.assertFalse(response['subscribed'])
Ejemplo n.º 6
0
    def test_get_context_contains_keys(self):
        """
        Test that the context contains required keys in context
        """
        request = self.factory.get(reverse('lettings:search'))
        request.user = AnonymousUser()

        view = super(SearchPageViewTestCase, self).initialize(SearchPageView(), request)
        view.object_list = []

        response = view.get_context_data()

        # Check contains distance, subscribed, paginator, view and form
        self.assertIn('distance', response)
        self.assertIn('subscribed', response)
        self.assertIn('paginator', response)
        self.assertIn('view', response)
        self.assertIn('form', response)
Ejemplo n.º 7
0
    def test_get_context_authenticated_not_subscribed(self):
        """
        Test that on hitting the get_context function when authenticated and subscribed to alert
        that subscribed returns true
        """
        user = UserFactory()

        request = self.factory.get(reverse('lettings:search') + '?' + urlencode({'test1': 'test','test2': 'test'}))
        request.user = user

        view = super(SearchPageViewTestCase, self).initialize(SearchPageView(), request)
        view.object_list = []

        response = view.get_context_data()

        # Check that the context has the subscribed key and it is set to false as the user is logged in but there
        # are no alerts he/she is subscribed to
        self.assertIn('subscribed', response)
        self.assertFalse(response['subscribed'])
Ejemplo n.º 8
0
    def test_get_context_authenticated_and_subscribed(self):
        """
        Test that on hitting the get_context function when authenticated and subscribed to alert
        that subscribed returns true
        """
        user = UserFactory()

        # Subscribe the user to an alert
        alert = AlertFactory(user=user, criteria={'test1': 'test','test2': 'test'})

        request = self.factory.get(reverse('lettings:search') + '?' + urlencode({'test1': 'test','test2': 'test'}))
        request.user = user

        view = super(SearchPageViewTestCase, self).initialize(SearchPageView(), request)
        view.object_list = []

        response = view.get_context_data()

        # Check if the context has the subscribed key and that it is set to true
        self.assertIn('subscribed', response)
        self.assertTrue(response['subscribed'])