def test_gen_no_data(self, stringify_mock):

        generator = LogicalIdGenerator(self.prefix)

        self.assertEqual(self.prefix, generator.gen())

        # Calling gen() again should return the same result
        self.assertEqual(generator.gen(), generator.gen())

        stringify_mock.assert_not_called()
    def test_gen_no_data(self, stringify_mock):

        generator = LogicalIdGenerator(self.prefix)

        self.assertEquals(self.prefix, generator.gen())

        # Calling gen() again should return the same result
        self.assertEquals(generator.gen(), generator.gen())

        stringify_mock.assert_not_called()
Пример #3
0
    def test_gen_hash_data_empty(self, stringify_mock):
        data = {"foo": "bar"}
        stringified_data = "stringified data"
        hash_value = ""
        stringify_mock.return_value = stringified_data

        generator = LogicalIdGenerator(self.prefix,
                                       data_obj=data,
                                       data_hash=hash_value)

        stringify_mock.assert_called_once_with(data)
        self.assertEqual(generator.gen(), generator.gen())
    def test_gen_dict_data(self, stringify_mock, get_hash_mock):
        data = {"foo": "bar"}
        stringified_data = "stringified data"
        hash_value = "some hash value"
        get_hash_mock.return_value = hash_value
        stringify_mock.return_value = stringified_data

        generator = LogicalIdGenerator(self.prefix, data_obj=data)

        expected = "{}{}".format(self.prefix, hash_value)
        self.assertEqual(expected, generator.gen())
        get_hash_mock.assert_called_once_with()
        stringify_mock.assert_called_once_with(data)

        self.assertEqual(generator.gen(), generator.gen())
    def test_gen_dict_data(self, stringify_mock, get_hash_mock):
        data = {"foo": "bar"}
        stringified_data =  "stringified data"
        hash_value = "some hash value"
        get_hash_mock.return_value = hash_value
        stringify_mock.return_value = stringified_data

        generator = LogicalIdGenerator(self.prefix, data_obj=data)

        expected = "{}{}".format(self.prefix, hash_value)
        self.assertEqual(expected, generator.gen())
        get_hash_mock.assert_called_once_with()
        stringify_mock.assert_called_once_with(data)

        self.assertEqual(generator.gen(), generator.gen())
Пример #6
0
    def test_gen_hash_data_override(self, stringify_mock):
        data = {"foo": "bar"}
        stringified_data = "stringified data"
        hash_value = "6b86b273ff"
        stringify_mock.return_value = stringified_data

        generator = LogicalIdGenerator(self.prefix,
                                       data_obj=data,
                                       data_hash=hash_value)

        expected = "{}{}".format(self.prefix, hash_value)
        self.assertEqual(expected, generator.gen())
        stringify_mock.assert_called_once_with(data)

        self.assertEqual(generator.gen(), generator.gen())
    def test_gen_stability_with_copy(self):
        data = {"foo": "bar", "a": "b"}
        generator = LogicalIdGenerator(self.prefix, data_obj=data)

        old = generator.gen()
        new = LogicalIdGenerator(self.prefix, data_obj=data.copy()).gen() # Create a copy of data obj
        self.assertEqual(old, new)
    def test_gen_stability_with_different_dict_ordering(self):
        data = {"foo": "bar", "nested": {"a": "b", "c": "d"}}
        data_other = {"nested": {"c": "d", "a": "b"}, "foo": "bar"}  # Same content but different ordering of keys
        generator = LogicalIdGenerator(self.prefix, data_obj=data)

        old = generator.gen()
        new = LogicalIdGenerator(self.prefix, data_obj=data_other).gen()
        self.assertEqual(old, new)
    def test_gen_stability_with_copy(self):
        data = {"foo": "bar", "a": "b"}
        generator = LogicalIdGenerator(self.prefix, data_obj=data)

        old = generator.gen()
        new = LogicalIdGenerator(
            self.prefix,
            data_obj=data.copy()).gen()  # Create a copy of data obj
        self.assertEqual(old, new)
    def test_gen_stability_with_different_dict_ordering(self):
        data = {"foo": "bar", "nested": {"a": "b", "c": "d"}}
        data_other = {
            "nested": {
                "c": "d",
                "a": "b"
            },
            "foo": "bar"
        }  # Same content but different ordering of keys
        generator = LogicalIdGenerator(self.prefix, data_obj=data)

        old = generator.gen()
        new = LogicalIdGenerator(self.prefix, data_obj=data_other).gen()
        self.assertEqual(old, new)