Example #1
0
    def test_inject_via_attribute(self):
        di_container.load_resources([__package__])

        injected = InjectedViaAttribute()

        di_container.inject_resources(injected)

        self.assertIsInstance(injected._dependency, Dependency)
Example #2
0
    def test_internal_dependency_injection(self):
        di_container.load_resources([__package__])

        injected = Injected()

        di_container.inject_resources(injected)

        self.assertIsInstance(injected._dependency, Dependency)
Example #3
0
    def test_run_before_injection(self):
        di_container.load_resources([__package__])

        injected = InjectedWithCodeRunningBeforeInjection()

        di_container.inject_resources(injected)

        self.assertTrue(injected._before_injection_ran)
Example #4
0
    def test_inject_into_factory_for_external_dependencies(self):
        di_container.load_resources([__package__])

        injected = InjectedWithExternalTransient()

        di_container.inject_resources(injected)

        self.assertTrue(injected._was_set)
Example #5
0
    def test_external_dependency_injection(self):
        di_container.load_resources([__package__])

        injected = InjectedExternal()

        di_container.inject_resources(injected)

        self.assertEqual(injected._external_dependency,
                         'external dependency instance')
Example #6
0
    def test_transient_dependency_injection(self):
        di_container.load_resources([__package__])

        injected = InjectedTransient()

        di_container.inject_resources(injected)

        self.assertIsInstance(
            injected._dependency_with_transient._transient_dependency,
            TransientDependency)
Example #7
0
    def test_should_trow_exception_when_unexisting_dependency_is_found(self):
        di_container.load_resources([__package__])

        injected = InjectNotExistingDependency()

        with self.assertRaises(Exception) as context:
            di_container.inject_resources(injected)

        self.assertIsInstance(context.exception, Exception)
        self.assertEqual(
            'Dependency not found: "dependency which doesnt exists"',
            str(context.exception))
Example #8
0
    def main(self):
        packages = [
            'commons',
            'di_container',
            __package__ + '.commons',
            __package__ + '.conta',
            __package__ + '.database',
            __package__ + '.import',
            'fdc.lancamento',
            'fdc.produto',
            'fdc.fornecedor',
        ]

        di_container.load_resources(packages)
        controller.load_listeners(packages)

        di_container.inject_resources(self)

        self._logger.info('Loaded resources and listeners from packages: {}',
                          packages)

        self._logger.debug('Using configurations: {}', self._configs.dump())

        args = self.parse_command_line()

        self._logger.info('Command line parsed: {}', args)

        event_results = controller.event(args.event,
                                         inject_dependencies=True,
                                         args=args)

        for result in event_results:
            self._logger.info(
                'Calling front end for "{}" with data "{}, {}" due to status "{}"',
                args.event, result.kwdata, result.data, result.status)

            # inject_dependencies parameter put first
            event_args = True, *result.data

            controller.event(args.event + '_' + result.status, *event_args,
                             **result.kwdata)