Esempio n. 1
0
def test_update_source(testcase: TestCase, sources_backup: pd.DataFrame,
                       sources_backup_db: pd.DataFrame,
                       sources_add: pd.DataFrame,
                       sources_add_db: pd.DataFrame):
    '''
    Test that the sources are correctly updated in the database.

    Parameters
    ----------
    testcase : class
        Test class.
    sources_backup : pd.DataFrame
        The sources before adding images in the output.
    sources_backup_db : pd.DataFrame
        The sources before adding images in the database.
    sources_add : pd.DataFrame
        The sources after adding images in the output.
    sources_add_db : pd.DataFrame
        The sources after adding images in the database.
    '''
    # check source database and file is the same after original run
    for ind in sources_backup.index:
        n_meas_db = sources_backup_db.loc[ind, 'n_meas']
        n_meas_pd = sources_backup.loc[ind, 'n_meas']
        testcase.assertEqual(n_meas_db, n_meas_pd)

    # check source database and file is the same after adding an image
    for ind in sources_add.index:
        n_meas_db = sources_add_db.loc[ind, 'n_meas']
        n_meas_pd = sources_add.loc[ind, 'n_meas']
        testcase.assertEqual(n_meas_db, n_meas_pd)
Esempio n. 2
0
 def test_get_followers_empty_list(self):
     """
     Допустим, подписчиков нет.
     """
     self.user1.followers.clear()
     emails = get_followers_list(self.user1)
     TestCase.assertEqual(self, len(emails), 0)
Esempio n. 3
0
    def check_index(self, test_case: TestCase, response):
        exp_glry_data = json.loads(response.content.decode('utf-8'))
        exp_glry_list = exp_glry_data['gallery']

        valid_gallery_list = {
            g['name']: {
                'name': g['name'],
                'slug': str(g['id']),
                'description': g['description'],
                'preview_image_url': g['preview_image_url']
            }
            for g in self.galleries
        }
        test_case.assertEqual(len(exp_glry_list),
                              len(valid_gallery_list),
                              msg='Wrong Gallery Count')

        for g in exp_glry_list:
            valid_data = valid_gallery_list[g['name']]
            test_case.assertEqual(valid_data['name'],
                                  g['name'],
                                  msg='Wrong Gallery Name')
            test_case.assertEqual(valid_data['slug'],
                                  g['slug'],
                                  msg='Wrong Gallery Slug')
            test_case.assertEqual(valid_data['description'],
                                  g['description'],
                                  msg='Wrong Gallery Description')
            test_case.assertEqual(valid_data['preview_image_url'],
                                  g['preview_image_url'],
                                  msg='Wrong Preview Url')
Esempio n. 4
0
def get_list_check(instance: TestCase, res: HttpResponse):
  body = json.loads(res.content)

  instance.assertEqual(res.status_code, 200)
  instance.assertEqual(body.get('status'), 200)
  instance.assertIsInstance(body.get('data'), dict)
  instance.assertIsInstance(body.get('data').get('results'), list)
  format_success_response_check(instance, res)
Esempio n. 5
0
def assert_examine_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")

    test_case.assertTrue(response.data.pop('examiner_approval_date') is None)
    test_case.assertTrue(response.data.pop('nominator'))

    test_case.assertEqual(response.data, true_data)
Esempio n. 6
0
 def test_get_follwers_email_list(self):
     """
     Протестируем правильность вывода списка email'ов подписчиков.
     """
     emails = get_followers_list(self.user1)
     right_emails = ['*****@*****.**', '*****@*****.**']
     TestCase.assertEqual(self, len(emails), len(right_emails))
     for email, right_email in zip(emails, right_emails):
         TestCase.assertEqual(self, email, right_email)
Esempio n. 7
0
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")
Esempio n. 8
0
 def test_getCourse_courseNotExists(self):
     """
         Test adds 3 courses, and retrieves none, since
         none match the criteria
     """
     myRetrievedCourses = self.myCourseCatalog.searchCoursesThroughPartialName(
         "z")
     TestCase.assertEqual(
         self, 0, len(myRetrievedCourses),
         "The correct amount of courses was not retrieved")
