def setUp(self):
        from faker import Faker

        self.faker = Faker()
        self.mock = PartialCallableMock()
 def _setup_mock(self):
     self.mock_slack_client_instance.api_call = PartialCallableMock()
     self.mock_slack_client_instance.api_call.return_value = {'ok': True}
class TestPartialCallableMock(unittest.TestCase):
    def setUp(self):
        from faker import Faker

        self.faker = Faker()
        self.mock = PartialCallableMock()

    def test_is_mock(self):
        self.assertIsInstance(self.mock, Mock)

    def test_raises_exception_if_called_with_incorrect_params(self):
        param = self.faker.sentence()
        self.mock()

        with self.assertRaises(AssertionError) as error_context:
            self.mock.assert_called_with_partial(param)

        expected_message = "Expected call: mock('{}')\nActual call: mock()".format(
            param)
        self.assertIn(expected_message, error_context.exception.args)

    def test_raises_exception_if_called_with_incorrect_keywords_args(self):
        param = self.faker.sentence()
        self.mock()

        with self.assertRaises(AssertionError) as error_context:
            self.mock.assert_called_with_partial(hello=param)

        expected_message = "Expected call: mock(hello='{}')\nActual call: mock()".format(
            param)
        self.assertIn(expected_message, error_context.exception.args)

    def test_raises_exception_if_called_with_partial_out_of_order(self):
        param = self.faker.sentence()
        param_2 = self.faker.sentence()
        self.mock(param_2, param)

        with self.assertRaises(AssertionError) as error_context:
            self.mock.assert_called_with_partial(param, param_2)

        expected_message = "Expected call: mock('{}', '{}')\nActual call: mock('{}', '{}')".format(
            param, param_2, param_2, param)
        self.assertIn(expected_message, error_context.exception.args)

    def test_raises_exception_if_not_called(self):
        param = self.faker.sentence()

        with self.assertRaises(AssertionError) as error_context:
            self.mock.assert_called_with_partial(param)

        expected_message = "Expected call: mock('{}')\nNot called".format(
            param)
        self.assertIn(expected_message, error_context.exception.args)

    def test_does_not_raise_when_called_properly(self):
        param = self.faker.sentence()
        self.mock(param)
        self.mock.assert_called_with_partial(param)

    def test_does_not_raise_when_called_partially(self):
        param = self.faker.sentence()
        param_2 = self.faker.sentence()

        self.mock(param, param_2)
        self.mock.assert_called_with_partial(param)
Exemple #4
0
 def test_uses_channel_in_config(self):
     self.config_manager['job_notification_channel'] = self.channel
     self.slack_notifier.send_message = PartialCallableMock()
     self.slack_notifier.send_message.return_value = False
     self.notifier.send_message(self.message)
     self.slack_notifier.send_message.assert_called_with_partial(channel=self.channel)
Exemple #5
0
 def test_sends_message_to_slack_notifier_when_first_attempt_fails(self):
     self.slack_notifier.send_message = PartialCallableMock()
     self.slack_notifier.send_message.return_value = False
     self.notifier.send_message(self.message)
     self.slack_notifier.send_message.assert_called_with_partial(message=self.message)
Exemple #6
0
 def test_sends_null_channel_if_not_defined(self):
     self.slack_notifier.send_message = PartialCallableMock()
     self.notifier.send_message(self.message)
     self.slack_notifier.send_message.assert_called_with_partial(channel=None)
Exemple #7
0
 def test_sends_message_to_slack_notifier(self):
     self.slack_notifier.send_message = PartialCallableMock()
     self.notifier.send_message(self.message)
     self.slack_notifier.send_message.assert_called_with_partial(message=self.message)