예제 #1
0
    def test_order_item_to_string_method(self):
        test_category = Category(name="Kettlebells")
        test_category.save()
        test_discount = Discount(name="30%", rate=0.7)
        test_discount.save()
        test_manufacurer = Manufacturer(name="Great Sports")
        test_manufacurer.save()
        test_product = Product(name="Test", description="A description",
                               image_url="", category=test_category,
                               manufacturer=test_manufacurer,
                               prize=100,
                               discount_rate=test_discount,
                               units_sold=1)

        test_user = User(username="******")
        test_user.save()
        date = datetime.datetime.now()

        test_order = Order(date=date,
                           user=test_user,
                           amount_paid=100,
                           shipping_address="Street",
                           customer_name="Name",
                           customer_email="*****@*****.**")
        test_order.save()

        test_order_item = OrderItem(product=test_product,
                                    order=test_order,
                                    quantity=1)

        self.assertEquals(test_order_item.__str__(), "Test")
 def test_specific_product_page(self):
     """Test response of a product extra detail page"""
     category = Categories.objects.create(
         category="Exterior"
     )
     vehicle = Vehicle.objects.create(
         make="Mercedes",
         model="A Class",
         generation="W176"
     )
     manufacturer = Manufacturer(
         name="Test Manufacturer"
     )
     manufacturer.save()
     prod = Product(
         name="Test Product",
         description="Description",
         category=category,
         ticket_price="2.50",
         product_price="795",
         product_link="https://www.github.com",
         fits=vehicle,
         part_manufacturer=manufacturer
     )
     prod.save()
     response = self.client.get('/tickets/' + str(prod.id) +'/')
     self.assertEqual(response.status_code, 200)
    def test_product_fits_multiple_true(self):
        """Test product model"""
        category = Categories(
            category="Exterior"
        )
        category.save()
        manufacturer = Manufacturer(
            name="Eibach"
        )
        manufacturer.save()
        product = Product(
            name="Test Product",
            description="Description",
            img="",
            category=category,
            ticket_price="2.50",
            product_price="795",
            product_link="https://www.github.com",
            part_manufacturer=manufacturer,
            fits_multiple=True
        )
        product.save()

        self.assertEqual(product.name, 'Test Product')
        self.assertEqual(product.description, 'Description')
        self.assertEqual(product.img, '')
        self.assertEqual(product.category.category, 'Exterior')
        self.assertEqual(product.ticket_price, '2.50')
        self.assertEqual(product.product_price, '795')
        self.assertEqual(product.product_link, 'https://www.github.com')
        self.assertEqual(product.part_manufacturer.name, 'Eibach')
        self.assertTrue(product.fits_multiple)
