Exemplo n.º 1
0
 def test_load_error(self, mock_read_in, mock_clean):
     mock_read_in.return_value = [{}]
     (FAILED, endmsg) = load("filename")
     self.assertEqual(mock_read_in.call_count, 1)
     self.assertEqual(mock_clean.call_count, 0)  # bailed before cleaning
     self.assertTrue('ERROR' in " ".join(FAILED))
     mock_read_in.return_value = [{'raw_data': 'raw stuff'}]
     mock_clean.return_value = {'cleaned_data': 'clean stuff'}
     (FAILED, endmsg) = load("filename")
     self.assertEqual(mock_read_in.call_count, 2)
     self.assertEqual(mock_clean.call_count, 1)
     self.assertTrue('ERROR' in " ".join(FAILED))
 def test_load_error(self, mock_read_in, mock_clean):
     mock_read_in.return_value = [{}]
     (FAILED, endmsg) = load("filename")
     self.assertEqual(mock_read_in.call_count, 1)
     self.assertEqual(mock_clean.call_count, 0)  # bailed before cleaning
     self.assertTrue('ERROR' in " ".join(FAILED))
     mock_read_in.return_value = [{'raw_data': 'raw stuff'}]
     mock_clean.return_value = {'cleaned_data': 'clean stuff'}
     (FAILED, endmsg) = load("filename")
     self.assertEqual(mock_read_in.call_count, 2)
     self.assertEqual(mock_clean.call_count, 1)
     self.assertTrue('ERROR' in " ".join(FAILED))
