20
20
main_collection_name = test_app_config .database .main_collection_name
21
21
22
22
23
- def collections_exists (test_collection_names : list [str ], expected_collection_name : list [str ]) -> bool :
24
- """Checks if the test and expected list of collection names match."""
25
- return Counter (test_collection_names ) == Counter (expected_collection_name )
26
-
27
-
28
- def document_ids_are_correct (test_ids : list [str ], expected_ids : list [str ]) -> bool :
29
- """Checks if the test (retrieved from the API) and expected list of (document) ids match."""
30
- return Counter (test_ids ) == Counter (expected_ids )
31
-
32
-
33
- def single_query_is_correct (key : str , value : str | datetime ) -> bool :
34
- """Checks if the given single query, denoted by ``key`` matches correctly against the ``value``."""
35
- return (
36
- Counter (http_get (f"queries?{ key } ={ value } " ).json ()) ==
37
- Counter (TestDatabase .match_query (** {key : value }))
38
- )
39
-
40
-
41
- def make_query_string (keys : list [str ], values_list : list [list [str ] | datetime ]) -> str :
42
- """Makes a single query string for all the given queries."""
43
- query_buffer = []
44
- for key , value_list in zip (keys , values_list , strict = True ):
45
- query_buffer += [f"{ key } ={ value } " for value in value_list ]
46
- return "&" .join (query_buffer )
47
-
48
-
49
- def query_results_are_correct (keys : list [str ], values_list : list [list [str ] | datetime ]) -> bool :
50
- """Checks if the retrieved result from querying the database via the API matches the expected result.
51
-
52
- There can be more than one query `key/value` pair.
53
-
54
- Args:
55
- keys:
56
- A list of all query keys, e.g. ``keys=["platform", "sensor"]``
57
-
58
- values_list:
59
- A list in which each element is a list of values itself. The `nth` element corresponds to the `nth` key in
60
- the ``keys``.
61
-
62
- Returns:
63
- A boolean flag indicating whether the retrieved result matches the expected result.
64
- """
65
- query_string = make_query_string (keys , values_list )
66
-
67
- return (
68
- Counter (http_get (f"queries?{ query_string } " ).json ()) ==
69
- Counter (TestDatabase .match_query (
70
- ** {label : value_list for label , value_list in zip (keys , values_list , strict = True )}
71
- ))
72
- )
73
-
74
-
75
23
@pytest .mark .usefixtures ("_test_server_fixture" )
76
24
def test_root ():
77
25
"""Checks that the server is up and running, i.e. the root routes responds with 200."""
@@ -120,6 +68,16 @@ def test_collections():
120
68
)
121
69
122
70
71
+ def collections_exists (test_collection_names : list [str ], expected_collection_name : list [str ]) -> bool :
72
+ """Checks if the test and expected list of collection names match."""
73
+ return Counter (test_collection_names ) == Counter (expected_collection_name )
74
+
75
+
76
+ def document_ids_are_correct (test_ids : list [str ], expected_ids : list [str ]) -> bool :
77
+ """Checks if the test (retrieved from the API) and expected list of (document) ids match."""
78
+ return Counter (test_ids ) == Counter (expected_ids )
79
+
80
+
123
81
@pytest .mark .usefixtures ("_test_server_fixture" )
124
82
def test_collections_negative ():
125
83
"""Checks that the non-existing collections cannot be found."""
@@ -159,6 +117,40 @@ def test_queries_platform_or_sensor(key: str, values: list[str]):
159
117
)
160
118
161
119
120
+ def make_query_string (keys : list [str ], values_list : list [list [str ] | datetime ]) -> str :
121
+ """Makes a single query string for all the given queries."""
122
+ query_buffer = []
123
+ for key , value_list in zip (keys , values_list , strict = True ):
124
+ query_buffer += [f"{ key } ={ value } " for value in value_list ]
125
+ return "&" .join (query_buffer )
126
+
127
+
128
+ def query_results_are_correct (keys : list [str ], values_list : list [list [str ] | datetime ]) -> bool :
129
+ """Checks if the retrieved result from querying the database via the API matches the expected result.
130
+
131
+ There can be more than one query `key/value` pair.
132
+
133
+ Args:
134
+ keys:
135
+ A list of all query keys, e.g. ``keys=["platform", "sensor"]``
136
+
137
+ values_list:
138
+ A list in which each element is a list of values itself. The `nth` element corresponds to the `nth` key in
139
+ the ``keys``.
140
+
141
+ Returns:
142
+ A boolean flag indicating whether the retrieved result matches the expected result.
143
+ """
144
+ query_string = make_query_string (keys , values_list )
145
+
146
+ return (
147
+ Counter (http_get (f"queries?{ query_string } " ).json ()) ==
148
+ Counter (TestDatabase .match_query (
149
+ ** {label : value_list for label , value_list in zip (keys , values_list , strict = True )}
150
+ ))
151
+ )
152
+
153
+
162
154
@pytest .mark .usefixtures ("_test_server_fixture" )
163
155
def test_queries_mix_platform_sensor ():
164
156
"""Tests a mix of platform and sensor queries."""
@@ -185,3 +177,11 @@ def test_queries_time():
185
177
"time_max" ,
186
178
time_max
187
179
)
180
+
181
+
182
+ def single_query_is_correct (key : str , value : str | datetime ) -> bool :
183
+ """Checks if the given single query, denoted by ``key`` matches correctly against the ``value``."""
184
+ return (
185
+ Counter (http_get (f"queries?{ key } ={ value } " ).json ()) ==
186
+ Counter (TestDatabase .match_query (** {key : value }))
187
+ )
0 commit comments