Exemple #1
0
    def test_delete_listing_by_owner_auth_user_succeeds(self):
        owner = UserFactory()
        listing = ListingFactory(user=owner)
        self.sign_in_as_user(owner)

        response = self.client.delete(self.get_detail_url(listing.id))

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Exemple #2
0
    def test_update_listing_by_anon_fails(self):
        self.client.credentials()
        listing = ListingFactory()

        response = self.client.patch(self.get_detail_url(listing.id),
                                     self.listing_update_data)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
Exemple #3
0
    def test_update_listing_image_by_auth_user_on_owned_listing_succeeds(self):
        owned_listing = ListingFactory(user=self.user)
        owned_image = ListingImageFactory(listing=owned_listing)

        response = self.client.patch(self.get_detail_url(owned_image.id),
                                     self.valid_listing_image_update_data)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
Exemple #4
0
    def test_update_listing_by_non_owner_auth_user_fails(self):
        listing = ListingFactory()
        another_user = UserFactory()
        self.sign_in_as_user(another_user)

        response = self.client.patch(self.get_detail_url(listing.id),
                                     self.listing_update_data)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemple #5
0
    def test_update_listing_by_admin_succeeds(self):
        listing = ListingFactory()
        self.sign_in_as_user(self.admin)

        response = self.client.patch(self.get_detail_url(listing.id),
                                     self.listing_update_data)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json().get('title'),
                         self.listing_update_data.get('title'))
Exemple #6
0
    def setUp(self):
        self.user = UserFactory(email=fake.email())
        self.other_user = UserFactory(email=fake.email())
        self.admin = UserFactory(is_admin=True)

        self.listing_one = ListingFactory(user=self.user)
        self.listing_image_one = ListingImageFactory()

        self.valid_listing_image_update_data = {
            'image': self.create_test_image()
        }

        self.valid_listing_image_create_data = {
            'listing': self.listing_one.id,
            'image': self.create_test_image()
        }

        self.sign_in_as_user(self.user)
Exemple #7
0
    def setUp(self):
        self.user = UserFactory(email=fake.email())
        self.admin = UserFactory(is_admin=True)

        self.listing_one = ListingFactory()

        self.listing_update_data = {'title': fake.color_name(), 'images': []}
        self.listing_valid_create_data = {
            'title': fake.color_name(),
            'description': fake.sentence(nb_words=10),
            'price': 555,
            'location': fake.address(),
            'location_coordinates': f'{fake.latitude()},{fake.longitude()}',
            'images': [
                self.create_test_image(),
                self.create_test_image(),
            ]
        }

        self.sign_in_as_user(self.user)
Exemple #8
0
def listing(db):
    """Add a test listing to the database."""
    return ListingFactory.create()