diff --git a/almanach/tests/unit/api/auth/test_mixed_auth.py b/almanach/tests/unit/api/auth/test_mixed_auth.py index 512ede5..1f7ad68 100644 --- a/almanach/tests/unit/api/auth/test_mixed_auth.py +++ b/almanach/tests/unit/api/auth/test_mixed_auth.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flexmock import flexmock -from hamcrest import assert_that -from hamcrest import calling -from hamcrest import equal_to -from hamcrest import raises +import mock from almanach.api.auth import mixed_auth from almanach.core import exception @@ -27,24 +23,34 @@ class TestMixedAuthentication(base.BaseTestCase): def setUp(self): super(TestMixedAuthentication, self).setUp() - self.auth_one = flexmock() - self.auth_two = flexmock() + self.auth_one = mock.Mock() + self.auth_two = mock.Mock() self.auth_backend = mixed_auth.MixedAuthentication([self.auth_one, self.auth_two]) + def tearDown(self): + super(TestMixedAuthentication, self).tearDown() + def test_with_token_valid_with_auth_one(self): token = "my token" - self.auth_one.should_receive("validate").and_return(True) - assert_that(self.auth_backend.validate(token), equal_to(True)) + self.auth_one.validate.return_value = True + + self.assertEqual(self.auth_backend.validate(token), True) + self.auth_one.validate.assert_called_once() def test_with_token_valid_with_auth_two(self): token = "my token" - self.auth_one.should_receive("validate").and_raise(exception.AuthenticationFailureException) - self.auth_two.should_receive("validate").and_return(True) - assert_that(self.auth_backend.validate(token), equal_to(True)) + self.auth_one.validate.side_effect = exception.AuthenticationFailureException + self.auth_two.validate.return_value = True + + self.assertEqual(self.auth_backend.validate(token), True) + self.auth_one.validate.assert_called_once() + self.auth_two.validate.assert_called_once() def test_with_token_valid_with_auth_twos(self): token = "bad token" - self.auth_one.should_receive("validate").and_raise(exception.AuthenticationFailureException) - self.auth_two.should_receive("validate").and_raise(exception.AuthenticationFailureException) - assert_that(calling(self.auth_backend.validate) - .with_args(token), raises(exception.AuthenticationFailureException)) + self.auth_one.validate.side_effect = exception.AuthenticationFailureException + self.auth_two.validate.side_effect = exception.AuthenticationFailureException + + self.assertRaises(exception.AuthenticationFailureException, self.auth_backend.validate, token) + self.auth_one.validate.assert_called_once() + self.auth_two.validate.assert_called_once() diff --git a/almanach/tests/unit/base.py b/almanach/tests/unit/base.py index 5144225..b777c7a 100644 --- a/almanach/tests/unit/base.py +++ b/almanach/tests/unit/base.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flexmock import flexmock_teardown from oslo_config import fixture import testtools @@ -28,4 +27,3 @@ class BaseTestCase(testtools.TestCase): def tearDown(self): super(BaseTestCase, self).tearDown() - flexmock_teardown()