Ejemplo n.º 1
0
    def test_get_queryset_not_published(self):
        """
         Test that the queryset returned is as expected a LettingQuerySet
         """
        letting = LettingFactory.create(status=Letting.STATUS_CHOICE_INACTIVE)

        request = self.factory.get(reverse('lettings:detail', kwargs={
            'slug': letting.slug
        }))

        request.user = AnonymousUser()

        with self.assertRaises(Http404):
            DetailPageView.as_view()(request, slug=letting.slug)
Ejemplo n.º 2
0
    def test_get_queryset_expired(self):
        """
         Test that the queryset returned is as expected a LettingQuerySet
         """
        expired_date = datetime.utcnow().replace(tzinfo=pytz.utc) - timedelta(days=1)
        letting = LettingFactory.create(expires_at=expired_date)

        request = self.factory.get(reverse('lettings:detail', kwargs={
            'slug': letting.slug
        }))

        request.user = AnonymousUser()

        with self.assertRaises(Http404):
            DetailPageView.as_view()(request, slug=letting.slug)
Ejemplo n.º 3
0
    def test_template_name(self):
        """
        Test that the template name of the view is as expected
        """
        letting = LettingFactory()
        request = self.factory.get(reverse('lettings:detail', kwargs={
            'slug': letting.slug
        }))

        request.user = UserFactory()

        response = DetailPageView.as_view()(request, slug=letting.slug)

        # Check that the correct template is used for the view
        self.assertIn('homes-to-let/detail.html', response.template_name)
Ejemplo n.º 4
0
    def test_get_queryset(self):
        """
         Test that the queryset returned is as expected a LettingQuerySet
         """
        letting = LettingFactory()

        request = self.factory.get(reverse('lettings:detail', kwargs={
            'slug': letting.slug
        }))

        view = super(DetailPageViewTestCase, self).initialize(DetailPageView(), request, kwargs={'slug':letting.slug})

        response = view.get_queryset()

        # Check if response is LettingQuerySet
        self.assertIsInstance(response, LettingQuerySet)
Ejemplo n.º 5
0
    def test_favourited_context_user_anon(self):
        """
         Test that a property is not favourited by a anonymous user
         """
        favourite = LettingFavouriteFactory()

        request = self.factory.get(reverse('lettings:detail', kwargs={
            'slug': favourite.property.slug
        }))

        request.user = AnonymousUser()

        response = DetailPageView.as_view()(request, slug=favourite.property.slug)

        # Check that the favourited context data is found but that it is set to false (not favourited)
        self.assertIn('favourited', response.context_data)
        self.assertFalse(response.context_data['favourited'])
Ejemplo n.º 6
0
    def test_favourited_context_is_true(self):
        """
        Test that a property is favourited by the user
        """
        favourite = LettingFavouriteFactory()

        request = self.factory.get(reverse('lettings:detail', kwargs={
            'slug': favourite.property.slug
        }))

        request.user = favourite.user

        response = DetailPageView.as_view()(request, slug=favourite.property.slug)

        # Check that the favourited context data is found but that it is set to true it is favourited
        self.assertIn('favourited', response.context_data)
        self.assertTrue(response.context_data['favourited'])
Ejemplo n.º 7
0
    def test_get_context_keys_correct_type(self):
        """
        Test that the context contains required keys in context
        """
        letting = LettingFactory()

        request = self.factory.get(reverse('lettings:detail', kwargs={
            'slug': letting.slug
        }))

        request.user = UserFactory()

        response = DetailPageView.as_view()(request, slug=letting.slug)

        # Check contains contact as LettingContactForm and form as SearchForm
        self.assertIsInstance(response.context_data['contact'], LettingContactForm)
        self.assertIsInstance(response.context_data['form'], SearchForm)
Ejemplo n.º 8
0
    def test_get_context_contains_keys(self):
        """
        Test that the context contains required keys in context
        """
        letting = LettingFactory()
        request = self.factory.get(reverse('lettings:detail', kwargs={
            'slug': letting.slug
        }))

        request.user = UserFactory()

        response = DetailPageView.as_view()(request, slug=letting.slug)

        # Check that the context contains the correct keys
        self.assertIn('contact', response.context_data)
        self.assertIn('favourited', response.context_data)
        self.assertIn('form', response.context_data)
        self.assertIn('google', response.context_data)
        self.assertIn('recaptcha', response.context_data)