def test_name_get_qualifier_on_instance(self,
                                         class_with_indeterminate_contexts,
                                         container):
     foo = create_component(class_with_indeterminate_contexts, container)
     bar_context = get_di_context(foo.bar)
     # the dependent on component has the dependency context already determined, based
     # on the dependant state
     assert bar_context == DIContext(
         name="bar", qualifier=class_with_indeterminate_contexts.qualifier)
     assert bar_context.is_determined()
    def test_without_validation(self, container, request_data, team):
        interactor = create_component(AddTeamMember,
                                      container,
                                      kwargs={'validators': ()})
        response = interactor(request_data)

        assert response.data == request_data
        assert not response.errors
        assert response.is_success
        # noinspection PyUnresolvedReferences
        interactor.teams.update.assert_called_once_with(team)
    def test_no_name_no_interface(self, container):
        class NoAnnotationBike(Component):
            wheel = Inject()

        instance = create_component(NoAnnotationBike, container)
        with pytest.raises(ConfigError) as error_info:
            assert instance.wheel
        assert error_info.value == DIErrors.NO_IDENTIFIER_SPECIFIED
        assert error_info.value.params == {
            'class_name': ('TestInjectDescriptor.test_no_name_no_interface.'
                           '<locals>.NoAnnotationBike'),
            'attribute':
            'wheel',
        }
    def test_no_name_no_interface(self, container):
        class NoAnnotationBike(Component):
            wheel = Inject()

        instance = create_component(NoAnnotationBike, container)
        with pytest.raises(ConfigError) as error_info:
            assert instance.wheel
        assert error_info.value == DIErrors.NO_IDENTIFIER_SPECIFIED
        assert error_info.value.params == {
            "class_name": ("TestInjectDescriptor.test_no_name_no_interface."
                           "<locals>.NoAnnotationBike"),
            "attribute":
            "wheel",
            "context":
            None,
        }
 def interactor(self, container, validators):
     return create_component(AddTeamMember,
                             container,
                             kwargs={'validators': validators})
Beispiel #6
0
 def instance(self, container, context):
     return create_component(self.Bike, container, context)