Esempio n. 9
0
 def test_getCourseBasedOnCredits_CourseNotExists(self):
     """
         Test adds 3 courses, and attempts to retrieve a
         course with les than 2 credits, which none of
         the courses have.
     """
     myRetrievedCourses = self.myCourseCatalog.searchCoursesByCredits(0, 2)
     TestCase.assertEqual(
         self, 0, len(myRetrievedCourses),
         "The correct amount of courses was not retrieved")
Esempio n. 10
0
 def test_getCourseBasedOnCredits(self):
     """
         Test adds 3 courses, and retrieves only the 1
         with 3.5 credits
     """
     myRetrievedCourses = self.myCourseCatalog.searchCoursesByCredits(3.5)
     TestCase.assertEqual(
         self, 1, len(myRetrievedCourses),
         "The correct amount of courses was not retrieved")
     TestCase.assertEqual(self, "Test 1", myRetrievedCourses[0].name,
                          "The course was not retrieved from the database")
Esempio n. 11
0
 def test_addCourse_removeItem_lecture(self):
     """
         Tests that a lecture is added to schedule and then removed
     """
     myLecture = self.myCourseCatalog.searchCoursesThroughPartialName("COEN428")[0].lecture_set.all()[0]
     mySchedule = Schedule()
     mySchedule.add_item(myLecture)
     coursesInMySchedule = mySchedule.view_schedule()
     TestCase.assertIn(self, myLecture, coursesInMySchedule, "The course was not added to the schedule")
     mySchedule.remove_item(myLecture)
     coursesInMySchedule = mySchedule.view_schedule()
     TestCase.assertEqual(self, len(coursesInMySchedule), 0, "The course was not removed from the schedule")
Esempio n. 12
0
 def test_getCourseBasedOnName(self):
     """
         Test adds 3 courses, and retrieves only the 1
         with course name Test 2
     """
     myRetrievedCourses = self.myCourseCatalog.searchCoursesThroughPartialName(
         "Test 1")
     TestCase.assertEqual(
         self, 1, len(myRetrievedCourses),
         "The correct amount of courses was not retrieved")
     TestCase.assertEqual(self, "Test 1", myRetrievedCourses[0].name,
                          "The course was not retrieved from the database")
Esempio n. 13
0
 def test_addLab_lectureNotExists(self):
     """
         Test attempts to add a lab to a course that doesn't
         exist and verifies that it is not found in the database.
     """
     self.myCourseCatalog.addLabToCourse("AM", "COEN", 341, "8:45:00",
                                         "10:00:00", "--W-F--", "Fall",
                                         "SGW H-620", "A", "AI")
     TestCase.assertEqual(
         self,
         len(self.myCourseCatalog.searchCoursesThroughPartialName(
             "COEN341")), 0, "Course has been added to database")
Esempio n. 14
0
def assertRunsSuccessfully(test_case: TestCase, job: ProcessorJob) -> dict:
    final_context = no_op.no_op_processor(job.pk)
    test_case.assertTrue(final_context["success"])
    test_case.assertTrue(os.path.exists(final_context["output_file_path"]))

    test_case.assertEqual(len(final_context["samples"]), 1)
    test_case.assertEqual(len(final_context["computed_files"]), 1)

    for sample in final_context["samples"]:
        for cf in final_context["computed_files"]:
            test_case.assertTrue(cf in sample.computed_files.all())

    # Return final_context so we can perform additional checks manually
    return final_context
Esempio n. 15
0
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)
Esempio n. 16
0
 def test_modifyCourseCredits(self):
     """
         Test modifies the number of credits a course
         that exists is worth
     """
     myCourse = self.myCourseCatalog.searchCoursesByCredits(4, 4)
     TestCase.assertEqual(
         self, myCourse[0].name, "Test 2",
         "The course does not have the expected number of credits")
     self.myCourseCatalog.modifyCreditsForCourse("SOEN", 341, 5)
     myCourse = self.myCourseCatalog.searchCoursesByCredits(5, 5)
     TestCase.assertEqual(
         self, myCourse[0].name, "Test 2",
         "The course does not have the modified number of credits")
Esempio n. 17
0
def test_num_sources(testcase: TestCase, sources: pd.DataFrame, num: int):
    '''
    Test the number of overall sources identified is correct.

    Parameters
    ----------
    testcase : class
        Test class.
    sources : pd.DataFrame
        Dataframe containing identified sources.
    num : int
        Number of identified sources.
    '''

    testcase.assertEqual(len(sources.index), num)
