def test_update_colleges_not_OK(self, mock_requests): mock_response = mock.Mock() mock_response.ok = False mock_response.reason = "Testing OK == False" (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertTrue(len(FAILED) == 3) mock_requests.status_code = 429 (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertTrue(len(FAILED) == 3)
def test_update_colleges_single_school(self, mock_requests): mock_response = mock.Mock() mock_response.json.return_value = self.mock_dict mock_response.ok = True mock_requests.return_value = mock_response (FAILED, NODATA, endmsg) = update_colleges.update(single_school=243197) self.assertTrue(len(NODATA) == 0) self.assertTrue(len(FAILED) == 0) self.assertTrue('updated' in endmsg) (FAILED, N0DATA, endmsg) = update_colleges.update(exclude_ids=[999999]) self.assertTrue(len(NODATA) == 0) self.assertTrue(len(FAILED) == 0) self.assertTrue('updated' in endmsg)
def test_update_colleges(self, mock_requests): mock_response = mock.Mock() mock_response.json.return_value = self.mock_dict mock_response.ok = True mock_requests.return_value = mock_response (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertTrue(len(NO_DATA) == 0) self.assertTrue(len(FAILED) == 0) self.assertTrue('updated' in endmsg) mock_response.json.return_value = self.no_data_dict (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertFalse(len(NO_DATA) == 0) mock_response.json.return_value = self.mock_lt_4 (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertTrue(len(NO_DATA) == 0)
def test_update_colleges_not_OK(self, mock_requests): mock_response = mock.Mock() mock_response.ok = False mock_response.reason = "Testing OK == False" mock_response.status_code = 429 mock_requests.return_value = mock_response (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertTrue('limit' in endmsg) mock_response = mock.Mock() mock_response.ok = False mock_response.reason = "Testing OK == False" (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertFalse(len(FAILED) == 0) mock_requests.side_effect = requests.exceptions.ConnectTimeout (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertFalse(len(FAILED) == 0)
def test_update_colleges_bad_responses(self, mock_requests): mock_response = mock.Mock() mock_response.ok = True mock_response.json.return_value = {'results': []} (FAILED, NO_DATA, endmsg) = update_colleges.update() # print("after results==[], NO_DATA is %s" % FAILED) self.assertTrue('no data' in endmsg)
def test_store_programs(self, mock_get_data): api_data = {'latest.programs.cip_4_digit': [self.mock_program_data]} mock_get_data.return_value = api_data test_pk = 100636 program_count = Program.objects.count() (NO_DATA, endmsg) = update_colleges.update( single_school=test_pk, store_programs=True) self.assertEqual(Program.objects.count(), program_count + 1)
def test_update_colleges_single_not_operating(self, mock_get_data): altered_results = copy.copy(self.mock_results).get('results')[0] altered_results['school.operating'] = 0 mock_get_data.return_value = altered_results (NO_DATA, endmsg) = update_colleges.update( single_school=408039) self.assertTrue(len(NO_DATA) == 0) self.assertTrue('closed since last run: 1' in endmsg)
def handle(self, *args, **options): try: (no_data, endmsg) = update_colleges.update( single_school=options['school_id']) except(IndexError): self.stdout.write(ID_ERROR.format(options['school_id'])) else: self.stdout.write(endmsg)
def test_update_colleges(self, mock_requests): mock_response = mock.Mock() mock_response.json.return_value = self.mock_dict mock_response.ok = True mock_requests.return_value = mock_response (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertTrue(len(NO_DATA) == 0) self.assertTrue(len(FAILED) == 0) self.assertTrue('updated' in endmsg)
def handle(self, *args, **options): try: (failed, no_data, endmsg) = update_colleges.update(single_school=options['school_id']) except(IndexError): self.stdout.write(ID_ERROR.format(options['school_id'])) else: self.stdout.write(endmsg)
def test_update_colleges_no_data_single_school(self, mock_get_data): mock_get_data.return_value = None (NO_DATA, endmsg) = update_colleges.update( single_school=408039) self.assertEqual(len(NO_DATA), 1)
def test_update_colleges_success_community_college(self, mock_get_data): mock_get_data.return_value = self.mock_lt_4.get('results')[0] (NO_DATA, endmsg) = update_colleges.update( single_school=100636) self.assertTrue(len(NO_DATA) == 0) self.assertTrue('Updated' in endmsg)
def test_update_colleges_success(self, mock_get_data): mock_get_data.return_value = self.mock_results.get('results')[0] (NO_DATA, endmsg) = update_colleges.update() self.assertTrue(len(NO_DATA) == 0) self.assertTrue('Updated' in endmsg)
def test_update_colleges_bad_responses(self, mock_requests): mock_response = mock.Mock() mock_response.ok = True mock_response.json.return_value = {'results': []} (FAILED, NO_DATA, endmsg) = update_colleges.update() self.assertTrue('no data' in endmsg)
def test_update_colleges_community_colleges(self, mock_get_data): mock_get_data.return_value = self.mock_lt_4.get('results')[0] (NO_DATA, endmsg) = update_colleges.update() self.assertTrue(len(NO_DATA) == 0)
def test_single_school_failure(self): (flist, msg) = update_colleges.update(single_school=99999) self.assertIn("Could not find", msg)
def test_single_school_request(self, mock_get_data): mock_get_data.return_value = self.mock_results.get('results')[0] update_colleges.update(single_school=408039) self.assertEqual(mock_get_data.call_count, 1) self.assertTrue( mock_get_data.called_with(408039, api_utils.build_field_string()))