Пример #1
0
    def test_get(self, m_coordinates):
        PropertyFactory.create_batch(3)

        PropertyFactory(title='not available', is_available=False)

        response = self.client.get(reverse('property-available'))
        self.assertEqual(response.status_code, 200)

        qs = response.context['object_list']

        self.assertEqual(qs.count(), 3)
Пример #2
0
    def test_update_coordinates(self, m_geocoder):
        point = mock.Mock(lat=-22.902935, lng=-43.176592)
        m_geocoder.google.return_value = point

        # the task will be triggered by factory
        office = PropertyFactory(
            address='Lopes Mendes', point=Point(-23.167065, -44.139270))

        update_coordinates(office.id, office.address)

        m_geocoder.google.assert_called_once_with('Lopes Mendes')
Пример #3
0
    def test_get(self, m_coordinates):
        office = PropertyFactory(
            title='Point A',
            address='Rua do Carmo',
            point=Point(-22.902935, -43.176592))

        related = PropertyFactory(
            title='Point B',
            address='Rio Branco',
            point=Point(-22.907005, -43.176262))

        far = PropertyFactory(
            title='Point C',
            address='Parati',
            point=Point(-23.167065, -44.139270))

        response = self.client.get(
            reverse('property-available-detail', args=[office.slug]))
        self.assertEqual(response.status_code, 200)

        qs = response.context['related']

        self.assertEqual(qs.count(), 1)
        self.assertIsNotNone(qs.get(title=related.title))
Пример #4
0
    def test_post_invalid_form(self, m_coordinates):
        self.client.login(username='******', password='******')

        office = PropertyFactory()

        response = self.client.post(
            reverse('property-update', args=[office.slug]),
            {
                'title': 'almost changed',
                'property_type': 'home',
                'price': 7
            })

        self.assertEqual(response.status_code, 200)
        self.assertFormError(
            response, 'form', 'address', 'This field is required.')
Пример #5
0
    def test_post(self, m_coordinates):
        self.client.login(username='******', password='******')

        office = PropertyFactory(
            address='Avenida Rio Branco, 156, Centro, Rio de Janeiro')

        response = self.client.post(
            reverse('property-update', args=[office.slug]),
            {
                'title': 'The Changed office',
                'description': 'work',
                'address': 'Rua do Carmo, 71 - Centro, Rio de Janeiro - RJ',
                'is_available': True,
                'price': 42.5,
                'property_type': 'commercial'
            }
        )

        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, '/property/the-changed-office/')

        m_coordinates.delay.assert_called()
Пример #6
0
    def test_delete(self, m_coordinates):
        office = PropertyFactory()

        response = self.client.delete(
            reverse('property-delete', args=[office.slug]))
        self.assertEqual(response.status_code, 302)