def test_throws_when_piazza_is_unreachable(self, _): with unittest.mock.patch('requests.post') as stub: stub.side_effect = ConnectionError(request=unittest.mock.Mock()) with self.assertRaises(piazza.Unreachable): piazza.deploy(data_id='test-data-id', poll_interval=0, max_poll_attempts=2)
def test_handles_http_errors_gracefully_during_polling(self, m: Mocker): m.post('/deployment', text=RESPONSE_JOB_CREATED, status_code=201) m.get('/job/test-job-id', text=RESPONSE_ERROR_GENERIC, status_code=500) with self.assertRaises(piazza.ServerError): piazza.deploy(data_id='test-data-id', poll_interval=0, max_poll_attempts=2)
def test_throws_when_deployment_fails(self, m: Mocker): m.post('/deployment', text=RESPONSE_JOB_CREATED, status_code=201) m.get('/job/test-job-id', [ { 'text': RESPONSE_JOB_RUNNING }, { 'text': RESPONSE_JOB_ERROR }, ]) with self.assertRaisesRegex(piazza.DeploymentError, 'job failed'): piazza.deploy(data_id='test-data-id', poll_interval=0, max_poll_attempts=2)
def test_honors_polling_interval(self, m: Mocker): m.post('/deployment', text=RESPONSE_JOB_CREATED, status_code=201) m.get('/job/test-job-id', [ { 'text': RESPONSE_JOB_RUNNING }, { 'text': RESPONSE_DEPLOY_SUCCESS }, ]) with unittest.mock.patch('time.sleep') as stub: piazza.deploy(data_id='test-data-id', poll_interval=-12345, max_poll_attempts=2) self.assertEqual([(-12345, )], stub.call_args)
def test_calls_correct_urls(self, m: Mocker): m.post('/deployment', text=RESPONSE_JOB_CREATED, status_code=201) m.get('/job/test-job-id', [ { 'text': RESPONSE_JOB_RUNNING }, { 'text': RESPONSE_DEPLOY_SUCCESS }, ]) piazza.deploy(data_id='test-data-id', poll_interval=0, max_poll_attempts=2) self.assertEqual('https://test-piazza-host.localdomain/deployment', m.request_history[0].url) self.assertEqual( 'https://test-piazza-host.localdomain/job/test-job-id', m.request_history[1].url)
def test_sends_correct_payload(self, m: Mocker): m.post('/deployment', text=RESPONSE_JOB_CREATED, status_code=201) m.get('/job/test-job-id', [ { 'text': RESPONSE_JOB_RUNNING }, { 'text': RESPONSE_DEPLOY_SUCCESS }, ]) piazza.deploy(data_id='test-data-id', poll_interval=0, max_poll_attempts=2) self.assertEqual( { 'dataId': 'test-data-id', 'deploymentType': 'geoserver', 'type': 'access' }, m.request_history[0].json())
def test_returns_layer_id(self, m: Mocker): m.post('/deployment', text=RESPONSE_JOB_CREATED, status_code=201) m.get('/job/test-job-id', [ { 'text': RESPONSE_JOB_RUNNING }, { 'text': RESPONSE_DEPLOY_SUCCESS }, ]) layer_id = piazza.deploy(data_id='test-data-id', poll_interval=0, max_poll_attempts=2) self.assertEqual('test-layer-id', layer_id)
def test_throws_when_credentials_are_rejected(self, m: Mocker): m.post('/deployment', text=RESPONSE_ERROR_GENERIC, status_code=401) with self.assertRaises(piazza.Unauthorized): piazza.deploy(data_id='test-data-id', poll_interval=0, max_poll_attempts=2)