예제 #4
0
    def test_product_creation_no_image(self):
        """Test product model"""
        category = Categories(category="Exterior")
        category.save()
        manufacturer = Manufacturer(name="Eibach")
        manufacturer.save()
        product = Product(slug="test-slug",
                          name="Test Product",
                          description="Description",
                          img="",
                          category=category,
                          ticket_price="2.50",
                          product_price="795",
                          product_link="https://www.github.com",
                          part_manufacturer=manufacturer)
        product.save()

        self.assertEqual(product.slug, 'test-slug')
        self.assertEqual(product.name, 'Test Product')
        self.assertEqual(product.description, 'Description')
        self.assertEqual(product.img, '')
        self.assertEqual(product.category.category, 'Exterior')
        self.assertEqual(product.ticket_price, '2.50')
        self.assertEqual(product.product_price, '795')
        self.assertEqual(product.product_link, 'https://www.github.com')
        self.assertEqual(product.part_manufacturer.name, 'Eibach')
 def setUp(self):
     """Set database for tests"""
     self.user = {
         'username': '******',
         'email': '*****@*****.**',
         'password': '******'
     }
     User.objects.create_user(**self.user)
     Competition.objects.create(is_active=True, next_competition=False)
     category = Categories(category="Exterior")
     category.save()
     vehicle = Vehicle(make="Mercedes", model="A Class", generation="W176")
     vehicle.save()
     manufacturer = Manufacturer(name="Eibach")
     manufacturer.save()
     product = Product(name="Test Product",
                       description="Description",
                       img="",
                       category=category,
                       ticket_price="2.50",
                       product_price="795",
                       product_link="https://www.github.com",
                       fits=vehicle,
                       part_manufacturer=manufacturer)
     product.save()
    def test_vehicle_creation(self):
        """Test creation of a vehicle"""
        manufacturer = Manufacturer(
            name="CarbonWurks",
        )
        manufacturer.save()

        self.assertEqual(manufacturer.name, 'CarbonWurks')
 def test_str(self):
     """Test __str__ return"""
     manufacturer = Manufacturer(
         name="Test"
     )
     manufacturer.save()
     test_name = Product(name='Product', part_manufacturer=manufacturer)
     self.assertEqual(str(test_name), 'Test Product')
    def test_delete_from_quantity(self):

        """
        Creates a test Product.
        First sends a post request with the id of the product
        to add the product to the bag to add_to_bag view.
        Then sends another post request to delete_from_quantity to
        remove one item of that product from the bag.
        Ensures that the Product quantity is decreased in the bag by
        displaying the correct message returned by the request.
        Ensures correct redirect status code is returned.
        """

        test_category = Category(name="Kettlebells")
        test_category.save()
        test_discount = Discount(name="30%", rate=0.7)
        test_discount.save()
        test_manufacurer = Manufacturer(name="Great Sports")
        test_manufacurer.save()
        test_product = Product(name="Test", description="A description",
                               image_url="", category=test_category,
                               manufacturer=test_manufacurer,
                               prize=100,
                               discount_rate=test_discount,
                               units_sold=1)
        test_product.save()

        self.client.post("/bag/add_to_bag/1/", {"quantity-input": 1})
        test_response = self.client.post("/bag/delete_from_quantity/1/")

        self.client.post("/bag/add_to_bag/1/", {"quantity-input": 1})
        test_response_message = self.client.post(
            "/bag/delete_from_quantity/1/", follow=True)

        intended_message = "Item was deleted"
        message = ""

        get_stored_messages = test_response_message.context["messages"]
        for message in get_stored_messages:
            message = message

        self.assertEquals(test_response.status_code, 302)
        self.assertEquals(intended_message, message.__str__())

        # Add a quantity of two
        # Ensure the bag content contains one item after deleting one

        self.client.post("/bag/add_to_bag/1/", {"quantity-input": 2})
        test_response_message = self.client.post(
            "/bag/delete_from_quantity/1/", follow=True)

        intended_bag_content = {'1': {'quantity': 1}, 'total_cost': 70}
        shopping_bag = self.client.session["shopping_bag"]

        self.assertEquals(test_response.status_code, 302)
        self.assertEquals(intended_bag_content, shopping_bag)
예제 #9
0
 def test_specific_product_page(self):
     """Test response of a product extra detail page"""
     category = Categories.objects.create(category="Exterior")
     manufacturer = Manufacturer(name="Test Manufacturer")
     manufacturer.save()
     prod = Product(slug="test-slug",
                    name="Test Product",
                    description="Description",
                    category=category,
                    ticket_price="2.50",
                    product_price="795",
                    product_link="https://www.github.com",
                    part_manufacturer=manufacturer)
     prod.save()
     response = self.client.get('/tickets/test-slug')
     self.assertEqual(response.status_code, 200)
