Ejemplo n.º 1
0
 def test_product_generate_unique_slug(self):
     """
     Check unique slug is generated
     """
     product_one = factories.ProductFactory(name='Foo')
     product_two = factories.ProductFactory(name='Foo')
     self.assertNotEqual(product_one.slug, product_two.slug)
Ejemplo n.º 2
0
def before_step(context, step):
    """
    These run before every step.
    """
    if step.name in [
            'I am an admin',
    ]:
        # Create an Admin account.
        admin = factories.AdminFactory()
    elif step.name in [
            'I am a staff member',
    ]:
        # Create a Staff Member account.
        staff = factories.StaffMemberFactory()
    elif step.name in [
            'I am a regular user',
    ]:
        # Create a User account.
        user = factories.UserFactory()
    elif step.name in [
            'I am an anonymous user',
    ]:
        # Create a User account.
        user = factories.UserFactory()
    elif step.name in [
            'I visit the "home" page',
    ]:
        # Create a product.
        product = factories.ProductFactory(
            option__Size=['Small', 'Medium', 'Large'],
            option__Color=['Black', 'White'])
Ejemplo n.º 3
0
 def test_product_detail_with_comment_form(self):
     """
     Checking comment's form
     """
     product = factories.ProductFactory()
     context = self._test_product_detail(product)
     self.assertIsInstance(context['form'], CommentForm)
Ejemplo n.º 4
0
 def test_product_detail_view(self):
     """
     Test product's an instance on product detail page
     """
     product = factories.ProductFactory()
     context_object = self._test_product_detail(product)['product']
     self.assertEqual(context_object.name, product.name)
Ejemplo n.º 5
0
 def test_invalid_comment_form(self):
     """
     Check required field
     """
     product = factories.ProductFactory()
     response = self.client.post(
         reverse('products:product_detail', kwargs={'slug': product.slug}),
         {'text': ''})
     self.assertEqual(response.status_code, 200)
     self.assertFormError(response, 'form', 'text',
                          'This field is required.')
Ejemplo n.º 6
0
 def test_post_to_valid_comment_form(self):
     """
     Check post data when comment form is valid
     """
     product = factories.ProductFactory()
     self.assertEqual(product.comments.count(), 0)
     response = self.client.post(
         reverse('products:product_detail', kwargs={'slug': product.slug}),
         {'text': 'something'})
     self.assertEqual(response.status_code, 302)
     self.assertEqual(product.comments.count(), 1)
Ejemplo n.º 7
0
    def test_product_detail_with_comments_list(self):
        """
        Test product's comments
        """
        product = factories.ProductFactory()
        now = timezone.now()
        yesterday = timezone.now() - timezone.timedelta(days=1)

        factories.CommentFactory.create_batch(2,
                                              created_at=yesterday,
                                              product=product)
        factories.CommentFactory.create_batch(5,
                                              created_at=now,
                                              product=product)

        context_object = self._test_product_detail(product)['product']
        self.assertEqual(context_object.comments.count(), 5)
Ejemplo n.º 8
0
    def test_user_post_to_send_like(self):
        """
        Test user like and send post request
        """
        product = factories.ProductFactory()

        self._log_in_and_test(self.user)
        self.assertEqual(Like.objects.all().count(), 0)

        response = self.client.post(reverse('products:like_create'),
                                    {'productId': product.id},
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        self.assertEqual(response.status_code, 201)
        self.assertJSONEqual(response.content,
                             {'message': 'Thanks for your feedback'})
        self.assertEqual(Like.objects.all().count(), 1)
Ejemplo n.º 9
0
def before_scenario(context, scenario):
    if scenario.name in [
            'get a list of users as an admin',
            'get a list of users as a regular user',
            'get a list of users as an anonymous user',
    ]:
        # Create 3 users.
        users = [
            factories.UserFactory(username='******' % i) for i in range(3)
        ]
    elif scenario.name in [
            'add a variant via the change user page'  # steps/admin.py
    ]:
        product = factories.ProductFactory()
        inventory = factories.InventoryFactory()
    elif scenario.name in [
            'add a product via the admin panel'  # steps/admin.py
    ]:
        inventory = factories.InventoryFactory()
Ejemplo n.º 10
0
 def test_product_price(self):
     """
     Check price must be greater than negative
     """
     with self.assertRaises(ValidationError):
         factories.ProductFactory(price=Decimal('-0.01'))
Ejemplo n.º 11
0
 def setUp(self):
     self.product = factories.ProductFactory()
     self.user = UserFactory()