Ejemplo n.º 1
0
    def setUp(self):
        langs = (
            ('polish', 'pl'),
            ('english', 'eng')
        )
        for name, code in langs:
            Language.objects.create(name=name, code=code)

        UserFactory(email='*****@*****.**')
        UserFactory(email='*****@*****.**')
        ArticleFactory()
Ejemplo n.º 2
0
 def test_get_address_list_for_user(self):
     user1 = UserFactory()
     user2 = UserFactory()
     address1 = AddressFactory(user=user1)
     address2 = AddressFactory(user=user2)
     self.client.force_login(user1)
     response = self.client.get(reverse('main:address_list'))
     self.assertEqual(response.status_code, 200)
     self.assertTemplateUsed(response, 'main/address_list.html')
     address_list = Address.objects.filter(user=user1)
     self.assertEqual(list(response.context['address_list']),
                      list(address_list))
Ejemplo n.º 3
0
    def test_create_order_works(self):
        p1 = ProductFactory()
        p2 = ProductFactory()
        user1 = UserFactory()
        billing = AddressFactory(user=user1)
        shipping = AddressFactory(user=user1)
        cart = models.Cart.objects.create(user=user1)
        models.ProductInCart.objects.create(cart=cart, product=p1)
        models.ProductInCart.objects.create(cart=cart, product=p2)

        with self.assertLogs("main.models", level="INFO") as cm:
            order = cart.create_order(billing, shipping)

        self.assertGreaterEqual(len(cm.output), 1)

        order.refresh_from_db()

        self.assertEqual(order.user, user1)
        self.assertEqual(order.billing_address1, billing.address1)
        self.assertEqual(order.shipping_address1, shipping.address1)

        self.assertEqual(order.lines.all().count(), 2)
        lines = order.lines.all()
        self.assertEqual(lines[0].product, p1)
        self.assertEqual(lines[1].product, p2)
Ejemplo n.º 4
0
def user_client(db, client):
    """A Django client logged-in as a new user"""
    from main.tests.factories import UserFactory
    user = UserFactory()
    client.login(username=getattr(user, user.USERNAME_FIELD),
                 password=user.raw_password)
    client.user = user
    return client
Ejemplo n.º 5
0
 def test_delete_user_address(self):
     user = UserFactory()
     self.client.force_login(user)
     address = AddressFactory(user=user)
     self.assertTrue(Address.objects.filter(user=user).exists())
     response = self.client.post(
         reverse('main:address_delete', kwargs={'pk': address.id}))
     self.assertEqual(response.status_code, 302)
     self.assertFalse(Address.objects.filter(user=user).exists())
Ejemplo n.º 6
0
 def test_create_address(self):
     user = UserFactory()
     post_data = {
         'name': 'some',
         'address1': 'addr1',
         'city': 'Lublin',
         'zip_code': '12233',
         'country': 'pl'
     }
     self.client.force_login(user)
     response = self.client.post(reverse('main:address_create'), post_data)
     self.assertEqual(response.status_code, 302)
     self.assertTrue(Address.objects.filter(user=user))
     self.assertEqual(Address.objects.get(user=user).city, 'Lublin')
Ejemplo n.º 7
0
 def test_add_to_basket(self):
     user = UserFactory()
     product1 = ProductFactory()
     product2 = ProductFactory()
     self.client.force_login(user)
     self.client.get(reverse('main:add_to_basket'),
                     {'product_id': product1.id})
     self.assertTrue(Basket.objects.filter(user=user).exists())
     self.client.get(reverse('main:add_to_basket'),
                     {'product_id': product1.id})
     self.client.get(reverse('main:add_to_basket'),
                     {'product_id': product2.id})
     self.assertEqual(Basket.objects.get(user=user).count(), 3)
     self.assertTrue(BasketLine.objects.filter(product=product2).exists())
     self.assertEqual(
         BasketLine.objects.filter(basket__user=user).count(), 2)
Ejemplo n.º 8
0
    def create_articles(self):
        titles = ['About', 'News', 'Program', 'Speakers', 'Sponsors']
        langs = list(Language.objects.all())

        for i, title in enumerate(titles):
            translator = UserFactory(raw_password='******',
                                     is_translator=True,
                                     is_staff=True)
            article = ArticleFactory(author=translator)
            Menu.objects.create(article=article, position=i)

            for lang in langs:
                TranslationFactory(article=article,
                                   lang=lang,
                                   author=translator,
                                   title=title,
                                   published=True)
Ejemplo n.º 9
0
    def create_prelections(self):
        num = randint(2, 5)

        conf = self.conference
        for i in range(num):
            user = UserFactory()
            prelectors_num = choice([1, 1, 1, 1, 2, 2, 3])  # probability
            main_prelector, *other_prelectors = [
                ParticipationFactory(
                    participant=ParticipantFactory(user=user),
                    conference=conf
                ).participant
                for _ in range(prelectors_num)
            ]

            PrelectionFactory(conference=conf,
                              main_prelector=main_prelector,
                              other_prelectors=other_prelectors)
Ejemplo n.º 10
0
 def test_update_address(self):
     user = UserFactory()
     address = AddressFactory(user=user)
     self.client.force_login(user)
     update_data = {
         'name': address.name,
         'address1': address.address1,
         'address2': address.address2,
         'country': address.country,
         'zip_code': address.zip_code,
         'city': 'Warsaw'
     }
     response = self.client.post(
         reverse('main:address_update', kwargs={'pk': address.id}),
         update_data)
     address.refresh_from_db()
     self.assertEqual(response.status_code, 302)
     self.assertEqual(address.city, 'Warsaw')
Ejemplo n.º 11
0
 def test_merge_basket_on_login(self):
     user = UserFactory(email='*****@*****.**')
     product1 = ProductFactory()
     product2 = ProductFactory()
     self.client.get(reverse('main:add_to_basket'),
                     {'product_id': product2.id})
     self.assertTrue(BasketLine.objects.filter(product=product2).exists())
     credentials = dict(email='*****@*****.**', password='******')
     self.client.post(reverse('main:login'), {
         'email': '*****@*****.**',
         'password': '******'
     })
     self.assertTrue(auth.get_user(self.client).is_authenticated)
     self.assertTrue(Basket.objects.filter(user=user).exists())
     self.client.get(reverse('main:add_to_basket'),
                     {'product_id': product1.id})
     self.assertEqual(Basket.objects.get(user=user).count(), 2)
     self.assertTrue(BasketLine.objects.filter(product=product2).exists())
     self.assertEqual(BasketLine.objects.get(product=product1).quantity, 1)
Ejemplo n.º 12
0
 def create_users(self):
     UserFactory(email='*****@*****.**',
                 raw_password='******',
                 is_administrator=True,
                 is_superuser=True,
                 is_staff=True)
Ejemplo n.º 13
0
def user_credentials():
    user = UserFactory.create()
    password = '******'
    user.set_password(password)
    user.save()
    return user, password
Ejemplo n.º 14
0
 def setUp(self):
     self.user = UserFactory()
     self.client.login(email=self.user.email, password='******')
Ejemplo n.º 15
0
 def test_user_authentication(self):
     user = UserFactory(email='*****@*****.**')
     credentials = dict(email='*****@*****.**', password='******')
     response = self.client.post(reverse('main:login'), credentials)
     self.assertEqual(response.status_code, 302)
     self.assertTrue(auth.get_user(self.client).is_authenticated)