Exemplo n.º 3
0
 def handle(self, *args, **options):
     if options['s3'].upper() == "TRUE":
         S3 = True
     else:
         S3 = False
     for filesource in options['source']:
         try:
             if S3:
                 (FAILED, endmsg) = load_programs.load(filesource, s3=S3)
             else:
                 (FAILED, endmsg) = load_programs.load(filesource)
         except:
             self.stdout.write("Error with script")
         else:
             if FAILED:
                 for fail_msg in FAILED:
                     self.stdout.write(fail_msg)
             self.stdout.write(endmsg)
    def test_load(self, mock_get_or_create_program, mock_clean, mock_read_in):
        accreditor = (
            "Accrediting Council for Independent Colleges "
            "and Schools (ACICS) - Test")
        jpr_note = (
            "The rate reflects employment status "
            "as of November 1, 2014 - Test")
        program_name = "Occupational Therapy Assistant - 981 - Test"
        mock_read_in.return_value = [
            {"ipeds_unit_id": "408039",
             "ope_id": "",
             "campus_name": "Ft Wayne - Test",
             "program_code": "981 - Test",
             "program_name": program_name,
             "program_level": "4",
             "program_length": "25",
             "accreditor": accreditor,
             "median_salary": "24000",
             "average_time_to_complete": "35",
             "books_supplies": "1000",
             "completion_rate": "13",
             "default_rate": "50",
             "job_placement_rate": "0.20",
             "job_placement_note": jpr_note,
             "mean_student_loan_completers": "30000",
             "median_student_loan_completers": "30500",
             "total_cost": "50000",
             "tuition_fees": "40000",
             "cip_code": "51.0803 - Test",
             "completers": "0",
             "completion_cohort": "0"}
        ]
        mock_clean.return_value = {
            "ipeds_unit_id": "408039",
            "ope_id": "",
            "campus_name": "Ft Wayne - Test",
            "program_code": "981 - Test",
            "program_name": program_name,
            "program_level": 4,
            "program_length": 25,
            "accreditor": accreditor,
            "median_salary": 24000,
            "average_time_to_complete": 35,
            "books_supplies": 1000,
            "completion_rate": 13,
            "default_rate": 50,
            "job_placement_rate": 0.20,
            "job_placement_note": jpr_note,
            "mean_student_loan_completers": 30000,
            "median_student_loan_completers": 30500,
            "total_cost": 50000,
            "tuition_fees": 40000,
            "cip_code": "51.0803 - Test",
            "completers": 0,
            "completion_cohort": 0}
        program = Program.objects.first()
        mock_get_or_create_program.return_value = (program, False)

        load("filename")
        self.assertEqual(mock_read_in.call_count, 1)
        self.assertEqual(mock_clean.call_count, 1)
        self.assertEqual(mock_get_or_create_program.call_count, 1)
        self.assertEqual(program.accreditor, accreditor)
        self.assertEqual(program.cip_code, "51.0803 - Test")
        self.assertEqual(program.completion_rate, 13.00)
        self.assertEqual(program.default_rate, 50.00)
        self.assertEqual(program.mean_student_loan_completers, 30000)
        self.assertEqual(program.median_student_loan_completers, 30500)
        self.assertEqual(program.program_code, "981 - Test")
        self.assertEqual(
            program.program_name,
            "Occupational Therapy Assistant - 981 - Test"
        )
        self.assertEqual(program.program_length, 25)
        self.assertEqual(program.total_cost, 50000)
        self.assertEqual(program.campus, "Ft Wayne - Test")
        self.assertEqual(program.level, 4)
        self.assertEqual(program.time_to_complete, 35)
        self.assertEqual(program.salary, 24000)
        self.assertEqual(program.job_rate, 0.20)
        self.assertEqual(program.job_note, jpr_note)
        self.assertEqual(program.tuition, 40000)
        self.assertEqual(program.books, 1000)
        self.assertEqual(program.completers, 0)
        self.assertEqual(program.completion_cohort, 0)
        mock_clean.return_value['ipeds_unit_id'] = '9'
        load('filename')
        self.assertEqual(mock_read_in.call_count, 2)
        self.assertEqual(mock_get_or_create_program.call_count, 1)
        mock_clean.return_value['program_code'] = '<904>'
        load('filename')
        self.assertEqual(mock_read_in.call_count, 3)
        self.assertEqual(
            mock_get_or_create_program.call_count,
            1)  # loader bails before creating program
        mock_clean.return_value['ipeds_unit_id'] = "408039"
        mock_clean.return_value['program_code'] = "99982"
        mock_get_or_create_program.return_value = (program, True)
        load('filename')
        self.assertEqual(mock_read_in.call_count, 4)
        mock_read_in.return_value[0]['test'] = "True"
        load('filename')
        self.assertEqual(mock_read_in.call_count, 5)
 def test_load_s3_failure(self, mock_read_in_s3):
     mock_read_in_s3.return_value = [{}]
     (FAILED, msg) = load('mockurl', s3=True)
     self.assertTrue(mock_read_in_s3.call_count == 1)
     self.assertTrue('ERROR' in FAILED[0])
 def test_load_s3(self, mock_read_in_s3):
     mock_read_in_s3.return_value = self.read_out
     (FAILED, msg) = load('mockurl', s3=True)
     self.assertTrue(mock_read_in_s3.call_count == 1)
     self.assertEqual(FAILED, [])
     self.assertIn('0 programs created', msg)
