class ScoreEncodingTest(TestCase): def setUp(self): self.score_encoding = ScoreEncodingFactory() self.global_id = self.score_encoding.global_id def test_find_by_global_id(self): score_encoding = mdl_score_encoding.find_by_global_id( global_id=self.global_id) self.assertEqual(score_encoding, self.score_encoding, "Wrong score encoding returned") score_encoding = mdl_score_encoding.find_by_global_id( global_id="101245") self.assertIsNone(score_encoding, "Should return no score encoding") def test_insert_or_update_document(self): new_document = load_score_encoding_sample() score_encoding = mdl_score_encoding.insert_or_update_document( "1202151", new_document) self.assertJSONEqual(score_encoding.document, new_document, "Problem when inserting new document") mdl_score_encoding.insert_or_update_document(self.global_id, new_document) self.score_encoding.refresh_from_db() self.assertJSONEqual(self.score_encoding.document, new_document, "Problem when updating document") def test_str(self): a_score_encoding = ScoreEncodingFactory(global_id="123654") self.assertEqual(str(a_score_encoding), "123654")
class ScoreSheetTest(TestCase): def setUp(self): self.score_encoding = ScoreEncodingFactory(global_id=GLOBAL_ID) def test_get_score_sheet_invalid_json(self): global_id = "007896" test_score_encoding.create_invalid_score_encoding(global_id=global_id) document = score_encoding.get_score_sheet(global_id) self.assertIsNone(document) def test_check_db_scores(self): scores_check = score_encoding.check_db_scores(GLOBAL_ID) self.assertTrue(scores_check) def test_get_score_sheet_if_not_present_in_db(self): self.score_encoding.delete() document = score_encoding.get_score_sheet(GLOBAL_ID) self.assertIsNone(document) def test_get_score_sheet_if_present_in_db_but_outdated(self): old_date = "15/11/2016" json_obj = json.loads(self.score_encoding.document) json_obj['publication_date'] = old_date self.score_encoding.document = json.dumps(json_obj) self.score_encoding.save() document = score_encoding.get_score_sheet(GLOBAL_ID) self.assertIsNone(document) def test_get_score_sheet_if_present_in_db(self): document = score_encoding.get_score_sheet(GLOBAL_ID) self.assertJSONEqual(self.score_encoding.document, document)
def test_when_invalid_structure_json(self): global_id = "045123" incorrect_format_json = load_score_encoding_sample( "assessments/tests/resources/incorrect_format_sample.json") ScoreEncodingFactory(global_id=global_id, document=incorrect_format_json) pdf = score_encoding.print_scores(global_id) self.assertIsNone(pdf, "Should not create any pdf")
def test_when_papersheet_is_present(self): ScoreEncodingFactory(global_id=GLOBAL_ID) response = self.client.get(self.url, data={}, follow=True, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, OK)
def setUp(self): self.score_encoding = ScoreEncodingFactory() self.global_id = self.score_encoding.global_id self.tutor = test_tutor.create_tutor() self.tutor.person.user = User.objects.create_user('testo', password='******') self.tutor.person.save() perm = Permission.objects.get(codename="is_tutor") self.tutor.person.user.user_permissions.add(perm)
def test_when_papersheet_is_present(self): ScoreEncodingFactory(global_id=GLOBAL_ID) response = self.client.get(self.url, follow=True) self.assertEqual(response.status_code, OK) self.assertEqual(response.get('Content-Type'), 'application/pdf') self.assertEqual( response.get('Content-Disposition'), 'attachment; filename="%s"' % ("%s.pdf" % _('scores_sheet')))
def test_when_faculty_administator(self): PersonFactory(global_id=OTHER_GLOBAL_ID) ScoreEncodingFactory(global_id=OTHER_GLOBAL_ID) self.__set_user_as_faculty_administrator() response = self.client.get(self.url, follow=True) self.assertEqual(response.status_code, OK) self.assertEqual(response.get('Content-Type'), 'application/pdf') self.assertEqual( response.get('Content-Disposition'), 'attachment; filename="%s"' % ("%s.pdf" % _('scores_sheet')))
def setUp(self): self.score_encoding = ScoreEncodingFactory(global_id=GLOBAL_ID)
def test_str(self): a_score_encoding = ScoreEncodingFactory(global_id="123654") self.assertEqual(str(a_score_encoding), "123654")
def setUp(self): self.score_encoding = ScoreEncodingFactory() self.global_id = self.score_encoding.global_id