Ejemplo n.º 1
0
    def test_add_products_to_a_non_existing_wish_list(self):
        product = ProductFactory()

        data = json.dumps({
            'product': {
                'id': product.id,
                'title': product.title,
                'brand': product.brand,
                'reviewScore': product.reviewScore,
                'price': product.price,
                'image': product.image,
            }
        })

        user = UserFactory(username='******',
                           email='*****@*****.**',
                           password='******')

        create_token(user=user)
        token = get_token_from_user(user=user)

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        response = self.client.post(reverse('wish-list-product-list',
                                            kwargs={'version': 'v1'}),
                                    data=data,
                                    content_type='application/json')

        self.assertEqual(response.status_code,
                         status.HTTP_412_PRECONDITION_FAILED)
        response_wish_list_product_data = json.loads(response.content)
        self.assertEqual(response_wish_list_product_data,
                         'User has no wish list')
Ejemplo n.º 2
0
    def setUp(self):
        self.user = UserFactory(username='******',
                                email='*****@*****.**',
                                password='******')
        self.user.save()
        create_token(user=self.user)

        self.customer = CustomerFactory(user=self.user)
Ejemplo n.º 3
0
    def setUp(self):
        self.user = User.objects.create_user(username='******',
                                             email='*****@*****.**',
                                             password='******')
        self.user.save()
        create_token(user=self.user)

        self.wish_list = WishList.objects.create(user=self.user,
                                                 name='santa_claws_wish_list')
Ejemplo n.º 4
0
    def setUp(self):
        self.user = UserFactory(username='******',
                                email='*****@*****.**',
                                password='******')
        create_token(user=self.user)

        self.product = ProductFactory(
            title='pro controller',
            brand='nintendo',
            price=200.00,
            image='http://example.com/pro_controller',
        )
Ejemplo n.º 5
0
    def setUp(self):
        self.user = UserFactory(username='******',
                                email='*****@*****.**',
                                password='******')
        create_token(user=self.user)

        self.wish_list = WishListFactory(user=self.user,
                                         name='santa_claws_wish_list')

        self.product = ProductFactory(
            title='pro controller',
            brand='nintendo',
            reviewScore=8,
            price=200.00,
            image='http://example.com/pro_controller',
        )

        self.wish_list_product = WishListProductFactory(
            wish_list=self.wish_list, product=self.product)
Ejemplo n.º 6
0
    def test_create_wish_list(self):
        data = json.dumps({'name': 'my_personal_product_wishes'})

        user = User.objects.create_user(username='******',
                                        email='*****@*****.**',
                                        password='******')
        user.save()

        create_token(user=user)
        token = get_token_from_user(user=user)

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        response = self.client.post(reverse('wish-list-list',
                                            kwargs={'version': 'v1'}),
                                    data=data,
                                    content_type='application/json')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        wish_list_response_data = json.loads(response.content)
        wish_list = WishList.objects.get(name='my_personal_product_wishes')
        self.assertEqual(wish_list_response_data['name'], wish_list.name)
Ejemplo n.º 7
0
    def test_delete_existing_user(self):
        user = UserFactory(username='******')

        create_token(user=user)

        token = get_token_from_user(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        created_user = User.objects.filter(username='******')

        self.assertEqual(created_user.first().username, user.username)

        response = self.client.delete(reverse('user-detail',
                                              kwargs={
                                                  'version': 'v1',
                                                  'pk': user.id
                                              }),
                                      content_type='application/json')

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        deleted_user = User.objects.filter(username='******')
        self.assertFalse(deleted_user.exists())
Ejemplo n.º 8
0
 def setUp(self):
     self.user = UserFactory(username='******',
                             email='*****@*****.**',
                             password='******')
     create_token(user=self.user)
     self.product_review = ProductReviewFactory()