Beispiel #1
0
    def test_yaml_import_with_wipe(self, mock_directoryclass):
        """Tests YAML importing with a datastore wipe."""
        mock_directoryclient = mock_directoryclass.return_value
        mock_directoryclient.get_chrome_device_by_serial.return_value = (
            loanertest.TEST_DIR_DEVICE1)
        mock_directoryclient.move_chrome_device_org_unit.return_value = (
            loanertest.TEST_DIR_DEVICE_DEFAULT)
        test_device = device_model.Device.enroll(
            serial_number='0987654321', user_email=loanertest.USER_EMAIL)
        test_shelf = shelf_model.Shelf.enroll(
            user_email='test@{}'.format(loanertest.USER_DOMAIN),
            location='Somewhere',
            capacity=42,
            friendly_name='Nice shelf',
            responsible_for_audit='inventory')
        user_model.User(id=loanertest.USER_EMAIL).put()
        template_model.Template.create('template_1')
        template_model.Template.create('template_2')
        test_event = event_models.CoreEvent.create('test_event')
        test_event.description = 'A test event'
        test_event.enabled = True
        test_event.actions = ['some_action', 'another_action']
        test_event.put()
        event_models.CustomEvent.create('test_custom_event')

        datastore_yaml.import_yaml(ALL_YAML, loanertest.USER_EMAIL, wipe=True)

        # Datastore wiped, new devices/shelves from YAML.
        devices = device_model.Device.query().fetch()
        shelves = shelf_model.Shelf.query().fetch()
        core_events = event_models.CoreEvent.query().fetch()
        shelf_audit_events = event_models.ShelfAuditEvent.query().fetch()
        custom_events = event_models.CustomEvent.query().fetch()
        reminder_events = event_models.ReminderEvent.query().fetch()
        survey_questions = survey_models.Question.query().fetch()
        templates = template_model.Template.query().fetch()
        users = user_model.User.query().fetch()

        self.assertLen(shelves, 2)
        self.assertLen(devices, 2)
        self.assertLen(core_events, 1)
        self.assertLen(shelf_audit_events, 1)
        self.assertLen(custom_events, 1)
        self.assertLen(reminder_events, 1)
        self.assertLen(survey_questions, 1)
        self.assertLen(templates, 1)
        self.assertLen(users, 2)

        self.assertNotIn(test_device.serial_number,
                         [device.serial_number for device in devices])
        self.assertNotIn(test_shelf.location,
                         [shelf.location for shelf in shelves])
        self.assertNotIn(test_event.name,
                         [event.name for event in core_events])
        self.assertIsInstance(custom_events[0].conditions[0].value,
                              datetime.timedelta)
Beispiel #2
0
def bootstrap_datastore_yaml(wipe=True, **kwargs):
    """Bootstraps arbitrary datastore entities from supplied YAML input.

  Args:
    wipe: bool, whether to wipe all existing datastore models for any model
        contained in the YAML.
    **kwargs: keyword args including a user_email with which to run the
        datastore methods (required for BigQuery streaming).
  """
    with open(os.path.join(os.path.dirname(__file__),
                           'bootstrap.yaml')) as yaml_file:
        datastore_yaml.import_yaml(yaml_file.read(), kwargs['user_email'],
                                   wipe)
Beispiel #3
0
 def test_yaml_import_with_randomized_shelves(self, mock_directoryclass):
     """Tests YAML importing with devices randomly assigned to shelves."""
     mock_directoryclient = mock_directoryclass.return_value
     mock_directoryclient.get_chrome_device_by_serial.side_effect = [
         loanertest.TEST_DIR_DEVICE1, loanertest.TEST_DIR_DEVICE2
     ]
     mock_directoryclient.move_chrome_device_org_unit.side_effect = [
         loanertest.TEST_DIR_DEVICE_DEFAULT, loanertest.TEST_DIR_DEVICE2
     ]
     datastore_yaml.import_yaml(SHELF_YAML + DEVICE_YAML,
                                loanertest.USER_EMAIL,
                                randomize_shelving=True)
     devices = device_model.Device.query().fetch()
     shelves = shelf_model.Shelf.query().fetch()
     self.assertLen(devices, 2)
     self.assertLen(shelves, 2)
     for device in devices:
         self.assertIn(device.shelf, [shelf.key for shelf in shelves])
Beispiel #4
0
 def test_yaml_import(self, mock_directoryclass):
     """Tests basic YAML importing."""
     mock_directoryclient = mock_directoryclass.return_value
     mock_directoryclient.get_chrome_device_by_serial.side_effect = [
         loanertest.TEST_DIR_DEVICE1, loanertest.TEST_DIR_DEVICE2
     ]
     mock_directoryclient.move_chrome_device_org_unit.side_effect = [
         loanertest.TEST_DIR_DEVICE_DEFAULT, loanertest.TEST_DIR_DEVICE2
     ]
     datastore_yaml.import_yaml(ALL_YAML, loanertest.USER_EMAIL)
     self.assertLen(shelf_model.Shelf.query().fetch(), 2)
     self.assertLen(device_model.Device.query().fetch(), 2)
     self.assertLen(event_models.CoreEvent.query().fetch(), 1)
     self.assertLen(event_models.ShelfAuditEvent.query().fetch(), 1)
     self.assertLen(event_models.CustomEvent.query().fetch(), 1)
     self.assertLen(event_models.ReminderEvent.query().fetch(), 1)
     self.assertLen(survey_models.Question.query().fetch(), 1)
     self.assertLen(template_model.Template.query().fetch(), 1)
     self.assertLen(user_model.User.query().fetch(), 2)
Beispiel #5
0
 def datastore_import(self, request):
     """Datastore import request for the Datastore API."""
     self.check_xsrf_token(self.request_state)
     datastore_yaml.import_yaml(request.yaml, wipe=False)
     return message_types.VoidMessage()