def test_overrides_defaults_with_given_arguments(self): arguments = self._arguments_from( db_host="test-db-server", registry_port=1290) settings = Settings.from_arguments(arguments) self.assertEqual(len(DeepDiff(Settings.defaults(), settings)["values_changed"]), 2)
def test_uses_config_file_when_it_exists(self): arguments = self._arguments_from( configuration_file="config/storage.yml") settings = Settings.from_arguments(arguments) with open("config/storage.yml") as source: expected = Settings.fromYAML(source) self.assertEqual(DeepDiff(expected, settings), {})
def test_overrides_config_file_with_given_arguments(self): arguments = self._arguments_from( configuration_file="config/storage.yml", db_host="test-db-server", registry_port=1290) settings = Settings.from_arguments(arguments) with open("config/storage.yml") as source: expected = Settings.fromYAML(source) self.assertEqual(len(DeepDiff(expected, settings)["values_changed"]), 2)
def test_uses_defaults_when_log_configuration_is_missing(self): snippet = ("partners:\n" " message_queue:\n" " domain: sensapp.org\n" " host: message-queue\n" " port: 8990\n") settings = Settings.fromYAML(StringIO(snippet)) self.assertEqual(Settings.DEFAULT_LOG_CONFIGURATION, settings.log_configuration)
def main(): arguments = Arguments.from_command_line(argv[1:]) settings = Settings.from_arguments(arguments) storage = Storage(settings, UI(stdout), QueueFactories.rabbitMQ, DataStoreFactories.influxDB, Registry) storage.start(arguments.command)
def test_uses_defaults_when_all_partners_are_missing(self): snippet = ("log_configuration: bidon.yaml\n" # Missing database! ) settings = Settings.fromYAML(StringIO(snippet)) self.assertEqual(PartnerSet.DEFAULT_DATABASE.domain, settings.partners.database.domain) self.assertEqual(PartnerSet.DEFAULT_DATABASE.hostname, settings.partners.database.hostname) self.assertEqual(PartnerSet.DEFAULT_DATABASE.port, settings.partners.database.port)
def setUp(self): self._settings = Settings.defaults() self._ui = MagicMock(UI) self._queue_factory = FakeQueueFactory() self._db_factory = FakeDBFactory() self._registry = MagicMock() self._storage = Storage(settings=self._settings, ui=self._ui, queue=self._queue_factory, db=self._db_factory, registry=lambda *args, **kwargs: self._registry) self._consumer = None
def test_uses_defaults_when_one_partner_is_missing(self): snippet = ("log_configuration: bidon.yaml\n" "partners:\n" " message_queue:\n" " domain: sensapp.org\n" " host: message-queue\n" " port: 8990\n" " registry:\n" " domain: sensapp.org\n" " host: registry\n" # Missing database! ) settings = Settings.fromYAML(StringIO(snippet)) self.assertEqual(PartnerSet.DEFAULT_DATABASE.domain, settings.partners.database.domain) self.assertEqual(PartnerSet.DEFAULT_DATABASE.hostname, settings.partners.database.hostname) self.assertEqual(PartnerSet.DEFAULT_DATABASE.port, settings.partners.database.port)
def test_uses_defaults_when_endpoints_lacks_domain(self): snippet = ("log_configuration: bidon.yaml\n" "partners:\n" " message_queue:\n" " domain: sensapp.org\n" " host: message-queue\n" " port: 8990\n" " registry:\n" " domain: sensapp.org\n" " host: registry\n" " database:\n" # Missing domain! " host: storage-db\n" " port: 12034\n") settings = Settings.fromYAML(StringIO(snippet)) self.assertEqual(PartnerSet.DEFAULT_DATABASE.domain, settings.partners.database.domain) self.assertEqual(12034, settings.partners.database.port)
def setUp(self): self.domain = "sensapp.org" fragment = ("partners: \n" " message_queue:\n" " domain: {domain}\n" " host: message-queue\n" " port: 8990\n" " resource: SENSAPP_QUEUE\n" " registry:\n" " domain: {domain}\n" " host: registry\n" " port: 3303\n" " database:\n" " domain: {domain}\n" " host: storage-db\n" " port: 1234\n" " resource: SENSAPP\n" "log_configuration: config/logging.yml\n") self.settings = Settings.fromYAML(StringIO(fragment.format(domain=self.domain)))
def test_uses_defaults_when_endpoints_lacks_resource(self): snippet = ("log_configuration: bidon.yaml\n" "partners:\n" " message_queue:\n" " domain: sensapp.org\n" " host: message-queue\n" " port: 8990\n" # Missing resource " registry:\n" " domain: sensapp.org\n" " host: test-registry\n" " database:\n" " domain: sensapp.org\n" " host: storage-db\n" " port: 1234\n") settings = Settings.fromYAML(StringIO(snippet)) self.assertEqual(PartnerSet.DEFAULT_MESSAGE_QUEUE.resource, settings.partners.message_queue.resource) self.assertEqual("message-queue", settings.partners.message_queue.hostname)
def test_uses_defaults_when_endpoints_lacks_port(self): snippet = ("log_configuration: bidon.yaml\n" "partners:\n" " message_queue:\n" " domain: sensapp.org\n" " host: message-queue\n" " port: 8990\n" " registry:\n" " domain: sensapp.org\n" " host: test-registry\n" # Missing port " database:\n" " domain: sensapp.org\n" " host: storage-db\n" " port: 1234\n") settings = Settings.fromYAML(StringIO(snippet)) self.assertEqual(PartnerSet.DEFAULT_REGISTRY.port, settings.partners.registry.port) self.assertEqual("test-registry", settings.partners.registry.hostname)
def test_uses_defaults_when_endpoints_lacks_hostname(self): snippet = ("log_configuration: bidon.yaml\n" "partners:\n" " message_queue:\n" " domain: sensapp.org\n" # Missing hostname here! " port: 67183\n" " registry:\n" " domain: sensapp.org\n" " host: registry\n" " port: 3303\n" " database:\n" " domain: sensapp.org\n" " host: storage-db\n" " port: 1234\n") settings = Settings.fromYAML(StringIO(snippet)) self.assertEqual(PartnerSet.DEFAULT_MESSAGE_QUEUE.hostname, settings.partners.message_queue.hostname) self.assertEqual(67183, settings.partners.message_queue.port)
def test_uses_defaults_when_config_file_does_not_exist(self): arguments = self._arguments_from( configuration_file="does_not_exists.yml") settings = Settings.from_arguments(arguments) self.assertEqual(DeepDiff(Settings.defaults(), settings), {})
def test_uses_defaults_when_no_argument_is_given(self): arguments = self._arguments_from() settings = Settings.from_arguments(arguments) self.assertEqual(DeepDiff(Settings.defaults(), settings), {})
def setUp(self): self.settings = Settings.defaults()