Exemplo n.º 1
0
    def test_merge_list_of_property_loaders_merges_properties_from_multiple_loaders_as_expected(
            self):
        k1 = util.base36_str()
        v1 = util.base36_str()
        k2 = util.base36_str()
        v2_a = util.base36_str()
        v2_b = util.base36_str()
        k3 = util.base36_str()
        v3 = util.base36_str()
        k4 = util.base36_str()
        v4 = util.base36_str()

        loaders = [
            DictPropertyLoader("first", {
                k1: v1,
                k2: v2_a
            }),
            DictPropertyLoader("second", {
                k2: v2_b,
                k3: v3
            }),
            DictPropertyLoader("third", {k4: v4}),
        ]

        ret = props.merge_list_of_property_loaders(loaders)

        expected_ret = {
            k1: v1,
            k2: v2_a,
            k3: v3,
            k4: v4,
        }

        self.assertEqual(expected_ret, ret)
Exemplo n.º 2
0
    def test_DictPropertyLoader_get_all_returns_same_dict_as_supplied_in_ctor(
            self):
        d = {"k1": "v1", "k2": "v2"}
        loader = DictPropertyLoader(util.base36_str(), d)

        ret = loader.get_all()

        self.assertEqual(d, ret)
Exemplo n.º 3
0
    def test_DictPropertyLoader_get_returns_property_from_dict(self):
        k = util.base36_str()
        v = util.base36_str()

        loader = DictPropertyLoader(util.base36_str(), {k: v})

        ret = loader.get(k)

        self.assertEqual(v, ret)
Exemplo n.º 4
0
    def test_get_property_from_list_of_loaders_overwrites_properties(self):
        k = util.base36_str()
        v1 = util.base36_str()
        v2 = util.base36_str()

        loaders = [
            DictPropertyLoader("first", {k: v1}),
            DictPropertyLoader("second", {k: v2}),
        ]

        ret = props.get_property_from_list_of_loaders(loaders, k)

        self.assertEqual(ret, v1)
Exemplo n.º 5
0
    def test_get_property_from_list_of_loaders_returns_prop_from_multiple_loaders(
            self):
        k1 = util.base36_str()
        v1 = util.base36_str()
        k2 = util.base36_str()
        v2 = util.base36_str()

        loaders = [
            DictPropertyLoader(util.base36_str(), {k1: v1}),
            DictPropertyLoader(util.base36_str(), {k2: v2}),
        ]

        ret = props.get_property_from_list_of_loaders(loaders, k2)

        self.assertEqual(v2, ret)
Exemplo n.º 6
0
    def test_get_returns_property_from_loaders(self):
        k = util.base36_str()
        v = util.base36_str()
        loaders = [DictPropertyLoader("some-loader", {k: v})]

        props._set_loaders(loaders)

        self.assertEqual(v, props.get(k))
Exemplo n.º 7
0
    def test_get_property_from_list_of_loaders_returns_prop_from_single_loader(
            self):
        k = util.base36_str()
        v = util.base36_str()
        loaders = [DictPropertyLoader(util.base36_str(), {k: v})]

        ret = props.get_property_from_list_of_loaders(loaders, k)

        self.assertEqual(v, ret)
Exemplo n.º 8
0
    def test__set_loaders_then_uses_loader_with_get_all_call(self):
        k1 = util.base36_str()
        v1 = util.base36_str()
        k2 = util.base36_str()
        v2 = util.base36_str()
        loaders = [
            DictPropertyLoader("some-loader", {k1: v1}),
            DictPropertyLoader("some-other-loader", {k2: v2}),
        ]

        props._set_loaders(loaders)

        expected_value = {
            k1: v1,
            k2: v2,
        }
        actual_value = props.get_all()

        self.assertEqual(expected_value, actual_value)
Exemplo n.º 9
0
    def test__set_loaders_then_uses_loader_with_get_call(self):
        k = util.base36_str()
        v = util.base36_str()
        loaders = [DictPropertyLoader("some-loader", {k: v})]

        props._set_loaders(loaders)

        ret = props.get(k)

        self.assertEqual(ret, v)
Exemplo n.º 10
0
    def test_get_all_dict_contains_expected_results(self):
        k1 = util.base36_str()
        v1 = util.base36_str()
        v2 = util.base36_str()
        k3 = util.base36_str()
        v3 = util.base36_str()

        loaders = [
            DictPropertyLoader("first", {k1: v1}),
            DictPropertyLoader("second", {k1: v2}),
            DictPropertyLoader("third", {k3: v3}),
        ]

        props._set_loaders(loaders)

        expected_result = {
            k1: v1,
            k3: v3,
        }

        actual_result = props.get_all()

        self.assertEqual(expected_result, actual_result)
Exemplo n.º 11
0
 def test__set_loaders_raises_ValueError_if_passed_list_containing_non_prop_loader(
         self):
     with self.assertRaises(ValueError):
         props._set_loaders(
             [DictPropertyLoader("some-loader", {}), "not-a-loader"])
Exemplo n.º 12
0
 def test_DictPropertyLoader_init_works_with_standard_args(self):
     DictPropertyLoader(util.base36_str(), {})
Exemplo n.º 13
0
 def test__set_loaders_allows_setting_list_of_loaders(self):
     loaders = [DictPropertyLoader("some-loader", {})]
     props._set_loaders(loaders)
Exemplo n.º 14
0
    def test_DictPropertyLoader_get_name_returns_supplied_name(self):
        name = util.base36_str()
        loader = DictPropertyLoader(name, {})

        self.assertEqual(name, loader.get_name())
Exemplo n.º 15
0
    def test_get_raises_KeyError_for_non_existent_property(self):
        props._set_loaders([DictPropertyLoader("some-loader", {})])

        with self.assertRaises(KeyError):
            props.get(util.base36_str())
Exemplo n.º 16
0
    def test_DictPropertyLoader_get_raises_KeyError_if_property_does_not_exist(
            self):
        loader = DictPropertyLoader(util.base36_str(), {})

        with self.assertRaises(KeyError):
            loader.get(util.base36_str())
Exemplo n.º 17
0
    def test_DictPropertyLoader_try_get_returns_None_if_property_does_not_exist(
            self):
        loader = DictPropertyLoader(util.base36_str(), {})

        self.assertIsNone(loader.try_get(util.base36_str()))