def create_shelf_list(self): """Convenience function to create extra shelves to test listing.""" self.shelf2 = shelf_model.Shelf(enabled=True, location='US-NYC2', capacity=20).put().get() self.shelf3 = shelf_model.Shelf(enabled=False, location='US-NYC3', capacity=30).put().get() self.shelf4 = shelf_model.Shelf(enabled=False, location='US-NYC4', capacity=40).put().get()
def setUp(self): super(ApiUtilsTest, self).setUp() self.test_shelf_model = shelf_model.Shelf( enabled=True, friendly_name='test_friendly_name', location='test_location', lat_long=ndb.GeoPt(10.10, 20.20), altitude=1.1, capacity=10, audit_interval_override=12, audit_notification_enabled=False, audit_requested=True, responsible_for_audit='test_group', last_audit_time=datetime.datetime(year=2018, month=1, day=1), last_audit_by='test_auditer').put().get() self.expected_shelf_message = shelf_messages.Shelf( shelf_request=shelf_messages.ShelfRequest( location='test_location', urlsafe_key=self.test_shelf_model.key.urlsafe()), enabled=True, friendly_name='test_friendly_name', location='test_location', identifier='test_friendly_name', latitude=10.10, longitude=20.20, altitude=1.1, capacity=10, audit_notification_enabled=False, audit_requested=True, responsible_for_audit='test_group', last_audit_time=datetime.datetime(year=2018, month=1, day=1), last_audit_by='test_auditer')
def setUp(self): super(BigQueryRowModelTest, self).setUp() self.test_shelf = shelf_model.Shelf(friendly_name='Test', location='Here', capacity=16) self.test_shelf.put() self.test_device = device_model.Device( serial_number='VOID', enrolled=False, device_model='HP Chromebook 13 G1', current_ou='/', shelf=self.test_shelf.key, chrome_device_id='unique_id_8', damaged=False) self.test_device.put() self.test_row_1 = bigquery_row_model.BigQueryRow.add( self.test_shelf, datetime.datetime.utcnow(), 'test@{}'.format(loanertest.USER_DOMAIN), 'test', 'This is a test') self.test_row_2 = bigquery_row_model.BigQueryRow.add( self.test_device, datetime.datetime.utcnow(), 'test@{}'.format(loanertest.USER_DOMAIN), 'test', 'This is a test') mock_bigquery = mock.patch.object(bigquery_row_model, 'bigquery', autospec=True) self.addCleanup(mock_bigquery.stop) self.mock_bigquery = mock_bigquery.start() self.mock_bigquery_client = mock.Mock() self.mock_bigquery.BigQueryClient.return_value = self.mock_bigquery_client
def test_stream_to_bq(self, mock_taskqueue): test_shelf = shelf_model.Shelf(location='Here', capacity=16) test_shelf.put() test_shelf.stream_to_bq('test@{}'.format(loanertest.USER_DOMAIN), 'Test stream') self.assertTrue(mock_taskqueue.add.called)
def setUp(self): super(ShelfModelTest, self).setUp() self.original_location = 'US-NYC' self.original_friendly_name = 'NYC office' self.original_capacity = 18 self.test_shelf = shelf_model.Shelf( enabled=True, friendly_name=self.original_friendly_name, location=self.original_location, capacity=self.original_capacity, audit_notification_enabled=True).put().get()
def setUp(self): super(BigQueryRowModelTest, self).setUp() test_shelf = shelf_model.Shelf( friendly_name='Test', location='Here', capacity=16) test_shelf.put() self.test_shelf = test_shelf mock_bigquery = mock.patch('__main__.bigquery_row_model.bigquery_client') self.addCleanup(mock_bigquery.stop) self.mock_bigquery = mock_bigquery.start() self.mock_bigquery_client = mock.Mock() self.mock_bigquery.BigQueryClient.return_value = self.mock_bigquery_client
def test_raise_event(self, mock_geteventactions, mock_taskqueueadd, mock_loginfo): """Tests raising an Action if the Event is configured for Actions.""" self.testbed.raise_event_patcher.stop( ) # Disable patcher; use real method. # No Actions configured for the Event. mock_geteventactions.return_value = [] events.raise_event('sample_event') mock_loginfo.assert_called_with(events._NO_ACTIONS_MSG, 'sample_event') mock_geteventactions.return_value = ['action1', 'action2'] test_device = device_model.Device(chrome_device_id='4815162342', serial_number='123456') test_shelf = shelf_model.Shelf(capacity=42, location='Helpdesk 123') expected_payload1 = pickle.dumps({ 'action_name': 'action1', 'device': test_device, 'shelf': test_shelf }) expected_payload2 = pickle.dumps({ 'action_name': 'action2', 'device': test_device, 'shelf': test_shelf }) events.raise_event('sample_event', device=test_device, shelf=test_shelf) self.testbed.raise_event_patcher.start( ) # Because cleanup will stop(). expected_calls = [ mock.call(queue_name='process-action', payload=expected_payload1, target='default'), mock.call(queue_name='process-action', payload=expected_payload2, target='default') ] mock_taskqueueadd.assert_has_calls(expected_calls)
def initialize_tables(self): """Performs first-time setup by creating dataset/tables.""" if constants.ON_LOCAL: logging.debug('On local, not connecting to BQ.') return logging.info('Beginning BigQuery initialization.') try: self._dataset.create() except cloud.exceptions.Conflict: logging.warning( 'Dataset %s already exists, not creating.', self._dataset.name) else: logging.info('Dataset %s successfully created.', self._dataset.name) self._create_table(constants.BIGQUERY_DEVICE_TABLE, device_model.Device()) self._create_table(constants.BIGQUERY_SHELF_TABLE, shelf_model.Shelf()) self._create_table( constants.BIGQUERY_SURVEY_TABLE, survey_models.Question()) logging.info('BigQuery successfully initialized.')