예제 #10
0
    def setUp(self):
        self.user = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******'
        }
        self.user2 = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******'
        }
        User.objects.create_user(**self.user)
        User.objects.create_user(**self.user2)
        Competition.objects.create(tickets=5000,
                                   tickets_left=5000,
                                   question="Is this a test?",
                                   answer_1="Yes",
                                   answer_2="No",
                                   answer_3="Maybe",
                                   correct_answer="Yes",
                                   is_active=True)
        category = Categories(category="Exterior")
        category.save()
        vehicle = Vehicle(make="Mercedes", model="A Class")
        vehicle.save()
        manufacturer = Manufacturer(name="Test Manufacturer")
        manufacturer.save()
        product = Product(name="Test Product",
                          description="Description",
                          img="",
                          category=category,
                          ticket_price="2.50",
                          product_price="795",
                          product_link="https://www.github.com",
                          part_manufacturer=manufacturer)
        product.save()

        user = User.objects.get(email='*****@*****.**')
        comp = Competition.objects.get(is_active=True)
        order = Order(user=user,
                      related_competition=comp,
                      order_date=timezone.now())
        order.save()
    def test_product_fits_multiple_false(self):
        """Test product model with fits multiple as false"""
        category = Categories(
            category="Exterior"
        )
        category.save()
        vehicle = Vehicle(
            make="Mercedes",
            model="A Class",
            generation="W176"
        )
        vehicle.save()
        manufacturer = Manufacturer(
            name="Eibach"
        )
        manufacturer.save()
        product = Product(
            name="Test Product",
            description="Description",
            img="",
            category=category,
            ticket_price="2.50",
            product_price="795",
            product_link="https://www.github.com",
            fits=vehicle,
            part_manufacturer=manufacturer
        )
        product.save()

        self.assertEqual(product.name, 'Test Product')
        self.assertEqual(product.description, 'Description')
        self.assertEqual(product.img, '')
        self.assertEqual(product.category.category, 'Exterior')
        self.assertEqual(product.ticket_price, '2.50')
        self.assertEqual(product.product_price, '795')
        self.assertEqual(product.product_link, 'https://www.github.com')
        self.assertEqual(product.fits.make, 'Mercedes')
        self.assertEqual(product.fits.model, 'A Class')
        self.assertEqual(product.fits.generation, 'W176')
        self.assertEqual(product.part_manufacturer.name, 'Eibach')
        self.assertFalse(product.fits_multiple)
예제 #12
0
 def test_str(self):
     """Test __str__ return"""
     category = Categories(category="Exterior")
     category.save()
     manufacturer = Manufacturer(name="Eibach")
     manufacturer.save()
     vehicle = Vehicle(make="Mercedes", model="A Class", generation="W176")
     vehicle.save()
     product = Product(slug="test-slug",
                       name="Test Product",
                       description="Description",
                       img="",
                       category=category,
                       ticket_price="2.50",
                       product_price="795",
                       product_link="https://www.github.com",
                       part_manufacturer=manufacturer)
     product.save()
     test_name = Fitments(products=product, vehicle=vehicle)
     self.assertEqual(str(test_name),
                      'Eibach Test Product - Mercedes A Class W176')
    def test_add_to_quantity(self):

        """
        Creates a test Product.
        First sends a post request with the id of the product
        to add the product to the bag to add_to_bag view.
        Then sends another post request to add_to quantity.
        Ensures that the Product quantity is increased in the bag by
        displaying the correct message returned by the request.
        Ensures correct redirect status code is returned.
        """

        test_category = Category(name="Kettlebells")
        test_category.save()
        test_discount = Discount(name="30%", rate=0.7)
        test_discount.save()
        test_manufacurer = Manufacturer(name="Great Sports")
        test_manufacurer.save()
        test_product = Product(name="Test", description="A description",
                               image_url="", category=test_category,
                               manufacturer=test_manufacurer,
                               prize=100,
                               discount_rate=test_discount,
                               units_sold=1)
        test_product.save()

        self.client.post("/bag/add_to_bag/1/", {"quantity-input": 1})
        test_response = self.client.post("/bag/add_to_quantity/1/")
        test_response_message = self.client.post("/bag/add_to_quantity/1/",
                                                 follow=True)

        intended_message = "Item was added"
        message = ""

        get_stored_messages = test_response_message.context["messages"]
        for message in get_stored_messages:
            message = message

        self.assertEquals(test_response.status_code, 302)
        self.assertEquals(intended_message, message.__str__())
예제 #14
0
 def setUp(self):
     """Set database for tests"""
     self.user = {
         'username': '******',
         'email': '*****@*****.**',
         'password': '******'
     }
     User.objects.create_user(**self.user)
     Competition.objects.create(is_active=True, next_competition=False)
     category = Categories(category="Exterior")
     category.save()
     manufacturer = Manufacturer(name="Eibach")
     manufacturer.save()
     product = Product(name="Test Product",
                       description="Description",
                       img="",
                       category=category,
                       ticket_price="2.50",
                       product_price="795",
                       product_link="https://www.github.com",
                       part_manufacturer=manufacturer)
     product.save()
     user = User.objects.get(username='******')
     OrderItem(user=user, product=product, is_paid=True, quantity=5).save()
 def test_str(self):
     """Test __str__ return"""
     test_name = Manufacturer(name='CarbonWurks')
     self.assertEqual(str(test_name), 'CarbonWurks')