class TestFuncKeyMapper(unittest.TestCase): def setUp(self): self.builder = Mock(DestinationBuilder) self.builders = {"spam": self.builder} self.mapper = FuncKeyMapper(self.builders) def test_given_json_dict_when_decoding_then_returns_dict(self): expected = {"label": "foo", "blf": True, "destination": {"type": "spam"}} result = self.mapper.for_decoding(expected) assert_that(result, equal_to(expected)) def test_given_model_when_encoding_then_encodes_funckey_and_destination(self): destination = Mock(type="spam") expected_destination = self.builder.to_mapping.return_value expected = { "id": sentinel.id, "label": None, "blf": True, "inherited": True, "destination": expected_destination, } model = FuncKey(id=sentinel.id, destination=destination) result = self.mapper.for_encoding(model) assert_that(result, equal_to(expected))
def setUp(self): self.builder = Mock(DestinationBuilder) self.builders = {"spam": self.builder} self.mapper = FuncKeyMapper(self.builders)