def test_all_new_tags(self): with self.assertLogs( 'project.services.logging_service', logging.INFO) as logs: result = TagsService.update_tags_for_submission( self.cfa_user.id, self.sub.id, "new, thing") self.assertTagsHaveNames(result, ["existing", "new", "thing"]) assertInLogsCount(logs, { 'event_name=app_tag_added': 2, 'new': 1, 'thing': 1})
def test_some_new_tags(self): with self.assertLogs( 'project.services.logging_service', logging.INFO) as logs: result = TagsService.update_tags_for_submission( self.cfa_user.id, self.sub.id, "old, new") self.assertTagsHaveNames(result, ["existing", "new", "old"]) assertInLogsCount( logs, { 'event_name=app_tag_added': 2, "'tag_name': 'new'": 1, "'tag_name': 'old'": 1})
def post(self, request): try: submission_id, tags_text = parse_tag_post_data(request.POST) except ValueError: return Response(status=400) if not isinstance(submission_id, int): return Response(status=400) try: updated_tags = TagsService.update_tags_for_submission( request.user.id, submission_id, tags_text) except IntegrityError: return Response(status=400) except UserCannotBeNoneError: return Response(status=403) return Response(data=updated_tags, status=201)
def post(self, request): try: submission_id, tags_text = parse_tag_post_data(request.POST) except ValueError: return Response(status=400) if not isinstance(submission_id, int): return Response(status=400) try: updated_tags = TagsService.update_tags_for_submission( request.user.id, submission_id, tags_text) except IntegrityError: return Response(status=400) except UserCannotBeNoneError: return Response(status=403) return Response(data=updated_tags, status=201)
def test_empty_tags(self): result = TagsService.update_tags_for_submission( self.cfa_user.id, self.sub.id, ", ,") self.assertTagsHaveNames(result, ["existing"])
def test_bad_submission(self): with self.assertRaises(ValueError): TagsService.update_tags_for_submission(self.cfa_user.id, None, "existing")
def test_bad_user(self): with self.assertRaises(UserCannotBeNoneError): TagsService.update_tags_for_submission(None, self.sub.id, "existing")
def test_no_new_tags(self): result = TagsService.update_tags_for_submission( self.cfa_user.id, self.sub.id, "old, existing") self.assertTagsHaveNames(result, ["existing", "old"])