def test_batchjobstatus_methods(self): """context.BatchJobStatus methods""" from cartoframes.context import BatchJobStatus from carto.sql import BatchSQLClient cc = cartoframes.CartoContext(base_url=self.baseurl, api_key=self.apikey) batch_client = BatchSQLClient(cc.auth_client) job_response = batch_client.create([ 'select 1', ]) job_status = BatchJobStatus(cc, job_response) possible_status = ( 'pending', 'running', 'done', 'canceled', 'unknown', ) self.assertTrue(job_status.get_status() in possible_status) job_status._set_status('foo') self.assertEqual(job_status.get_status(), 'foo') new_status = job_status.status() self.assertSetEqual(set(new_status.keys()), {'status', 'updated_at', 'created_at'}) # job_id as str str_bjs = BatchJobStatus(cc, 'foo') self.assertIsNone(str_bjs.get_status()) self.assertEqual(str_bjs.job_id, 'foo')
def test_batchjobstatus_repr(self): """context.BatchJobStatus.__repr__""" from cartoframes.context import BatchJobStatus cc = cartoframes.CartoContext(base_url=self.baseurl, api_key=self.apikey) bjs = BatchJobStatus( cc, dict(job_id='foo', status='unknown', created_at=None)) self.assertMultiLineEqual(bjs.__repr__(), ("BatchJobStatus(job_id='foo', " "last_status='unknown', " "created_at='None')"))
def test_batchjobstatus(self): """context.BatchJobStatus""" from cartoframes.context import BatchJobStatus, MAX_ROWS_LNGLAT cc = cartoframes.CartoContext(base_url=self.baseurl, api_key=self.apikey) n_vals = MAX_ROWS_LNGLAT + 1 df = pd.DataFrame({ 'lngvals': [random.random() for r in range(n_vals)], 'latvals': [random.random() for r in range(n_vals)] }) job = cc.write(df, self.test_write_lnglat_table, lnglat=('lngvals', 'latvals')) self.assertIsInstance(job, cartoframes.context.BatchJobStatus) # no job exists for job_id 'foo' bjs = BatchJobStatus(cc, dict(job_id='foo', status='unknown')) with self.assertRaises(CartoException): bjs.status()