class ReaderBaseTestCase(TestCase): """ Base test case for Booktype with common utility functions """ def setUp(self): """ Sets common attributes for test classes """ self.book = BookFactory() self.book.version = BookVersionFactory(book=self.book) self.book.save() self.user = self.book.owner def assertTrueMultiple(self, response, var_list=[]): """ Checks if response contains multiples variables in context """ for var_name in var_list: self.assertTrue(var_name in response.context) def reload_from_db(self, obj): """ Returns reloaded attributes of a given object from the database """ return obj.__class__.objects.get(pk=obj.id)
def setUp(self): """ Sets common attributes for test classes """ self.book = BookFactory() self.book.version = BookVersionFactory(book=self.book) self.book.save() self.user = self.book.owner
def setUp(self): self.user = UserFactory() # setup for books self.book = BookFactory() # setup for groups self.bookGroup = self.book.group # add members self.bookGroup.members.add(1)
def setUp(self): self.book = BookFactory() self.book.version = BookVersionFactory( book=self.book) # TODO: improve this self.book.save() self.user_1 = self.book.owner # need two users to be able to test collaboration within a book self.user_2 = UserFactory() # setup book content chapter_1 = ChapterFactory(book=self.book, version=self.book.version) chapter_2 = ChapterFactory(book=self.book, version=self.book.version) # setup content for user two in same book # call this "Contribution" book_history = BookHistoryFactory(book=self.book, user=self.user_2, chapter=chapter_2) self.dispatcher = reverse('accounts:view_profile', args=[self.user_1.username])
def setUp(self): self.book = BookFactory() self.book.version = BookVersionFactory(book=self.book) # TODO: improve this self.book.save() self.user_1 = self.book.owner # need two users to be able to test collaboration within a book self.user_2 = UserFactory() # setup book content chapter_1 = ChapterFactory(book=self.book, version=self.book.version) chapter_2 = ChapterFactory(book=self.book, version=self.book.version) # setup content for user two in same book # call this "Contribution" book_history = BookHistoryFactory( book=self.book, user=self.user_2, chapter=chapter_2 ) self.dispatcher = reverse('accounts:view_profile', args=[self.user_1.username])
class DashboardTest(TestCase): """ Tests Dashboard page as logged in and as anonymous user """ def setUp(self): self.book = BookFactory() self.book.version = BookVersionFactory(book=self.book) # TODO: improve this self.book.save() self.user_1 = self.book.owner # need two users to be able to test collaboration within a book self.user_2 = UserFactory() # setup book content chapter_1 = ChapterFactory(book=self.book, version=self.book.version) chapter_2 = ChapterFactory(book=self.book, version=self.book.version) # setup content for user two in same book # call this "Contribution" book_history = BookHistoryFactory( book=self.book, user=self.user_2, chapter=chapter_2 ) self.dispatcher = reverse('accounts:view_profile', args=[self.user_1.username]) def _test_base_details(self, response): # context should contain all below variables context_vars = [ 'books', 'books_collaborating', 'licenses', 'groups', 'recent_activity', 'book_license', 'book_visible' ] for var in context_vars: self.assertTrue(var in response.context) def test_as_anonymous(self): response = self.client.get(self.dispatcher) # response status code should be 403 self.assertEquals(response.status_code, 403) # This is temporary. We should test this logic in new tests # page title should be "User profile" #self.assertContains(response, 'User profile') # create button shouldn't be available #self.assertNotContains(response, 'Create new book') # as anonymous, check basic details #self._test_base_details(response) def test_as_account_owner(self): self.client.login( username=self.user_2.username, password=PLAIN_USER_PASSWORD ) own_dispatcher = reverse('accounts:view_profile', args=[self.user_2.username]) response = self.client.get(own_dispatcher) context = response.context # as authenticated user, test basic details self._test_base_details(response) # response should contain next things self.assertContains(response, 'My Dashboard') self.assertContains(response, 'Create new book') self.assertContains(response, 'Go to settings') self.assertContains(response, 'Log out') self.assertContains(response, 'Import Book') self.assertContains(response, 'Participating Books') # this user is collaborating with other books self.assertTrue(len(context['books_collaborating']) >= 1) self.assertTrue(self.book in context['books_collaborating']) # this user has no groups belonging self.assertTrue(len(context['groups']) == 0) def test_other_user_dashboard(self): self.client.login( username=self.user_2.username, password=PLAIN_USER_PASSWORD ) response = self.client.get(self.dispatcher) # response status code should be 403 self.assertEquals(response.status_code, 403) # This is temporary. We should test this logic in new tests # context = response.context # # as authenticated user, test basic details # self._test_base_details(response) # # response should contain next things # self.assertContains(response, 'FOLLOW ME') # # response shouldn't contain # self.assertNotContains(response, 'Go to settings') # self.assertNotContains(response, 'Create new book') # self.assertNotContains(response, 'Log out') # # this user has created one book and one group at least # self.assertTrue(len(context['books']) >= 1) # self.assertTrue(self.book in context['books']) # self.assertTrue(len(context['groups']) >= 1)
class DashboardTest(TestCase): """ Tests Dashboard page as logged in and as anonymous user """ def setUp(self): self.book = BookFactory() self.book.version = BookVersionFactory( book=self.book) # TODO: improve this self.book.save() self.user_1 = self.book.owner # need two users to be able to test collaboration within a book self.user_2 = UserFactory() # setup book content chapter_1 = ChapterFactory(book=self.book, version=self.book.version) chapter_2 = ChapterFactory(book=self.book, version=self.book.version) # setup content for user two in same book # call this "Contribution" book_history = BookHistoryFactory(book=self.book, user=self.user_2, chapter=chapter_2) self.dispatcher = reverse('accounts:view_profile', args=[self.user_1.username]) def _test_base_details(self, response): # context should contain all below variables context_vars = [ 'books', 'books_collaborating', 'licenses', 'groups', 'recent_activity', 'book_license', 'book_visible' ] for var in context_vars: self.assertTrue(var in response.context) def test_as_anonymous(self): response = self.client.get(self.dispatcher) # response status code should be 403 self.assertEquals(response.status_code, 403) # This is temporary. We should test this logic in new tests # page title should be "User profile" #self.assertContains(response, 'User profile') # create button shouldn't be available #self.assertNotContains(response, 'Create new book') # as anonymous, check basic details #self._test_base_details(response) def test_as_account_owner(self): self.client.login(username=self.user_2.username, password=PLAIN_USER_PASSWORD) own_dispatcher = reverse('accounts:view_profile', args=[self.user_2.username]) response = self.client.get(own_dispatcher) context = response.context # as authenticated user, test basic details self._test_base_details(response) # response should contain next things self.assertContains(response, 'My Dashboard') self.assertContains(response, 'Create new book') self.assertContains(response, 'Go to settings') self.assertContains(response, 'Log out') self.assertContains(response, 'Import Book') self.assertContains(response, 'Participating Books') # this user is collaborating with other books self.assertTrue(len(context['books_collaborating']) >= 1) self.assertTrue(self.book in context['books_collaborating']) # this user has no groups belonging self.assertTrue(len(context['groups']) == 0) def test_other_user_dashboard(self): self.client.login(username=self.user_2.username, password=PLAIN_USER_PASSWORD) response = self.client.get(self.dispatcher) # response status code should be 403 self.assertEquals(response.status_code, 403)