예제 #1
0
 def test_method_implemented(self):
     os.environ = {
         'SERF_SELF_NAME': 'null',
         'SERF_SELF_ROLE': 'null',
         'SERF_EVENT': 'user',
         'SERF_USER_EVENT': 'implemented',
     }
     handler = SerfHandlerProxy()
     sample = SerfHandler()
     sample.implemented = MagicMock(return_value=True)
     assert len(handler.handlers) == 0
     handler.register('default', sample)
     assert len(handler.handlers) == 1
     handler.run()
     sample.implemented.assert_called_with()
예제 #2
0
 def test_method_implemented(self):
     os.environ = {
         'SERF_SELF_NAME': 'null',
         'SERF_SELF_ROLE': 'null',
         'SERF_EVENT': 'user',
         'SERF_USER_EVENT': 'implemented',
     }
     handler = SerfHandlerProxy()
     sample = SerfHandler()
     sample.implemented = MagicMock(return_value=True)
     assert len(handler.handlers) == 0
     handler.register('default', sample)
     assert len(handler.handlers) == 1
     handler.run()
     sample.implemented.assert_called_with()
예제 #3
0
class TestSerfHandlerNegativeCases:
    def setup(self):
        os.environ = {
            'SERF_SELF_NAME': 'null',
            'SERF_SELF_ROLE': 'null',
            'SERF_EVENT': 'member-join',
        }
        self.handler = SerfHandlerProxy()
        self.handler.log = MagicMock(return_value=True)
        assert len(self.handler.handlers) == 0

    def test_no_handler(self):
        self.handler.run()
        self.handler.log.assert_called_with("no handler found")

    def test_no_method_implemented(self):
        self.handler.register('default', SerfHandler())
        assert len(self.handler.handlers) == 1
        self.handler.run()
        self.handler.log.assert_called_with("event not implemented by class")
예제 #4
0
class TestSerfHandlerNegativeCases:

    def setup(self):
        os.environ = {
            'SERF_SELF_NAME': 'null',
            'SERF_SELF_ROLE': 'null',
            'SERF_EVENT': 'member-join',
        }
        self.handler = SerfHandlerProxy()
        self.handler.log = MagicMock(return_value=True)
        assert len(self.handler.handlers) == 0

    def test_no_handler(self):
        self.handler.run()
        self.handler.log.assert_called_with("no handler found")

    def test_no_method_implemented(self):
        self.handler.register('default', SerfHandler())
        assert len(self.handler.handlers) == 1
        self.handler.run()
        self.handler.log.assert_called_with("event not implemented by class")
예제 #5
0
class TestSerfHandlerProxyStandardEvent:
    def setup(self):
        os.environ = {
            'SERF_SELF_NAME': 'null',
            'SERF_SELF_ROLE': 'web',
            'SERF_EVENT': 'member-join',
        }
        self.handler = SerfHandlerProxy()
        self.sample = SerfHandler()
        self.sample.member_join = MagicMock(return_value=True)

    def test_standard_events_called(self):
        self.handler.register('default', self.sample)
        assert len(self.handler.handlers) == 1
        assert 'default' in self.handler.handlers
        self.handler.run()
        self.sample.member_join.assert_called_with()

    def test_role_registration(self):
        self.handler.register('web', self.sample)
        assert len(self.handler.handlers) == 1
        assert 'web' in self.handler.handlers
        self.handler.run()
        self.sample.member_join.assert_called_with()
예제 #6
0
class TestSerfHandlerProxyStandardEvent:
    def setup(self):
        os.environ = {
            'SERF_SELF_NAME': 'null',
            'SERF_SELF_ROLE': 'web',
            'SERF_EVENT': 'member-join',
        }
        self.handler = SerfHandlerProxy()
        self.sample = SerfHandler()
        self.sample.member_join = MagicMock(return_value=True)

    def test_standard_events_called(self):
        self.handler.register('default', self.sample)
        assert len(self.handler.handlers) == 1
        assert 'default' in self.handler.handlers
        self.handler.run()
        self.sample.member_join.assert_called_with()

    def test_role_registration(self):
        self.handler.register('web', self.sample)
        assert len(self.handler.handlers) == 1
        assert 'web' in self.handler.handlers
        self.handler.run()
        self.sample.member_join.assert_called_with()