Ejemplo n.º 1
0
 def test_throws_when_response_is_malformed(self, m: Mocker):
     mangled_response = json.loads(RESPONSE_TRIGGER_LIST)
     mangled_response['data'] = 'lolwut'
     m.post('/trigger/query', json=mangled_response)
     with self.assertRaisesRegex(piazza.InvalidResponse,
                                 '`data` is of the wrong type'):
         piazza.get_triggers('test-name')
Ejemplo n.º 2
0
 def test_sends_correct_payload(self, m: Mocker):
     m.post('/trigger/query', text=RESPONSE_TRIGGER_LIST)
     piazza.get_triggers('test-name')
     self.assertEqual({
         'query': {
             'match': {
                 'name': 'test-name',
             },
         },
     }, m.request_history[0].json())
Ejemplo n.º 3
0
 def test_throws_when_credentials_are_rejected(self, m: Mocker):
     m.post('/trigger/query', text=RESPONSE_TRIGGER_LIST, status_code=401)
     with self.assertRaises(piazza.Unauthorized):
         piazza.get_triggers('test-name')
Ejemplo n.º 4
0
 def test_throws_when_piazza_is_unreachable(self, _):
     with unittest.mock.patch('requests.post') as mock:
         mock.side_effect = piazza.Unreachable()
         with self.assertRaises(piazza.Unreachable):
             piazza.get_triggers('test-name')
Ejemplo n.º 5
0
 def test_throws_when_data_is_missing(self, m: Mocker):
     mangled_response = json.loads(RESPONSE_TRIGGER_LIST)
     mangled_response.pop('data')
     m.post('/trigger/query', json=mangled_response)
     with self.assertRaisesRegex(piazza.InvalidResponse, 'missing `data`'):
         piazza.get_triggers('test-name')
Ejemplo n.º 6
0
 def test_gracefully_handles_errors(self, m: Mocker):
     m.post('/trigger/query', text=RESPONSE_ERROR_GENERIC, status_code=500)
     with self.assertRaises(piazza.ServerError):
         piazza.get_triggers('test-name')
Ejemplo n.º 7
0
 def test_returns_a_list_of_triggers(self, m: Mocker):
     m.post('/trigger/query', text=RESPONSE_TRIGGER_LIST)
     triggers = piazza.get_triggers('test-name')
     self.assertIsInstance(triggers, list)
     self.assertEqual(['test-trigger-id-1', 'test-trigger-id-2'],
                      list(map(lambda d: d['triggerId'], triggers)))
Ejemplo n.º 8
0
 def test_calls_correct_url(self, m: Mocker):
     m.post('/trigger/query', text=RESPONSE_TRIGGER_LIST)
     piazza.get_triggers('test-name')
     self.assertEqual('https://test-piazza-host.localdomain/trigger/query',
                      m.request_history[0].url)