def setUp(self): self.preset = list(presets.keys())[0] call_command( "provisiondevice", facility="test", superusername="******", superuserpassword="******", preset=self.preset, language_id="en", )
def create_facility(facility_name=None, preset=None, interactive=False): if facility_name is None and interactive: answer = get_user_response( "Do you wish to create a facility? [y/n] ", ["y", "n"] ) if answer == "y": facility_name = get_user_response( "What do you wish to name your facility? ", to_lower_case=False ) else: sys.exit(1) if facility_name: facility_query = Facility.objects.filter(name__iexact=facility_name) if facility_query.exists(): facility = facility_query.get() logger.warn( "Facility with name '{name}' already exists, not modifying preset.".format( name=facility.name ) ) return facility else: facility = Facility.objects.create(name=facility_name) logger.info( "Facility with name '{name}' created.".format(name=facility.name) ) if preset is None and interactive: preset = get_user_response( "Which preset do you wish to use? [{presets}]: ".format( presets="/".join(presets.keys()) ), valid_answers=presets, ) # Only set preset data if we have created the facility, otherwise leave previous data intact if preset: dataset_data = mappings[preset] facility.dataset.preset = preset for key, value in dataset_data.items(): check_facility_setting(key) setattr(facility.dataset, key, value) facility.dataset.save() logger.info("Facility preset changed to {preset}.".format(preset=preset)) else: facility = Facility.get_default_facility() or Facility.objects.first() if not facility: raise CommandError("No facility exists") return facility
def test_create_facility_set_preset(self): preset = list(presets.keys())[0] facility = create_facility(facility_name="test", preset=preset) dataset_data = mappings[preset] for key, value in dataset_data.items(): self.assertEqual(getattr(facility.dataset, key), value)