summaryrefslogtreecommitdiffstats
path: root/tests/db_tests/configuration_db_test.py
blob: e8b7188b9ef912afd4bb1f6e173d5f20892185a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
##############################################################################
# Copyright (c) 2015 EMC and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

from storperf.db.configuration_db import ConfigurationDB
import os
import unittest


class ConfigurationDBTest(unittest.TestCase):

    def setUp(self):
        ConfigurationDB.db_name = __name__ + ".db"
        try:
            os.remove(ConfigurationDB.db_name)
        except OSError:
            pass

        self.config_db = ConfigurationDB()

    def test_create_key(self):
        expected = "ABCDE-12345"

        self.config_db.set_configuration_value(
            "test", "key", expected)

        actual = self.config_db.get_configuration_value(
            "test", "key")

        self.assertEqual(
            expected, actual, "Did not expect: " + str(actual))

    def test_update_key(self):
        expected = "ABCDE-12345"

        self.config_db.set_configuration_value(
            "test", "key", "initial_value")

        self.config_db.set_configuration_value(
            "test", "key", expected)

        actual = self.config_db.get_configuration_value(
            "test", "key")

        self.assertEqual(
            expected, actual, "Did not expect: " + str(actual))

    def test_deleted_key(self):
        expected = None

        self.config_db.set_configuration_value(
            "test", "key", "initial_value")

        self.config_db.delete_configuration_value(
            "test", "key")

        actual = self.config_db.get_configuration_value(
            "test", "key")

        self.assertEqual(
            expected, actual, "Did not expect: " + str(actual))