def setUp(self): # The most direct way to create users is to use the included create_user() helper function self.user = User.objects.create_user(first_name="Suzy", last_name="Bishop", email="*****@*****.**", username="******", password="******") self.suzy = Customer(user=self.user, city="New Penzance", state="Rhode Island", zip_code="52801", street_address="300 Summer's End") self.suzy.save() self.school_supplies = ProductType(label="School Supplies") self.school_supplies.save() self.scissors = Product(name="Lefty Scissors", price=3.99, description="For the lefties", quantity=3, product_type=self.school_supplies, seller=self.suzy) self.scissors.save()
def setUp(self): # The most direct way to create users is to use the included create_user() helper function self.user = User.objects.create_user( first_name = "Suzy", last_name = "Bishop", email = "*****@*****.**", username = "******", password="******" ) self.suzy = Customer( user = self.user, city = "New Penzance" , state = "Rhode Island" , zip_code = "52801", street_address = "300 Summer's End" ) self.suzy.save() self.payment = PaymentType( card_type = "Visa", card_number = "12312341234", cvv = "101", expiration_date = "10/10/17", billing_name = "Suzy S. Bishop", customer = self.suzy ) self.payment.save() self.school_supplies = ProductType( label = "School Supplies" ) self.school_supplies.save() self.scissors = Product( name = "Lefty Scissors", price = 3.99, description = "For the lefties", quantity = 3, product_type = self.school_supplies, seller = self.suzy ) self.scissors.save() self.order = CustomerOrder( active_order = 1, customer = self.suzy, payment_type = self.payment, ) self.order.save() new_line_item = LineItem.objects.create(order=self.order, product=self.scissors, quantity=1) # Log in the setup customer self.client.login(username="******", password="******")
def test_product_fields_contain_correct_values(self): ball = Product(None,"ball", 1.99, "It's round", 3, None, None) self.assertEqual(ball.name, "ball") self.assertEqual(ball.price, 1.99) self.assertEqual(ball.description, "It's round") self.assertEqual(ball.quantity, 3)
class TestProductCategory(TestCase): def setUp(self): # The most direct way to create users is to use the included create_user() helper function self.user = User.objects.create_user(first_name="Suzy", last_name="Bishop", email="*****@*****.**", username="******", password="******") self.suzy = Customer(user=self.user, city="New Penzance", state="Rhode Island", zip_code="52801", street_address="300 Summer's End") self.suzy.save() self.school_supplies = ProductType(label="School Supplies") self.school_supplies.save() self.scissors = Product(name="Lefty Scissors", price=3.99, description="For the lefties", quantity=3, product_type=self.school_supplies, seller=self.suzy) self.scissors.save() def test_product_category_view_can_display(self): # """Testing that page will return a HTTP 200 (success) response. If so, navigation runs properly.""" response = self.client.get(reverse('bang_app:categories')) self.assertTemplateUsed('products.html') self.assertEqual(response.status_code, 200) def test_product_categories(self): # Test to ensure that product categories return properly. self.assertIsInstance(self.school_supplies, ProductType) #Testing that the returned category list includes test instance. response = self.client.get(reverse('bang_app:categories')) self.assertIn( "{'category_list': <QuerySet [<ProductType: School Supplies>]>, 'total': 0}", str(response.context))
def setUpTestData(self): """ Provides data for test database """ self.user = User(first_name="Suzy", last_name="Bishop", email="*****@*****.**", username="******", password="******") self.user.save() self.suzy = Customer(user=self.user, city="New Penzance", state="Rhode Island", zip_code="52801", street_address="300 Summer's End") self.suzy.save() self.payment = PaymentType(card_type="Amex", card_number="1111222233334444", cvv="956", expiration_date="05/20", billing_name="Suzy Bishop", customer=self.suzy) self.payment.save() self.new_customer_order = CustomerOrder(active_order=1, customer=self.suzy, payment_type=self.payment) self.new_customer_order.save() self.ball = Product(None, "ball", 1.99, "It's round", 3, 1, 1) self.ball.save() self.testing_product = Product.objects.get(pk=1) new_line_item = LineItem.objects.create(order=self.new_customer_order, product=self.ball, quantity=1)
def test_product_can_be_created(self): self.ball = Product("ball", 1.99, "It's round", 3, None, None) self.assertIsInstance(self.ball, Product)
class TestOrderDetailView(TestCase): """ Purpose: tests the functionality of the OrderDetail view Author: Sam Phillips """ @classmethod def setUpTestData(self): """ Provides data for test database """ self.user = User(first_name="Suzy", last_name="Bishop", email="*****@*****.**", username="******", password="******") self.user.save() self.suzy = Customer(user=self.user, city="New Penzance", state="Rhode Island", zip_code="52801", street_address="300 Summer's End") self.suzy.save() self.payment = PaymentType(card_type="Amex", card_number="1111222233334444", cvv="956", expiration_date="05/20", billing_name="Suzy Bishop", customer=self.suzy) self.payment.save() self.new_customer_order = CustomerOrder(active_order=1, customer=self.suzy, payment_type=self.payment) self.new_customer_order.save() self.ball = Product(None, "ball", 1.99, "It's round", 3, 1, 1) self.ball.save() self.testing_product = Product.objects.get(pk=1) new_line_item = LineItem.objects.create(order=self.new_customer_order, product=self.ball, quantity=1) def test_order_detail_template_is_rendered_properly(self): try: view_request_response = self.client.get( reverse('bang_app:order_detail_view')) self.assertContains(view_request_response, "Your Current Order:") self.assertEqual(view_request_response.status_code, 200) except AttributeError: pass def test_closing_an_order_adds_payment_and_updates_order_to_inactive(self): order_pre_closing = CustomerOrder.objects.get(pk=1) close_order_request_response = self.client.post( reverse('bang_app:close_order'), { "customer_order_id": order_pre_closing.id, "payment_type_id": self.payment.id }) order_post_closing = CustomerOrder.objects.get(id=order_pre_closing.id) self.assertEqual(order_pre_closing.id, order_post_closing.id) self.assertEqual(order_post_closing.active_order, 0) self.assertEqual(order_post_closing.payment_type, self.payment) def test_closing_an_order_redirects_the_user(self): order = CustomerOrder.objects.get(pk=1) close_order_request_response = self.client.post( reverse('bang_app:close_order'), { "customer_order_id": order.id, "payment_type_id": self.payment.id }) self.assertEqual(close_order_request_response.status_code, 302)
class TestLineItem(TestCase): """ Purpose: This class tests matters related to adding a line item to an order Methods: test_line_item_should_redirect_to_success_view test_line_item_returns_correct_context Author: Abby """ def setUp(self): # The most direct way to create users is to use the included create_user() helper function self.user = User.objects.create_user( first_name = "Suzy", last_name = "Bishop", email = "*****@*****.**", username = "******", password="******" ) self.suzy = Customer( user = self.user, city = "New Penzance" , state = "Rhode Island" , zip_code = "52801", street_address = "300 Summer's End" ) self.suzy.save() self.payment = PaymentType( card_type = "Visa", card_number = "12312341234", cvv = "101", expiration_date = "10/10/17", billing_name = "Suzy S. Bishop", customer = self.suzy ) self.payment.save() self.school_supplies = ProductType( label = "School Supplies" ) self.school_supplies.save() self.scissors = Product( name = "Lefty Scissors", price = 3.99, description = "For the lefties", quantity = 3, product_type = self.school_supplies, seller = self.suzy ) self.scissors.save() self.order = CustomerOrder( active_order = 1, customer = self.suzy, payment_type = self.payment, ) self.order.save() new_line_item = LineItem.objects.create(order=self.order, product=self.scissors, quantity=1) # Log in the setup customer self.client.login(username="******", password="******") def test_line_item_should_redirect_to_success_view(self): response = self.client.get(reverse('bang_app:categories')) self.assertTemplateUsed('success.html') self.assertEqual(response.status_code, 200) def test_line_item_returns_correct_context(self): # In order to see what's being returned, print response.context response = self.client.get(reverse('bang_app:list_line_items')) self.assertIn("{'line_items': <QuerySet [<Product: Lefty Scissors 3.99 For the lefties 3 School Supplies>]>, 'current_order': <CustomerOrder: Order for customer Suzy>, 'total': 1}", str(response.context))