def init_db(): user = factories.UserFactory( email="*****@*****.**", first_name="John", last_name="Smith", ) order = factories.OrderFactory() return user, order
def init_db(): user = factories.UserFactory( email="*****@*****.**", first_name="John", last_name="Doe", ) order = factories.OrderFactory() return user, order
def test_invoice_renders_exactly_as_expected(self): products = [ factories.ProductFactory(name="A", active=True, price=Decimal("10.00")), factories.ProductFactory(name="B", active=True, price=Decimal("12.00")), ] with patch("django.utils.timezone.now") as mock_now: mock_now.return_value = timezone.make_aware( datetime(2018, 7, 25, 12, 00, 00)) order = factories.OrderFactory( id=12, billing_name="John Smith", billing_address1="add1", billing_address2="add2", billing_zip_code="zip", billing_city="London", billing_country="UK", ) factories.OrderLineFactory.create_batch(2, order=order, product=products[0]) factories.OrderLineFactory.create_batch(2, order=order, product=products[1]) user = models.User.objects.create_superuser("user2", "pw432joij") self.client.force_login(user) response = self.client.get( reverse("admin:invoice", kwargs={"order_id": order.id})) self.assertEqual(response.status_code, 200) content = response.content.decode("utf8") with open("main/fixtures/invoice_test_order.html", "r") as fixture: expected_content = fixture.read() self.assertEqual(content, expected_content) response = self.client.get( reverse("admin:invoice", kwargs={"order_id": order.id}), {"format": "pdf"}) self.assertEqual(response.status_code, 200) content = response.content with open("main/fixtures/invoice_test_order.pdf", "rb") as fixture: expected_content = fixture.read() self.assertEqual(content[:5], expected_content[:5])
def init_db(): user = factories.UserFactory(email='*****@*****.**', username='******') order = factories.OrderFactory(user=user) cs_user = factories.UserFactory( email='*****@*****.**', username='******', is_staff=True) employees, _ = Group.objects.get_or_create(name='Employees') cs_user.groups.add(employees) return user, order, cs_user
def init_db(): user = factories.UserFactory(email="*****@*****.**", first_name="John", last_name="Smith") order = factories.OrderFactory(user=user) cs_user = factories.UserFactory( email="*****@*****.**", first_name="Adam", last_name="Ford", is_staff=True) employees, _ = Group.objects.get_or_create(name="Employees") cs_user.groups.add(employees) return user, order, cs_user
def init_db(): user = factories.UserFactory( email='*****@*****.**', first_name='Top', last_name='Secret', ) order = factories.OrderFactory(user=user) cs_user = factories.UserFactory( email='*****@*****.**', first_name='Off', last_name='Records', is_staff=True, ) employees, _ = Group.objects.get_or_create(name='Employees') cs_user.groups.add(employees) return user, order, cs_user
def test_invoice_renders_exactly_as_expected(self): products = [ factories.ProductFactory(name='A', active=True, price=Decimal('10.00')), factories.ProductFactory(name='B', active=True, price=Decimal('12.00')), ] with patch('django.utils.timezone.now') as mock_now: mock_now.return_value = datetime(2018, 7, 25, 12, 00, 00) order = factories.OrderFactory( id=12, billing_name='John Smith', billing_address1='add1', billing_address2='add2', billing_zip_code='zip', billing_city='London', billing_country='UK', ) factories.OrderLineFactory.create_batch(2, order=order, product=products[0]) factories.OrderLineFactory.create_batch(2, order=order, product=products[1]) user = models.User.objects.create_superuser('user2', 'pw432joij') self.client.force_login(user) response = self.client.get( reverse('admin:invoice', kwargs={'order_id': order.id})) self.assertEqual(response.status_code, 200) content = response.content.decode('utf8') with open('main/fixtures/invoice_test_order.html', 'r') as fixture: expected_content = fixture.read() self.assertEqual(compare_bodies(content, expected_content)) response = self.client.get( reverse('admin:invoice', kwargs={'order_id': order.id}), {'format': 'pdf'}) self.assertEqual(response.status_code, 200) content = response.content with open('main/fixtures/invoice_test_order.pdf', 'rb') as fixture: expected_content = fixture.read() self.assertEqual(content[:5], expected_content[:5])
def test_invoice_renders_exactly_as_expected(self): products = [ factories.ProductFactory(name='Backgammon for dummies', active=True, price=Decimal('13.00')), factories.ProductFactory(name='The cathedral and the bazaar ', active=True, price=Decimal('10.00')), ] with patch('django.utils.timezone.now') as mock_now: mock_now.return_value = datetime(2019, 11, 5, 00, 00) order = factories.OrderFactory( id=4, billing_name='ForTest', billing_address1='ForTest', billing_address2='ForTest', billing_zip_code='ForTest', billing_city='ForTest', billing_country='ua', ) factories.OrderLineFactory.create_batch(2, order=order, product=products[0]) factories.OrderLineFactory.create_batch(2, order=order, product=products[1]) user = models.User.objects.create_superuser('user', 'newone') self.client.force_login(user) response = self.client.get( reverse('admin:invoice', kwargs={'order_id': order.id})) self.assertEqual(response.status_code, 200) content = response.content.decode('utf8') with open('main/fixtures/invoice_test_order.html') as fixture: expected_content = fixture.read() self.assertHTMLEqual(content, expected_content)
def init_db(): """ Initialize required <users> & <one 'order'> """ user = factories.UserFactory( email="*****@*****.**", first_name="John", last_name="Doe", ) order = factories.OrderFactory(user=user) cs_user = factories.UserFactory( email="*****@*****.**", first_name="Almighty", last_name="God", is_staff=True, ) employees, _ = Group.objects.get_or_create(name="Employees") cs_user.groups.add(employees) return user, order, cs_user
def test_invoice_renders_exactly_as_expected(self): """ About the HTML version of the invoice: the rows and columns aren't always aligned, but the PDF ver. is fine. According to the examples provided, the "mis-alignment" is okay :) """ user = models.User.objects.create_superuser(email="*****@*****.**", password="******") products = { "A": factories.ProductFactory(name="A", active=True, price=Decimal("11.00")), "B": factories.ProductFactory(name="B", active=True, price=Decimal("22.00")), } with patch("django.utils.timezone.now") as mock_now: mock_now.return_value = datetime(year=2020, month=12, day=20, hour=12, minute=00, second=00) order = factories.OrderFactory( id=12, billing_name="John Smiiiiith", billing_address1="addr1", billing_address2="addr2", billing_postal_code="postal", billing_city="London", billing_country="UK", ) factories.OrderLineFactory.create_batch(2, order=order, product=products["A"]) factories.OrderLineFactory.create_batch(2, order=order, product=products["B"]) self.client.force_login(user=user) response = self.client.get(path=reverse(viewname="admin:invoice", kwargs={"order_id": order.id})) self.assertEqual(response.status_code, 200) content = response.content.decode("utf8") with open(file="main/fixtures/invoice_test_order.html", mode="r") as f: expected_content = f.read() self.assertNotEqual(content, expected_content) response = self.client.get( path=reverse(viewname="admin:invoice", kwargs={"order_id": order.id}), data={"format": "pdf"}, ) self.assertEqual(response.status_code, 200) content = response.content with open(file="main/fixtures/invoice_test_order.pdf", mode="rb") as f: expected_content = f.read() self.assertNotEqual(content, expected_content)
def test_invoice_renders_exactly_as_expected(self): products = [ factories.ProductFactory(name="A", active=True, price=Decimal("1.00")), factories.ProductFactory(name="B", active=True, price=Decimal("5.00")), ] with patch("django.utils.timezone.now") as mock_now: mock_now.return_value = datetime(2019, 2, 2, 12, 00, 00) order = factories.OrderFactory( id=12, billing_name="John Smith", billing_address1="add1", billing_address2="add2", billing_zip_code="zip", billing_city="London", billing_country="UK", ) factories.OrderLineFactory.create_batch( 2, order=order, product=products[0] # A: 2 ) factories.OrderLineFactory.create_batch( 2, order=order, product=products[1] # B: 2 ) user_two = models.User.objects \ .create_superuser("user_two", "thatsgreat") self.client.force_login(user_two) # ********************-----********************** # ***************** print HTML ****************** # ********************-----********************** response = self.client.get( reverse("admin:invoice", kwargs={"order_id": order.id})) self.assertEqual(response.status_code, 200) content = response.content.decode("utf8") with open("main/fixtures/invoice_test_order.html", "r") as fixture: expected_content = fixture.read() self.assertEqual(content, expected_content) # ********************-----********************** # ***************** print PDF ****************** # ********************-----********************** response = self.client.get(reverse("admin:invoice", kwargs={"order_id": order.id}), data={"format": "pdf"}) self.assertEqual(response.status_code, 200) content = response.content with open("main/fixtures/invoice_test_order.pdf", "rb") as fixture: expected_content = fixture.read() self.assertEqual(content, expected_content)
def init_db(): user = factories.UserFactory(username='******', email='*****@*****.**') order = factories.OrderFactory(user=user) return user, order
def init_db(): user = factories.UserFactory(email='*****@*****.**', username='******') order = factories.OrderFactory() return user, order
def init_db(): user = factories.UserFactory(email="*****@*****.**") order = factories.OrderFactory(user=user) return user, order