Пример #1
0
    def test_make_request(self, mock_request):
        mock_response = Response()
        mock_response._content = str.encode(json.dumps({'test': 'test'}))
        mock_response.status_code = 200
        mock_request.return_value = mock_response

        self.assertDictEqual({'test': 'test'}, make_request('GET', 'google.com', headers={'test': 'test'}).json())

        mock_response.status_code = 403
        mock_request.return_value = mock_response
        with self.assertRaises(ImproperCredentialsException):
            make_request('GET', 'google.com', headers={'test': 'test'})
Пример #2
0
 def submit_observation(self, observation_payload):
     observation_payload = self.add_calibrations(observation_payload)
     response = make_request('POST',
                             PORTAL_URL + '/api/requestgroups/',
                             json=observation_payload,
                             headers=self._portal_headers())
     return [r['id'] for r in response.json()['requests']]
Пример #3
0
 def validate_observation(self, observation_payload):
     observation_payload = self.add_calibrations(observation_payload)
     response = make_request('POST',
                             PORTAL_URL + '/api/requestgroups/validate/',
                             json=observation_payload,
                             headers=self._portal_headers())
     return response.json()['errors']
Пример #4
0
 def validate_observation(self, observation_payload):
     response = make_request('POST',
                             PORTAL_URL + '/api/requestgroups/validate/',
                             json=observation_payload,
                             headers=self._portal_headers())
     print('Validating observation')
     return response.json()['errors']
Пример #5
0
 def submit_observation(self, observation_payload):
     response = make_request(
         'POST',
         #PORTAL_URL + '/api/requestgroups/validate/',
         PORTAL_URL + '/api/requestgroups/',
         json=observation_payload,
         headers=self._portal_headers())
     print('Made request')
     return [r['id'] for r in response.json()['requests']]
Пример #6
0
 def get_extra_context(self):
     """
     Provide extra context to the view using this form.
     """
     json_response = make_request('GET',
                                  PORTAL_URL + '/api/instruments/').json()
     info = EducationLCOForm.get_schedulable_codes(json_response)
     return {
         'instrument_filters': json.dumps(info),
         'filter_fields': self.filter_fields
     }