44from tests .test_models import test_model , test_model2
55
66
7- @mock .patch .object (client , ' connect' , autospec = True )
7+ @mock .patch .object (client , " connect" , autospec = True )
88def test_close_connection (mock_connect ):
99 """
1010 This function tests if the .close() functions of the self.conn and self.cursor objects is called
@@ -25,14 +25,16 @@ def test_close_connection(mock_connect):
2525 mock_connect .return_value = conn
2626 conn .cursor .return_value = cursor
2727 db_writer = CrateDbWriter ("localhost:4200" , "crate" , "password" , test_model )
28- mock_connect .assert_called_with ("localhost:4200" , username = "crate" , password = "password" )
28+ mock_connect .assert_called_with (
29+ "localhost:4200" , username = "crate" , password = "password"
30+ )
2931 # Test Case 1:
3032 db_writer .close_connection ()
3133 conn .close .assert_called ()
3234 cursor .close .assert_called ()
3335
3436
35- @mock .patch .object (client , ' connect' , autospec = True )
37+ @mock .patch .object (client , " connect" , autospec = True )
3638def test_prepare_database1 (mock_connect ):
3739 """
3840 This function tests if the .prepare_database() functions of the db_writer uses the correct values when
@@ -58,7 +60,9 @@ def test_prepare_database1(mock_connect):
5860 mock_connect .return_value = conn
5961 conn .cursor .return_value = cursor
6062 db_writer = CrateDbWriter ("localhost:4200" , "crate2" , "password2" , test_model )
61- mock_connect .assert_called_with ("localhost:4200" , username = "crate2" , password = "password2" )
63+ mock_connect .assert_called_with (
64+ "localhost:4200" , username = "crate2" , password = "password2"
65+ )
6266 # Test Case 1:
6367 db_writer .prepare_database ()
6468 stmt = cursor .execute .call_args .args [0 ]
@@ -72,7 +76,7 @@ def test_prepare_database1(mock_connect):
7276 assert "number_of_replicas = 1" in stmt
7377
7478
75- @mock .patch .object (client , ' connect' , autospec = True )
79+ @mock .patch .object (client , " connect" , autospec = True )
7680def test_prepare_database2 (mock_connect ):
7781 """
7882 This function tests if the .prepare_database() functions of the db_writer uses the correct values when
@@ -97,7 +101,9 @@ def test_prepare_database2(mock_connect):
97101 cursor = mock .Mock ()
98102 mock_connect .return_value = conn
99103 conn .cursor .return_value = cursor
100- db_writer = CrateDbWriter ("localhost:4200" , "crate3" , "password3" , test_model2 , "table_name" , 3 , 0 , "day" )
104+ db_writer = CrateDbWriter (
105+ "localhost:4200" , "crate3" , "password3" , test_model2 , "table_name" , 3 , 0 , "day"
106+ )
101107 db_writer .prepare_database ()
102108 # Test Case 1:
103109 stmt = cursor .execute .call_args .args [0 ]
@@ -111,7 +117,7 @@ def test_prepare_database2(mock_connect):
111117 assert "number_of_replicas = 0" in stmt
112118
113119
114- @mock .patch .object (client , ' connect' , autospec = True )
120+ @mock .patch .object (client , " connect" , autospec = True )
115121def test_insert_stmt (mock_connect ):
116122 """
117123 This function tests if the .insert_stmt() functions of CrateDbWriter uses the correct table name and arguments
@@ -134,15 +140,24 @@ def test_insert_stmt(mock_connect):
134140 conn .cursor .return_value = cursor
135141 db_writer = CrateDbWriter ("localhost:4200" , "crate2" , "password2" , test_model )
136142 # Test Case 1:
137- db_writer .insert_stmt ([1586327807000 ], [{"plant" : 1 , "line" : 1 , "sensor_id" : 1 , "value" : 6.7 , "button_press" : False }])
143+ db_writer .insert_stmt (
144+ [1586327807000 ],
145+ [{"plant" : 1 , "line" : 1 , "sensor_id" : 1 , "value" : 6.7 , "button_press" : False }],
146+ )
138147 call_arguments = cursor .execute .call_args .args
139148 stmt = call_arguments [0 ]
140149 values = call_arguments [1 ]
141- assert stmt == "INSERT INTO temperature (ts, payload) (SELECT col1, col2 FROM UNNEST(?,?))"
142- assert values == ([1586327807000 ], [{"plant" : 1 , "line" : 1 , "sensor_id" : 1 , "value" : 6.7 , "button_press" : False }])
150+ assert (
151+ stmt
152+ == "INSERT INTO temperature (ts, payload) (SELECT col1, col2 FROM UNNEST(?,?))"
153+ )
154+ assert values == (
155+ [1586327807000 ],
156+ [{"plant" : 1 , "line" : 1 , "sensor_id" : 1 , "value" : 6.7 , "button_press" : False }],
157+ )
143158
144159
145- @mock .patch .object (client , ' connect' , autospec = True )
160+ @mock .patch .object (client , " connect" , autospec = True )
146161def test_execute_query (mock_connect ):
147162 """
148163 This function tests if the .execute_query() functions of CrateDbWriter uses the correct query
0 commit comments