Ejemplo n.º 1
0
 def test_property_tenure_queryset(self):
     sales = [
         SaleFactory(property_tenure=PropertyTenureFactory(slug='test',name='Test')),
         SaleFactory()
     ]
     results = Sale.filtered.tenure('test')
     self.assertEquals(len(results),1)
     self.assertEquals(results[0].title, sales[0].title)
Ejemplo n.º 2
0
 def test_shared_ownership_queryset(self):
     sales = [
         SaleFactory(shared_ownership=True),
         SaleFactory(shared_ownership=False)
     ]
     results = Sale.filtered.shared_ownership()
     self.assertEquals(len(results),1)
     self.assertEquals(results[0].title, sales[0].title)
Ejemplo n.º 3
0
 def test_auction_queryset(self):
     sales = [
         SaleFactory(auction=True),
         SaleFactory(auction=False)
     ]
     results = Sale.filtered.auction()
     self.assertEquals(len(results),1)
     self.assertEquals(results[0].title, sales[0].title)
Ejemplo n.º 4
0
 def test_expired_queryset(self):
     sales = [
         SaleFactory(expires_at=datetime.utcnow().replace(tzinfo=pytz.UTC) + timedelta(days=30)),
         SaleFactory(expires_at=datetime.utcnow().replace(tzinfo=pytz.UTC) + timedelta(days=-30))
     ]
     results = Sale.filtered.expired()
     self.assertEquals(len(results),1)
     self.assertEquals(results[0].title, sales[1].title)
Ejemplo n.º 5
0
 def test_new_home_queryset(self):
     sales = [
         SaleFactory(new_home=True),
         SaleFactory(new_home=False)
     ]
     results = Sale.filtered.new_home()
     self.assertEquals(len(results),1)
     self.assertEquals(results[0].title, sales[0].title)
Ejemplo n.º 6
0
 def test_unpublished_queryset(self):
     sales = [
         SaleFactory(status=Sale.STATUS_CHOICE_ACTIVE),
         SaleFactory(status=Sale.STATUS_CHOICE_INACTIVE)
     ]
     results = Sale.filtered.unpublished()
     self.assertEquals(len(results),1)
     self.assertEquals(results[0].title, sales[1].title)
Ejemplo n.º 7
0
    def test_user_delete_favourite(self):
        """
        Test that on hitting the delete favourite function when logged in, and in group causes favourite
        to be deleted
        """
        sale = SaleFactory()
        user = UserFactory.create(groups=[GroupFactory(name='general')])

        SaleFavouriteFactory(property=sale, user=user)

        request = self.factory.get(
            reverse('user:favourite',
                    kwargs={
                        'type': 'sale',
                        'slug': sale.slug
                    }))
        request.user = user

        request = self.enable_middleware(request)

        response = UserFavouriteView.as_view()(request,
                                               type='sale',
                                               slug=sale.slug)

        favourites = SaleFavourite.objects.filter(user=user,
                                                  property__slug=sale.slug)

        # Check that status code is 302 and redirect url is as expected and that the existing favourite was deleted
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, '/user/dashboard/')
        self.assertTrue(len(favourites) == 0)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
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)
        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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
    def test_user_logged_in_not_in_group(self):
        """
        Test that on hitting the favourite function when logged in, but not in group causes redirect
        """
        sale = SaleFactory()

        request = self.factory.get(
            reverse('user:favourite',
                    kwargs={
                        'type': 'sale',
                        'slug': sale.slug
                    }))
        request.user = UserFactory()

        response = UserFavouriteView.as_view()(request)

        # Check that status code is 302 and redirect url is as expected
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response.url,
            '/accounts/login/?next=/user/favourite/sale/{}/'.format(sale.slug))
Ejemplo n.º 15
0
 def test_string_representation(self):
     sale = SaleFactory()
     self.assertEquals(str(sale), sale.title)