Esempio n. 18
0
 def test_removeCourse_courseNotExists(self):
     """
         Test tries to remove a course that does not exist,
         then makes sure that the other courses are not affected.
     """
     allCourses = self.myCourseCatalog.searchCoursesThroughPartialName(" ")
     TestCase.assertEqual(
         self, len(allCourses), 3,
         "There are not the correct amount of courses in the database")
     self.myCourseCatalog.removeCourseWithSections("COEN", 341)
     allCourses = self.myCourseCatalog.searchCoursesThroughPartialName(" ")
     TestCase.assertLess(self, len(allCourses), 4,
                         "One or many courses have been added")
     TestCase.assertGreater(self, len(allCourses), 2,
                            "One or many courses have been removed")
Esempio n. 19
0
def test_cannot_post_with_empty_fields(test_case: TestCase,
                                       url: str,
                                       fields: List[str]):
    """Check if POST requests to url with missing data fields
    return 400 response code."""

    # Check post request with no data.
    response = test_case.client.post(url, data={})
    test_case.assertEqual(response.status_code, 400)

    # Check post request with only one field filled.
    if len(fields) > 1:
        for field in fields:
            response = test_case.client.post(url, data={field: 'test'})
            test_case.assertEqual(response.status_code, 400)
Esempio n. 20
0
def test_forced_num(testcase: TestCase, forced_1: dict, forced_2: dict):
    '''
    Test the number of forced extractions are correct.

    Parameters
    ----------
    testcase : class
        Test class.
    forced1 : dict
        The forced files in one run.
    forced_2 : dict
        The forced files in a different run.
    '''
    count = lambda x: np.sum([len(f.index) for f in x.values()])
    testcase.assertEqual(count(forced_1), count(forced_2))
Esempio n. 21
0
 def test_modifyCourseCredits_CourseNotExist(self):
     """
         Test attempts to modify the number of credits
         a course that does not exist, and then verifies
         that the course still does not exist
     """
     myCourse = self.myCourseCatalog.searchCoursesThroughPartialName(
         "COEN 341")
     TestCase.assertEqual(self, len(myCourse), 0,
                          "The course exists already")
     self.myCourseCatalog.modifyCreditsForCourse("COEN", 341, 5)
     myCourse = self.myCourseCatalog.searchCoursesThroughPartialName(
         "COEN 341")
     TestCase.assertEqual(
         self, len(myCourse), 0,
         "The course has been added from an attempt to modify credits")
Esempio n. 22
0
 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")
Esempio n. 23
0
def test_forced_num(testcase: TestCase, forced: dict, num: int):
    '''
    Test the number of forced extractions is expected.

    Parameters
    ----------
    testcase : class
        Test class.
    forced : dict
        The forced measurements.
    num : int
        The number of expected forced measurements.
    '''
    count = np.sum([len(f.index) for f in forced.values()])

    testcase.assertEqual(count, num)
Esempio n. 24
0
 def test_getCourseBasedOnDepartment(self):
     """
         Test adds 3 courses, and retrieves only the 2
         with department SOEN
     """
     myRetrievedCourses = self.myCourseCatalog.searchCoursesThroughPartialName(
         "SOEN")
     courses = []
     for c in myRetrievedCourses:
         courses.append(c.name)
     TestCase.assertEqual(
         self, 2, len(myRetrievedCourses),
         "The correct amount of courses was not retrieved")
     TestCase.assertIn(self, "Test 1", courses,
                       "The  course was not retrieved from the database")
     TestCase.assertIn(self, "Test 2", courses,
                       "The  course was not retrieved from the database")
Esempio n. 25
0
 def test_getCourseBasedOnCreditRange(self):
     """
         Test adds 3 courses, and retrieves only the 2
         courses with 3 to 3.5 credits
     """
     myRetrievedCourses = self.myCourseCatalog.searchCoursesByCredits(
         3, 3.5)
     courses = []
     for c in myRetrievedCourses:
         courses.append(c.name)
     TestCase.assertEqual(
         self, 2, len(myRetrievedCourses),
         "The correct amount of courses was not retrieved")
     TestCase.assertIn(self, "Test 0", courses,
                       "The  course was not retrieved from the database")
     TestCase.assertIn(self, "Test 1", courses,
                       "The  course was not retrieved from the database")