Exemplo n.º 7
0
    def test_load(self, mock_get_or_create_program, mock_clean, mock_read_in):
        accreditor = ("Accrediting Council for Independent Colleges "
                      "and Schools (ACICS) - Test")
        jpr_note = ("The rate reflects employment status "
                    "as of November 1, 2014 - Test")
        program_name = "Occupational Therapy Assistant - 981 - Test"
        mock_read_in.return_value = [
            {"ipeds_unit_id": "408039",
             "ope_id": "",
             "campus_name": "Ft Wayne - Test",
             "program_code": "981 - Test",
             "program_name": program_name,
             "program_level": "4",
             "program_length": "25",
             "accreditor": accreditor,
             "median_salary": "24000",
             "average_time_to_complete": "35",
             "books_supplies": "1000",
             "completion_rate": "13",
             "default_rate": "50",
             "job_placement_rate": "0.20",
             "job_placement_note": jpr_note,
             "mean_student_loan_completers": "30000",
             "median_student_loan_completers": "30500",
             "total_cost": "50000",
             "tuition_fees": "40000",
             "cip_code": "51.0803 - Test",
             "completers": "0",
             "completion_cohort": "0"}
        ]
        mock_clean.return_value = {"ipeds_unit_id": "408039",
                                   "ope_id": "",
                                   "campus_name": "Ft Wayne - Test",
                                   "program_code": "981 - Test",
                                   "program_name": program_name,
                                   "program_level": 4,
                                   "program_length": 25,
                                   "accreditor": accreditor,
                                   "median_salary": 24000,
                                   "average_time_to_complete": 35,
                                   "books_supplies": 1000,
                                   "completion_rate": 13,
                                   "default_rate": 50,
                                   "job_placement_rate": 0.20,
                                   "job_placement_note": jpr_note,
                                   "mean_student_loan_completers": 30000,
                                   "median_student_loan_completers": 30500,
                                   "total_cost": 50000,
                                   "tuition_fees": 40000,
                                   "cip_code": "51.0803 - Test",
                                   "completers": 0,
                                   "completion_cohort": 0}
        program = Program.objects.first()
        mock_get_or_create_program.return_value = (program, False)

        load("filename")
        self.assertEqual(mock_read_in.call_count, 1)
        self.assertEqual(mock_clean.call_count, 1)
        self.assertEqual(mock_get_or_create_program.call_count, 1)
        self.assertEqual(program.accreditor, accreditor)
        self.assertEqual(program.cip_code, "51.0803 - Test")
        self.assertEqual(program.completion_rate, 13.00)
        self.assertEqual(program.default_rate, 50.00)
        self.assertEqual(program.mean_student_loan_completers, 30000)
        self.assertEqual(program.median_student_loan_completers, 30500)
        self.assertEqual(program.program_code, "981 - Test")
        self.assertEqual(
            program.program_name,
            "Occupational Therapy Assistant - 981 - Test"
        )
        self.assertEqual(program.program_length, 25)
        self.assertEqual(program.total_cost, 50000)
        self.assertEqual(program.campus, "Ft Wayne - Test")
        self.assertEqual(program.level, 4)
        self.assertEqual(program.time_to_complete, 35)
        self.assertEqual(program.salary, 24000)
        self.assertEqual(program.job_rate, 0.20)
        self.assertEqual(program.job_note, jpr_note)
        self.assertEqual(program.tuition, 40000)
        self.assertEqual(program.books, 1000)
        self.assertEqual(program.completers, 0)
        self.assertEqual(program.completion_cohort, 0)
        mock_clean.return_value['ipeds_unit_id'] = '9'
        load('filename')
        self.assertEqual(mock_read_in.call_count, 2)
        self.assertEqual(mock_get_or_create_program.call_count, 1)
        mock_clean.return_value['program_code'] = '<904>'
        load('filename')
        self.assertEqual(mock_read_in.call_count, 3)
        self.assertEqual(
            mock_get_or_create_program.call_count,
            1)  # loader bails before creating program
        mock_clean.return_value['ipeds_unit_id'] = "408039"
        mock_clean.return_value['program_code'] = "99982"
        mock_get_or_create_program.return_value = (program, True)
        load('filename')
        self.assertEqual(mock_read_in.call_count, 4)
        mock_read_in.return_value[0]['test'] = "True"
        load('filename')
        self.assertEqual(mock_read_in.call_count, 5)
Exemplo n.º 8
0
 def test_load_s3_failure(self, mock_read_in_s3):
     mock_read_in_s3.return_value = [{}]
     (FAILED, msg) = load('mockurl', s3=True)
     self.assertTrue(mock_read_in_s3.call_count == 1)
     self.assertTrue('ERROR' in FAILED[0])
Exemplo n.º 9
0
 def test_load_s3(self, mock_read_in_s3):
     mock_read_in_s3.return_value = self.read_out
     (FAILED, msg) = load('mockurl', s3=True)
     self.assertTrue(mock_read_in_s3.call_count == 1)
     self.assertEqual(FAILED, [])
     self.assertIn('0 programs created', msg)