Пример #1
0
	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_payment_type_is_saved_to_database(self):
        new_payment = PaymentType(None, "Amex", "55555555", "555", "04/44",
                                  "Mr. Rogers", 1)

        post_response = self.client.post(
            reverse('bang_app:create_payment_type'), {
                "card_type": "Amex",
                "card_number": "55555555",
                "cvv": "555",
                "expiration_date": "04/44",
                "billing_name": "Mr. Rogers",
                "customer_pk_from_test": "1"
            })

        queried_payment = PaymentType.objects.get(card_type="Amex",
                                                  card_number="55555555",
                                                  cvv="555",
                                                  expiration_date="04/44",
                                                  billing_name="Mr. Rogers")

        self.assertEqual(new_payment.card_type, queried_payment.card_type)
        self.assertEqual(new_payment.card_number, queried_payment.card_number)
        self.assertEqual(new_payment.cvv, queried_payment.cvv)
        self.assertEqual(new_payment.expiration_date,
                         queried_payment.expiration_date)
        self.assertEqual(new_payment.billing_name,
                         queried_payment.billing_name)
Пример #3
0
 def test_payment_fields_contain_correct_values(self):
     new_payment = PaymentType(None, "Visa", "11111111", "111", "01/11",
                               "Happy Gilmore", 1)
     self.assertEqual(new_payment.card_type, "Visa")
     self.assertEqual(new_payment.card_number, "11111111")
     self.assertEqual(new_payment.cvv, "111")
     self.assertEqual(new_payment.expiration_date, "01/11")
     self.assertEqual(new_payment.billing_name, "Happy Gilmore")
Пример #4
0
    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)
Пример #5
0
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)
Пример #6
0
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))
Пример #7
0
 def test_new_payment_is_of_class_PaymentType(self):
     new_payment = PaymentType(None, "Visa", "11111111", "111", "01/11",
                               "Happy Gilmore", 1)
     self.assertIsInstance(new_payment, PaymentType)