Esempio n. 26
0
 def test_removeTutorial(self):
     """
         Test adds a lecture to a course, and then a tutorial
         to that lecture, and then verifies that it is in the
         database, and then removes it and verifies that it is
         no long in the database
     """
     self.test_addTutorial()
     TestCase.assertTrue(
         self,
         self.myCourseCatalog.removeTutorialFromCourse(
             "AI", "SOEN", 341, "Fall"), "Tutorial removal not successful")
     TestCase.assertEqual(
         self,
         len(
             self.myCourseCatalog.searchCoursesThroughPartialName("SOEN341")
             [0].tutorial_set.all()), 0, "Tutorial not removed from course")
Esempio n. 27
0
 def test_addCourse_removeItem_lab(self):
     """
         Tests that a lab and its accompanying tutorial and
         lecture are added to schedule and then removed
     """
     myLecture = self.myCourseCatalog.searchCoursesThroughPartialName("COEN428")[0].lecture_set.all()[0]
     myTutorial = self.myCourseCatalog.searchCoursesThroughPartialName("COEN428")[0].tutorial_set.all()[0]
     myLab = self.myCourseCatalog.searchCoursesThroughPartialName("COEN428")[0].lab_set.all()[0]
     mySchedule = Schedule()
     mySchedule.add_item(myLab)
     coursesInMySchedule = mySchedule.view_schedule()
     TestCase.assertIn(self, myLab, coursesInMySchedule, "The course was not added to the schedule")
     TestCase.assertIn(self, myTutorial, coursesInMySchedule, "The course was not added to the schedule")
     TestCase.assertIn(self, myLecture, coursesInMySchedule, "The course was not added to the schedule")
     mySchedule.remove_item(myLab)
     coursesInMySchedule = mySchedule.view_schedule()
     TestCase.assertEqual(self, len(coursesInMySchedule), 0, "The course was not removed from the schedule")
Esempio n. 28
0
 def test_addLecture(self):
     """
         Test attempts to add a lecture to a course
         and verifies that it is found in the database.
     """
     TestCase.assertTrue(
         self,
         self.myCourseCatalog.addLectureToCourse("A", "SOEN", 341,
                                                 "8:45:00", "10:00:00",
                                                 "--W-F--", "Fall",
                                                 "SGW H-620", False),
         "Lecture not successfully added to course")
     TestCase.assertEqual(
         self,
         len(
             self.myCourseCatalog.searchCoursesThroughPartialName("SOEN341")
             [0].lecture_set.all()), 1,
         "Lecture not successfully added to database")
Esempio n. 29
0
 def test_addTutorial(self):
     """
         Test attempts to add a tutorial to a lecture and
         verifies that it is found in the database.
     """
     self.test_addLecture()
     TestCase.assertTrue(
         self,
         self.myCourseCatalog.addTutorialToCourse("AI", "SOEN", 341, "Fall",
                                                  "8:45:00", "10:00:00",
                                                  "---R---", "SGW H-620",
                                                  "A"),
         "Tutorial not successfully added to course")
     TestCase.assertEqual(
         self,
         len(
             self.myCourseCatalog.searchCoursesThroughPartialName("SOEN341")
             [0].tutorial_set.all()), 1,
         "Tutorial not successfully added to lecture")
Esempio n. 30
0
 def test_getCourseBasedOnPartialNumber(self):
     """
         Test adds 3 courses, and retrieves the 3 with
         course number or name containing 1
     """
     myRetrievedCourses = self.myCourseCatalog.searchCoursesThroughPartialName(
         "1")
     courses = []
     for c in myRetrievedCourses:
         courses.append(c.name)
     TestCase.assertEqual(
         self, 3, len(myRetrievedCourses),
         "The correct amount of courses was not retrieved")
     TestCase.assertIn(self, "Test 0", courses,
                       "The  course was not retrieved from the database")
     TestCase.assertIn(self, "Test 1", courses,
                       "The  course was not retrieved from the database")
     TestCase.assertIn(self, "Test 2", courses,
                       "The  course was not retrieved from the database")
Esempio n. 31
0
 def test_convertDateStringToUnixTime(TestCase):
     (start_unixtime, end_unixtime) = views.convertDateStringToUnixTime("20131201", "20131202")
     TestCase.assertEqual(start_unixtime, "1385856000")
     TestCase.assertEqual(end_unixtime, "1385942400")