Upgrade to SDL 2.0.2
[ric-plt/a1.git] / tests / test_data.py
1 """
2 tests data functions
3 """
4 # ==================================================================================
5 #       Copyright (c) 2019-2020 Nokia
6 #       Copyright (c) 2018-2020 AT&T Intellectual Property.
7 #
8 #   Licensed under the Apache License, Version 2.0 (the "License");
9 #   you may not use this file except in compliance with the License.
10 #   You may obtain a copy of the License at
11 #
12 #          http://www.apache.org/licenses/LICENSE-2.0
13 #
14 #   Unless required by applicable law or agreed to in writing, software
15 #   distributed under the License is distributed on an "AS IS" BASIS,
16 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 #   See the License for the specific language governing permissions and
18 #   limitations under the License.
19 # ==================================================================================
20 from a1 import data
21 from ricsdl.syncstorage import SyncStorage
22
23
24 def setup_module():
25     """module level setup"""
26     data.SDL.sdl = SyncStorage(fake_db_backend="dict")
27
28
29 def test_sdl_raw():
30     """
31     test raw sdl functions
32     """
33     data.SDL.set("as.df1", "data")
34     data.SDL.set("as.df2", "data2")
35     assert data.SDL.get("as.df1") == "data"
36     assert data.SDL.get("as.df2") == "data2"
37     assert data.SDL.find_and_get("as.df1") == {"as.df1": "data"}
38     assert data.SDL.find_and_get("as.df2") == {"as.df2": "data2"}
39     assert data.SDL.find_and_get("as.df") == {"as.df1": "data", "as.df2": "data2"}
40     assert data.SDL.find_and_get("as.d") == {"as.df1": "data", "as.df2": "data2"}
41     assert data.SDL.find_and_get("as.") == {"as.df1": "data", "as.df2": "data2"}
42     assert data.SDL.find_and_get("asd") == {}
43
44     # delete 1
45     data.SDL.delete("as.df1")
46     assert data.SDL.get("as.df1") is None
47     assert data.SDL.get("as.df2") == "data2"
48
49     # delete 2
50     data.SDL.delete("as.df2")
51     assert data.SDL.get("as.df2") is None
52
53     assert data.SDL.find_and_get("as.df") == {}
54     assert data.SDL.find_and_get("") == {}