class CategoryTestClass(TestCase): """ Testing the Category class """ def setUp(self): """ Creating a new instance of the Category class """ self.category = Category(name="Test") self.category.save() def test_instance(self): self.assertTrue(isinstance(self.category, Category)) def test_save_method(self): categories = Category.objects.all() self.assertTrue(len(categories) > 0)
def setUpClass(cls): super().setUpClass() cls.options = Options() cls.options.add_argument("--headless") cls.browser = Chrome(ChromeDriverManager().install(), options=cls.options) cls.browser.implicitly_wait(3) User = get_user_model() cls.user = User.objects.create_user(username='******', email='*****@*****.**', password='******') # create category for indice in range(1, 6): category = Category(name="category_test_%s" % indice, in_menu=True, order_menu=1) category.save()
class PhotoTestClass(TestCase): """ Creating the initial instance of the Photo class """ def setUp(self): self.place = Location(city="Nairobi", country="Kenya") self.place.save() self.category = Category(name="Test") self.category.save() self.photo = Photo(name='A random title', description="A random description", location=self.place) self.photo.save() def test_instance(self): self.assertTrue(isinstance(self.photo, Photo)) def test_save_method(self): self.photo.save_photo() photos = Photo.objects.all() self.assertTrue(len(photos) > 0) def test_delete_method(self): Photo.delete_photo(self.photo.id) photos = Photo.objects.all() self.assertTrue(len(photos) == 0) def test_get_photo_by_id(self): photo = Photo.get_photo_by_id(self.photo.id) self.assertEqual(photo, self.photo) def test_search_photo_by_category(self): photos = Photo.search_photo_by_category("Test") self.assertFalse(len(photos) > 0) def test_filter_by_location(self): photos = Photo.filter_by_location(self.photo.id) self.assertTrue(len(photos) > 0)
userProfile.firstname = names[i] userProfile.lastname = names[i + 1] userProfile.email = (names[seed % namesLen]) + "@punk.com" userProfile.image = profilePic[seed % profilePicLen] userProfile.coverPhoto = coverUrl[seed % coverUrlLen] userProfile.description = titles[seed % titlesLen] userProfile.key_skills = titles[seed % titlesLen] userProfile.description = sentences[seed % sentenceLen] userProfile.save() for i in range(5): theCategory = Category() theCategory.title = categoriesTitle[(seed + i) % categoriesTitleLen] theCategory.owner = userProfile theCategory.thumbnail = profilePic[(seed + i) % profilePicLen] theCategory.save() for z in range(10): theArtwork = Artwork() theArtwork.title = titles[(seed + z) % titlesLen] theArtwork.url_path = articleUrl[(seed + z) % articleUrlLen] theArtwork.category = theCategory theArtwork.owner = userProfile theArtwork.save() for i in range(20): articleseed = randint(0, 1000) article = Article() article.title = titles[articleseed % titlesLen] article.body = sentences[articleseed % sentenceLen]