示例#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)
示例#2
0
	def test_category_title_is_unique(self):
		"""Test that the title field is unique."""
		category1 = Category(title = 'Test1')
		category1.save()
		
		category2 = Category(title = 'Test1')
		self.assertRaises(ValidationError, category2.save)
示例#3
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))
示例#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)
示例#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)
示例#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)
示例#7
0
	def test_categories_different_name_different(self):
		"""Test that the categories are different if their title is different."""
		category1 = Category(title = 'Test1')
		category2 = Category(title = 'Test2')
		self.assertNotEqual(category1, category2)
示例#8
0
	def test_slug_line_creation(self):
		"""Test that slug field is correctly created."""
		category = Category(title = 'Test The Slug Creation')
		category.save()
		self.assertEqual(category.slug, 'test-the-slug-creation')