def test_get_queryset_not_published(self): """ Test that the queryset returned is as expected a LettingQuerySet """ sale = SaleFactory.create(status=Sale.STATUS_CHOICE_INACTIVE) request = self.factory.get( reverse('sales:detail', kwargs={'slug': sale.slug})) request.user = AnonymousUser() with self.assertRaises(Http404): DetailPageView.as_view()(request, slug=sale.slug)
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) sale = SaleFactory.create(expires_at=expired_date) request = self.factory.get( reverse('sales:detail', kwargs={'slug': sale.slug})) request.user = AnonymousUser() with self.assertRaises(Http404): DetailPageView.as_view()(request, slug=sale.slug)
def test_template_name(self): """ Test that the template name of the view is as expected """ sale = SaleFactory() request = self.factory.get( reverse('sales:detail', kwargs={'slug': sale.slug})) request.user = UserFactory() response = DetailPageView.as_view()(request, slug=sale.slug) # Check that the correct template is used for the view self.assertIn('homes-for-sale/detail.html', response.template_name)
def test_favourited_context_user_anon(self): """ Test that a property is not favourited by a anonymous user """ favourite = SaleFavouriteFactory() request = self.factory.get( reverse('sales: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'])
def test_favourited_context_is_true(self): """ Test that a property is favourited by the user """ favourite = SaleFavouriteFactory() request = self.factory.get( reverse('sales: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'])
def test_get_context_keys_correct_type(self): """ Test that the context contains required keys in context """ sale = SaleFactory() request = self.factory.get( reverse('sales:detail', kwargs={'slug': sale.slug})) request.user = UserFactory() response = DetailPageView.as_view()(request, slug=sale.slug) # Check contains contact as SaleContactForm and form as SearchForm self.assertIsInstance(response.context_data['contact'], SaleContactForm) self.assertIsInstance(response.context_data['form'], SearchForm)
def test_get_queryset(self): """ Test that the queryset returned is as expected a SaleQuerySet """ sale = SaleFactory() request = self.factory.get( reverse('sales:detail', kwargs={'slug': sale.slug})) view = super(DetailPageViewTestCase, self).initialize(DetailPageView(), request, kwargs={'slug': sale.slug}) response = view.get_queryset() # Check if response is LettingQuerySet self.assertIsInstance(response, SaleQuerySet)
def test_get_context_contains_keys(self): """ Test that the context contains required keys in context """ sale = SaleFactory() request = self.factory.get( reverse('sales:detail', kwargs={'slug': sale.slug})) request.user = UserFactory() response = DetailPageView.as_view()(request, slug=sale.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)