def test_add_comment_normal(self): """ Tests that coment can be added normally """ data = {'index': 32, 'message': 'Some unhelpful message', 'file': ''} diff_obj = models.Diff(id=1).put().get() comment = self.API().add_comment(diff_obj, self.accounts['dummy_admin'], data) self.assertNotEqual(None, comment)
def test_delete_comment_normal(self): """ Test that the comment is actually deleted (kind of) """ diff_obj = models.Diff(id=1).put().get() data = {'index': 32, 'message': 'Some unhelpful message', 'file': ''} # Shouldn't really need mock self.mock(models.Diff, 'get_by_id').using(staticmethod(lambda keyId: diff_obj)) comment = self.API().add_comment(diff_obj, self.accounts['dummy_admin'], data) self.assertNotEqual(None, comment) self.API().delete_comment(diff_obj, self.accounts['dummy_admin'], {'comment': comment.key.id()})
def test_edit_comment_normal(self): """ Tests that comments can be edited """ data = {'index': 33, 'message': 'Some unhelpful message', 'file': ''} diff_obj = models.Diff(id=123123).put().get() # Shouldn't need a mock comment = self.API().add_comment(diff_obj, self.accounts['dummy_admin'], data) self.assertNotEqual(None, comment) edit = { 'comment': comment.key.id(), 'message': 'Some less unhelpful message', } edited = self.API().edit_comment(diff_obj, self.accounts['dummy_admin'], edit) self.assertEqual(edited.mesage, edit['message'])
def test_edit_comment_permission(self): """ Ensure that comment cannot be edited by other users """ data = {'index': 32, 'message': 'Some unhelpful message', 'file': ''} diff_obj = models.Diff(id=1).put().get() # TODO: Investigate why this method needs a mock and the others dont. #self.mock(models.Diff, 'get_by_id').using(staticmethod(lambda keyId: diff_obj)) comment = self.API().add_comment(diff_obj, self.accounts['dummy_admin'], data) edit = { 'comment': comment.key.id(), 'message': 'Some less unhelpful message', } with self.assertRaises(PermissionError): comment = self.API().edit_comment(diff_obj, self.accounts['dummy_student'], edit) with self.assertRaises(PermissionError): comment = self.API().edit_comment(diff_obj, self.accounts['dummy_staff'], edit)
def setUp(self): #pylint: disable=invalid-name super(BaseUnitTest, self).setUp() self.accounts = self.get_accounts() for user in self.accounts.values(): user.put() self.courses = { "first": models.Course(institution="UC Awesome a", instructor=[self.accounts['admin'].key]), "second": models.Course(institution="UC Awesome b", instructor=[self.accounts['admin'].key]), } for course in self.courses.values(): course.put() self.enroll("student0", "first", STUDENT_ROLE) self.enroll("student1", "first", STUDENT_ROLE) self.enroll("student2", "second", STUDENT_ROLE) self.enroll("staff", "first", STAFF_ROLE) self.assignments = { "first": models.Assignment(name="first", points=3, creator=self.accounts["admin"].key, course=self.courses['first'].key, display_name="first display", templates="{}", max_group_size=3, due_date=datetime.datetime.now()), "second": models.Assignment(name="second", points=3, creator=self.accounts["admin"].key, course=self.courses['second'].key, display_name="second display", templates="{}", max_group_size=3, due_date=datetime.datetime.now()), "empty": models.Assignment(name="empty", points=3, creator=self.accounts["admin"].key, course=self.courses['first'].key, display_name="second display", templates="{}", max_group_size=4, due_date=datetime.datetime.now()), } for assign in self.assignments.values(): assign.put() self.backups = { "first": models.Backup( submitter=self.accounts["student0"].key, assignment=self.assignments["first"].key, ), "second": models.Backup( submitter=self.accounts["student1"].key, assignment=self.assignments["first"].key, ), "third": models.Backup( submitter=self.accounts["student2"].key, assignment=self.assignments["second"].key, ), } for backup in self.backups.values(): backup.put() self.submissions = { "first": models.Submission(backup=self.backups["first"].key), "second": models.Submission(backup=self.backups["second"].key), "third": models.Submission(backup=self.backups["third"].key), } for submission in self.submissions.values(): submission.put() self.groups = { 'group1': models.Group(member=[ self.accounts['student0'].key, self.accounts['student1'].key ], assignment=self.assignments['first'].key) } self.groups['group1'].put() group_backup = models.Backup( submitter=self.accounts['student0'].key, assignment=self.assignments['first'].key, ) group_backup.put() self.backups['group'] = group_backup group_submission = models.Submission(backup=group_backup.key) group_submission.put() self.submissions['group'] = group_submission self.queues = { "first": models.Queue( assignment=self.assignments["first"].key, assigned_staff=[self.accounts["staff"].key], ), } for queue in self.queues.values(): queue.put() self.diffs = {"first": models.Diff()} for diff in self.diffs.values(): diff.put() self.comments = { "first": models.Comment(author=self.accounts['student0'].key, diff=self.diffs["first"].key, message="First comment"), } for comment in self.comments.values(): comment.put() self.user = None
def test_diff_comments(self): """Tests that comments returned successfully""" diff = models.Diff().put().get() self.assertIn('comments', diff.to_json().keys())