Пример #1
0
class TestTemplateMapper(unittest.TestCase):
    def setUp(self):
        self.funckey_mapper = Mock(FuncKeyMapper)
        self.mapper = TemplateMapper(self.funckey_mapper)

    def test_given_json_dict_when_decoding_then_returns_dict(self):
        expected = {"name": "foo"}

        result = self.mapper.for_decoding(expected)

        assert_that(result, equal_to(expected))

    def test_given_json_dict_with_keys_when_decoding_then_converts_key_positions(self):
        body = {"name": "foo", "keys": {"1": {"destination": "parking"}, "2": {"destination": "custom"}}}

        expected = {"name": "foo", "keys": {1: {"destination": "parking"}, 2: {"destination": "custom"}}}

        result = self.mapper.for_decoding(body)

        assert_that(result, equal_to(expected))

    def test_given_empty_model_when_encoding_then_returns_bare_mapping(self):
        model = FuncKeyTemplate(id=1, name="foobar")
        expected = {"id": 1, "name": "foobar", "keys": {}}

        result = self.mapper.for_encoding(model)

        assert_that(result, equal_to(expected))

    def test_given_template_with_funckey_when_encoding_then_encodes_funckeys(self):
        funckey = Mock(FuncKey)
        model = FuncKeyTemplate(id=1, name="foobar", keys={1: funckey})

        expected_mapping = self.funckey_mapper.for_encoding.return_value

        expected = {"id": 1, "name": "foobar", "keys": {1: expected_mapping}}

        result = self.mapper.for_encoding(model)

        assert_that(result, equal_to(expected))
Пример #2
0
 def setUp(self):
     self.funckey_mapper = Mock(FuncKeyMapper)
     self.mapper = TemplateMapper(self.funckey_mapper)