def assert_file_not_exist(test: TestCase, file_name: str): url = f"/media/gmm/{file_name}" file_path = f"{settings.MEDIA_ROOT}/gmm/{file_name}" response = test.client.get(url) test.assertEqual(404, response.status_code, "endpoint shall fail") test.assertFalse( FileObject.objects.filter(name=file_name).exists(), "file shall not be in DB") test.assertFalse(os.path.exists(file_path), "file is not in filesystem")
def assert_supervise_response(test_case: TestCase, response, true_data) -> None: if response.data.get('id', False): raise AttributeError( "Please remove id before passing data into this function") # Not check-able test_case.assertTrue(response.data.pop('supervisor_approval_date') is None) test_case.assertTrue(response.data.pop('nominator')) # We'll test approval in other tests test_case.assertFalse(response.data.pop('is_supervisor_approved')) test_case.assertEqual(response.data, true_data)
def test_removeLecture_noLectureExists(self): """ Test attempts to remove a non-existing lecture from a course and verifies that it is not there. """ TestCase.assertFalse( self, self.myCourseCatalog.removeLectureFromCourse( "A", "SOEN", 341, "Fall"), "The non-existant lecture was successfully removed") TestCase.assertEqual( self, len( self.myCourseCatalog.searchCoursesThroughPartialName("SOEN341") [0].lecture_set.all()), 0, "The lecture was created and not removed")
def test_addTutorial_lectureNotExists(self): """ Test attempts to add a tutorial to a course that doesn't exist and verifies that it is not found in the database. """ TestCase.assertFalse( self, self.myCourseCatalog.addTutorialToCourse("AI", "COEN", 341, "Fall", "8:45:00", "10:00:00", "--W-F--", "SGW H-620", "A"), "Tutorial successfully added to a course that does not exist") TestCase.assertEqual( self, len(self.myCourseCatalog.searchCoursesThroughPartialName( "COEN341")), 0, "Course has been added to database")
def assert_contract_response(test_case: TestCase, response, true_data) -> None: if response.data.get('id', False): raise AttributeError( 'Please remove id before passing data into this function') # Not check-able test_case.assertTrue(response.data.pop('create_date')) test_case.assertTrue(response.data.pop('supervise') is not None) test_case.assertTrue(response.data.pop('assessment') is not None) test_case.assertTrue(response.data.pop('was_submitted') is not None) test_case.assertTrue( response.data.pop('is_examiner_nominated') is not None) # Contract should at least have one supervisor, otherwise is_all_supervisors_approved # would be false. Contract test also does not approve any supervise relation, as such # is_all_supervisors_approved should always be False. test_case.assertFalse(response.data.pop('is_all_supervisors_approved')) # Contract should at least have one assessment, otherwise is_all_assessments_approved # would be false. Contract test also does not approve any assessment method, as such # is_all_assessments_approved should always be False. test_case.assertFalse(response.data.pop('is_all_assessments_approved')) test_case.assertEqual(response.data, true_data)
def test_login_method_is_not_post(self): methods = ['GET', 'HEAD', 'PUT', 'DELETE'] for method in methods: with self.subTest(method=method): TestCase.assertFalse(check_request_method_is_post(method), False)