Exemplo n.º 1
0
	def test_item_daily_visits_is_not_negative(self):
		"""Test that the database does not save negative daily visits."""
		valid_postcode = 'EC2R 8AH'
		user_profile = UserProfile(user = User.objects.create_user(username = '******',
																	email = '*****@*****.**',
																	password = '******', 
																	first_name = 'test',
																	last_name = 'visits'),
									postcode = valid_postcode)
		user_profile.save()

		category = Category('Test')
		category.save()
		
		section = Section('Test')
		section.save()
		
		size = Size('Test')
		size.save()

		valid_price = '10.30'

		item = Item(title = 'Test', price = valid_price, seller = user_profile, category = category, section = section,
					size = size, dailyVisits = -1)
		self.assertRaises(ValidationError, item.save)
Exemplo n.º 2
0
	def test_item_price_is_decimal(self):
		"""Test that the database can handle decimal prices."""
		valid_postcode = 'EC2R 8AH'
		user_profile = UserProfile(user = User.objects.create_user(username = '******',
																	email = '*****@*****.**',
																	password = '******', 
																	first_name = 'test',
																	last_name = 'price'),
									postcode = valid_postcode)
		user_profile.save()

		category = Category('Test')
		category.save()
		
		section = Section('Test')
		section.save()
		
		size = Size('Test')
		size.save()

		# Needs to be a string for the validator to work
		valid_price = '10.30'

		item = Item(title = 'Test', price = valid_price, seller = user_profile, category = category, section = section,
					size = size)
		item.save()

		self.assertEqual(valid_price, str(item.price))
Exemplo n.º 3
0
	def test_size_title_is_unique(self):
		"""Test that the title field is unique."""
		size1 = Size(title = 'Test1')
		size1.save()
		
		size2 = Size(title = 'Test1')
		self.assertRaises(ValidationError, size2.save)
Exemplo n.º 4
0
    def test_item_price_is_decimal_correct(self):
        '''Test that the database does not save prices with more than two decimal places.'''
        valid_postcode = 'EC2R 8AH'
        user_profile = UserProfile(user=User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            first_name='test',
            last_name='price'),
                                   postcode=valid_postcode)
        user_profile.save()

        category = Category('Test')
        category.save()

        section = Section('Test')
        section.save()

        size = Size('Test')
        size.save()

        item = Item(title='Test',
                    price='10.301',
                    seller=user_profile,
                    category=category,
                    section=section,
                    size=size)
        self.assertRaises(ValidationError, item.save)
Exemplo n.º 5
0
    def test_item_price_is_not_negative(self):
        '''Test that the database does not store a negative item price.'''
        valid_postcode = 'EC2R 8AH'
        user_profile = UserProfile(user=User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            first_name='test',
            last_name='price'),
                                   postcode=valid_postcode)
        user_profile.save()

        category = Category('Test')
        category.save()

        section = Section('Test')
        section.save()

        size = Size('Test')
        size.save()

        item = Item(title='Test',
                    price=-10,
                    seller=user_profile,
                    category=category,
                    section=section,
                    size=size)

        self.assertRaises(ValidationError, item.save)
Exemplo n.º 6
0
    def test_review_rating_is_smaller_than_5(self):
        '''Test that the database does not save ratings that are higher than 5.'''
        valid_postcode = 'EC2R 8AH'
        user_profile = UserProfile(user=User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            first_name='test',
            last_name='rating'),
                                   postcode=valid_postcode)
        user_profile.save()

        user_profile2 = UserProfile(user=User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            first_name='test',
            last_name='rating'),
                                    postcode=valid_postcode)
        user_profile2.save()

        category = Category('Test')
        category.save()

        section = Section('Test')
        section.save()

        size = Size('Test')
        size.save()

        valid_price = '10.30'

        item = Item(title='Test',
                    price=valid_price,
                    seller=user_profile,
                    category=category,
                    section=section,
                    size=size,
                    sold_to=user_profile2)
        item.save()

        review = Review(item=item, rating=6)
        self.assertRaises(ValidationError, review.save)