Ejemplo n.º 1
0
        def test_allowing_with_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass).with_args(
                *VALID_ARGS[test_class]).and_return('Bob Barker')

            assert TestClass(*VALID_ARGS[test_class]) == 'Bob Barker'
Ejemplo n.º 2
0
        def test_called_with_wrong_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass).with_args(*VALID_ARGS[test_class]).and_return('Bob Barker')

            with raises(UnallowedMethodCallError):
                TestClass('Bob', 101)
Ejemplo n.º 3
0
    def test_using_the_patched_class(self):
        allow_constructor(patch_class('doubles.testing.User')).and_return('result_1')
        allow_constructor(patch_class('doubles.testing.OldStyleUser')).and_return('result_2')

        result_1, result_2 = doubles.testing.top_level_function_that_creates_an_instance()

        assert result_1 == 'result_1'
        assert result_2 == 'result_2'
Ejemplo n.º 4
0
        def test_called_with_wrong_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass).with_args(
                *VALID_ARGS[test_class]).and_return('Bob Barker')

            with raises(UnallowedMethodCallError):
                TestClass('Bob', 101)
Ejemplo n.º 5
0
    def test_using_the_patched_class(self):
        allow_constructor(
            patch_class('doubles.testing.User')).and_return('result_1')
        allow_constructor(
            patch_class('doubles.testing.OldStyleUser')).and_return('result_2')

        result_1, result_2 = doubles.testing.top_level_function_that_creates_an_instance(
        )

        assert result_1 == 'result_1'
        assert result_2 == 'result_2'
Ejemplo n.º 6
0
        def test_allowing_with_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass).with_args(*VALID_ARGS[test_class]).and_return('Bob Barker')

            assert TestClass(*VALID_ARGS[test_class]) == 'Bob Barker'
Ejemplo n.º 7
0
 def test_fails_with_positional_args_and_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     with raises(VerifyingDoubleArgumentError):
         allow_constructor(double).with_args(1, 2, foo=1)
Ejemplo n.º 8
0
 def test_fails_with_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     with raises(VerifyingDoubleArgumentError):
         allow_constructor(double).with_args(bob='Barker')
Ejemplo n.º 9
0
 def test_passes_with_positional_args(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     allow_constructor(double).with_args(1, 2)
Ejemplo n.º 10
0
 def test_passes_with_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     allow_constructor(double).with_args(bob='Barker')
Ejemplo n.º 11
0
 def test_raises_if_you_allow_constructor(self, test_class):
     with raises(ConstructorDoubleError):
         allow_constructor(test_class)
Ejemplo n.º 12
0
 def test_raises_if_you_allow_constructor(self, test_class):
     with raises(ConstructorDoubleError):
         allow_constructor(test_class)
Ejemplo n.º 13
0
def gen_mock_service():
    class_name = 'bootcamp.handlers.title.TitleService'
    mock_service = TitleService()
    service_class = patch_class(class_name)
    allow_constructor(service_class).and_return(mock_service)
    return mock_service
Ejemplo n.º 14
0
        def test_with_no_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass)
            assert TestClass(*VALID_ARGS[test_class]) is None
Ejemplo n.º 15
0
 def test_fails_with_positional_args_and_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     with raises(VerifyingDoubleArgumentError):
         allow_constructor(double).with_args(1, 2, foo=1)
Ejemplo n.º 16
0
 def test_fails_with_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     with raises(VerifyingDoubleArgumentError):
         allow_constructor(double).with_args(bob='Barker')
Ejemplo n.º 17
0
 def test_passes_with_positional_args(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     allow_constructor(double).with_args(1, 2)
Ejemplo n.º 18
0
 def test_passes_with_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     allow_constructor(double).with_args(bob='Barker')
Ejemplo n.º 19
0
def git():
    repo = ClassDouble('accountable.accountable.Repo')
    git = InstanceDouble('accountable.accountable.Repo')
    git.git = support.MockRepo()
    allow_constructor(repo).and_return(git)
    accountable.Repo = repo
Ejemplo n.º 20
0
        def test_with_invalid_args(self, test_class):
            TestClass = ClassDouble(test_class)

            with raises(VerifyingDoubleArgumentError):
                allow_constructor(TestClass).with_args(10)
Ejemplo n.º 21
0
        def test_with_invalid_args(self, test_class):
            TestClass = ClassDouble(test_class)

            with raises(VerifyingDoubleArgumentError):
                allow_constructor(TestClass).with_args(10)
Ejemplo n.º 22
0
def gen_mock_service():
    class_name = 'bootcamp.handlers.add_user.UserService'
    mock_service = UserService()
    service_class = patch_class(class_name)
    allow_constructor(service_class).and_return(mock_service)
    return mock_service
Ejemplo n.º 23
0
        def test_with_no_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass)
            assert TestClass(*VALID_ARGS[test_class]) is None