def test_clean_ID_Contains_Invalid_Names(self): model = OitsParams() model.parameters = self.get_altered_params('ID', [ "3", "INTERMEDIATE POINT", "3", "5", "INTERMEDIATE POINT", "Not a correct name" ]) self.assertRaises(ValidationError, model.clean)
def test_clean_validates_all_examples(self): model = OitsParams() for example in example_list: model.parameters = example['value'] try: model.clean() except: self.fail("clean() raised ExceptionType unexpectedly! for {0}". format(example['name']))
def test_mission_api_list(self): model = OitsParams() model.description = 'description' model.parameters = esa_mission model.save() client = APIClient() response = client.get('/api/mission/', format='json') self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertTrue(len(data) > 0)
def test_mission_api_cancel_mission_readonly(self): model = OitsParams() model.description = 'description' model.parameters = esa_mission model.status = 'N' model.readonly = True model.save() client = Client() response = client.post('/api/mission/{0}/cancel/'.format(model.id), format='json') self.assertEqual(response.status_code, 400)
def test_mission_api_retrieve(self): model = OitsParams() model.description = 'description' model.parameters = esa_mission model.save() client = APIClient() url = '/api/mission/{0}/'.format(model.id) response = client.get(url, format='json') self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(model.id, data['id'])
def test_mission_api_delete(self): model = OitsParams() model.description = 'description' model.parameters = esa_mission model.save() client = APIClient() response = client.delete('/api/mission/{0}/'.format(model.id), format='json') self.assertEqual(response.status_code, 200) count = OitsParams.objects.filter(id=model.id).count() self.assertEqual(0, count)
def test_get_results_values(self): oitsParams = OitsParams() oitsParams.uid = test_guid oitsParams.parameters = esa_mission oitsParams.save() result = TrajectoryResult(oits_params=oitsParams) result.values = 'PROBE\n7.0739567e+08,-0.32819958,-0.95950251,4.9871959e-05' result.save() client = Client() response = client.get('/results/{0}/values/'.format(oitsParams.id)) self.assertEqual(response.status_code, 200) self.assertTrue( b'PROBE\n7.0739567e+08,-0.32819958,-0.95950251,4.9871959e-05' in response.content)
def test_mission_api_cancel_mission(self): model = OitsParams() model.description = 'description' model.parameters = esa_mission model.status = 'P' model.readonly = False model.save() client = Client() response = client.post('/api/mission/{0}/cancel/'.format(model.id), format='json') self.assertEqual(response.status_code, 200) json.loads(response.content) new_model = OitsParams.objects.get(pk=model.id) self.assertEqual('A', new_model.status)
def create(self, request): ''' Creates a new mission record ''' try: received_json_data = json.loads(request.body) model = OitsParams() model.description = received_json_data['description'] model.parameters = request.body.decode('utf-8') model.clean() model.save() serializer = OitsParamsSerializer(model) return Response(serializer.data) except Exception as e: raise ValidationError(str(e))
def test_populate_values_from_output_file(self): oitsParams = OitsParams() oitsParams.uid = test_guid oitsParams.parameters = esa_mission oitsParams.save() result = TrajectoryResult(oits_params=oitsParams) result.populate_values_from_output_file() self.assertTrue( 'PROBE\n7.0739567e+08,-0.32819958,-0.95950251,4.9871959e-05' in result.values) #self.assertFalse(os.path.isfile(self.destination_file_path)) client = Client() response = client.get('/results/{0}/values/'.format(oitsParams.id)) self.assertEqual(response.status_code, 200) self.assertTrue( b'PROBE\n7.0739567e+08,-0.32819958,-0.95950251,4.9871959e-05' in response.content)
def test_clean_t0_invalid_length(self): model = OitsParams() model.parameters = self.get_altered_params('t0', [1.0, 2.0]) self.assertRaises(ValidationError, model.clean)
def test_clean_t01(self): model = OitsParams() model.parameters = self.get_altered_params('t01', "21/01/2018") self.assertRaises(ValidationError, model.clean)
def test_clean_thilb(self): model = OitsParams() model.parameters = self.get_altered_params('thilb', ["not a float"]) self.assertRaises(ValidationError, model.clean)
def test_clean_rip(self): model = OitsParams() model.parameters = self.get_altered_params('rIP', -1) self.assertRaises(ValidationError, model.clean)
def test_clean_ID_Invalid_Length(self): model = OitsParams() model.parameters = self.get_altered_params('ID', ['1']) self.assertRaises(ValidationError, model.clean)
def test_clean_Nbody_Too_Large(self): model = OitsParams() model.parameters = self.get_altered_params('Nbody', 10) self.assertRaises(ValidationError, model.clean)
def test_clean_ID_Contains_Consecutive_Intermediate_Points(self): model = OitsParams() model.parameters = self.get_altered_params( 'ID', ["3", "INTERMEDIATE POINT", "INTERMEDIATE POINT", "5", "3", "9"]) self.assertRaises(ValidationError, model.clean)
def test_clean_trajectory_optimization(self): model = OitsParams() model.parameters = self.get_altered_params('trajectory_optimization', 'blah') self.assertRaises(ValidationError, model.clean)