Ejemplo n.º 1
0
    def test_filter_apartments(self):
        realtor = UserFactory.create_realtor(verified=True)
        client = UserFactory.create_client(verified=True)

        ApartmentFactory.create_apartment(realtor)
        ApartmentFactory.create_apartment(realtor)

        self.client.force_authenticate(user=client)

        url = '{}?min_size=70'.format(self.url)
        response = self.client.get(url, format='json')
        self.assertEqual(len(response.json().get('results')), 2)

        url = '{}?min_size=90'.format(self.url)
        response = self.client.get(url, format='json')
        self.assertEqual(len(response.json().get('results')), 0)

        url = '{}?max_price=300'.format(self.url)
        response = self.client.get(url, format='json')
        self.assertEqual(len(response.json().get('results')), 0)

        url = '{}?number_of_rooms=4'.format(self.url)
        response = self.client.get(url, format='json')
        self.assertEqual(len(response.json().get('results')), 2)

        url = '{}?number_of_rooms=2'.format(self.url)
        response = self.client.get(url, format='json')
        self.assertEqual(len(response.json().get('results')), 0)
Ejemplo n.º 2
0
    def test_client_create_apartment(self):
        client = UserFactory.create_client(verified=True)

        self.client.force_authenticate(user=client)
        response = self.client.post(self.url,
                                    self.apartment_data,
                                    format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 3
0
    def test_client_get_update_delete_another(self):
        client1 = UserFactory.create_client(verified=True)
        client2 = UserFactory.create_client(email='*****@*****.**',
                                            verified=True)

        url = '{}{}/'.format(self.user_url, client2.id)
        self.client.force_authenticate(user=client1)

        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        body = {'last_name': 'Lastname changed'}
        response = self.client.patch(url, body, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 4
0
    def test_client_get_apartments(self):
        client = UserFactory.create_client(verified=True)
        owner = UserFactory.create_realtor(verified=True)
        ApartmentFactory.create_apartment(owner)
        ApartmentFactory.create_apartment(owner, status='Rented')

        self.client.force_authenticate(user=client)
        response = self.client.get(self.url, format='json')
        self.assertEqual(len(response.json().get('results')), 1)
Ejemplo n.º 5
0
    def test_block_user_with_3_attempts(self):
        user = UserFactory.create_client(verified=True)

        credential = {'email': '*****@*****.**', 'password': '******'}
        self.client.post(self.login_url, credential, format='json')
        self.client.post(self.login_url, credential, format='json')
        response = self.client.post(self.login_url, credential, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        user.refresh_from_db()
        self.assertEqual(user.is_active, False)
Ejemplo n.º 6
0
    def test_admin_delete_user(self):
        admin = UserFactory.create_admin(verified=True)
        client = UserFactory.create_client()

        self.client.force_authenticate(user=admin)
        url = '{}{}/'.format(self.user_url, client.id)
        self.client.delete(url, format='json')

        with self.assertRaises(User.DoesNotExist):
            User.objects.get(pk=client.id)
Ejemplo n.º 7
0
    def test_admin_invite_existing_user(self):
        admin = UserFactory.create_admin(verified=True)
        client = UserFactory.create_client()

        self.client.force_authenticate(user=admin)
        url = '{}invite/'.format(self.user_url)
        body = {'email': client.email}
        response = self.client.post(url, body, format='json')

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 8
0
    def test_admin_update_user(self):
        admin = UserFactory.create_admin(verified=True)
        client = UserFactory.create_client()

        self.client.force_authenticate(user=admin)
        url = '{}{}/'.format(self.user_url, client.id)
        body = {'last_name': 'User Editted'}
        response = self.client.patch(url, body, format='json')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json().get('last_name'), 'User Editted')
Ejemplo n.º 9
0
    def test_client_update_delete_apartment(self):
        client = UserFactory.create_client(verified=True)
        owner = UserFactory.create_realtor(verified=True)
        apartment = ApartmentFactory.create_apartment(owner)

        body = {'name': 'Apartment new name'}
        url = '{}{}/'.format(self.url, apartment.id)
        self.client.force_authenticate(user=client)
        response = self.client.patch(url, body, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 10
0
    def test_client_get_update_delete_themself(self):
        client = UserFactory.create_client(verified=True)
        url = '{}{}/'.format(self.user_url, client.id)
        self.client.force_authenticate(user=client)

        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        body = {'last_name': 'My lastname changed'}
        response = self.client.patch(url, body, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 11
0
    def test_login_user_success(self):
        UserFactory.create_client(verified=True)

        credential = {'email': '*****@*****.**', 'password': '******'}
        response = self.client.post(self.login_url, credential, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 12
0
    def test_login_user_without_email_verification(self):
        UserFactory.create_client()

        credential = {'email': '*****@*****.**', 'password': '******'}
        response = self.client.post(self.login_url, credential, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)