def test_writes_single_value_all_args(self): values = [1, 2] when2(wm.write_query, "foo", ANY).thenReturn(True) wm.write_multiple_values("foo", values, measurement=["bar", "bar"], value_name=["my_val", "my_val"]) verify(wm, 2).write_query("foo", any)
def test_do_not_resolve_register(self): expected_query = "select from test_measurement where register = 'freshAirIntake'" when2(rm.read_query, "test", expected_query).thenReturn("success!") output = rm.read_data("test", measurement="test_measurement", register="freshAirIntake" ) self.assertEqual(output, "success!")
def test_only_end_set(self): expected_query = "select from test_measurement where register = '201' AND time < 1ms" when2(rm.read_query, "test", expected_query).thenReturn("success!") output = rm.read_data("test", measurement="test_measurement", register="freshAirIntake", resolve_register="True", end_utc=1 ) self.assertEqual(output, "success!")
def test_all_values_in_args(self): expected_query = "select from test_measurement where register = '201' AND time > 1ms AND time < 2ms" when2(rm.read_query, "test", expected_query).thenReturn("success!") output = rm.read_data("test", measurement="test_measurement", register="freshAirIntake", resolve_register="True", start_utc=1, end_utc=2 ) self.assertEqual(output, "success!")
def test_writes_single_value_no_time(self): expected_json = { 'measurement': "bar", "time": int(calendar.timegm(time.gmtime())), "fields": { "my_val": 1.0 } } when2(wm.write_query, "foo", expected_json).thenReturn(True) wm.write_single_value("foo", "1.0", measurement="bar", value_name="my_val") verify(wm).write_query("foo", any)
def test_writes_single_value_all_args(self): expected_json = { 'measurement': "bar", "time": 1, "fields": { "my_val": 1.0 } } when2(wm.write_query, "foo", expected_json).thenReturn(True) wm.write_single_value("foo", "1.0", measurement="bar", value_name="my_val", time_utc=1) verify(wm).write_query("foo", expected_json)
def test_adds_all_values(self): test_result_set = ResultSet({ "time": 1, "message": "success!" }) when2(test_result_set.get_points).thenReturn({ "time": 1, "message": "success!" }) test_dataframe = pandas.DataFrame({'time': [1], 'message': ['success!']}) when2(InfluxDBClient.query, "test_measurement").thenReturn(test_result_set) when2(pandas.DataFrame, {"time": 1, "message": "success!"}).thenReturn(test_dataframe) output = rm.read_query("test", "test_measurement") self.assertEqual(len(output["message"]), 1) self.assertTrue("success!" in output["message"]["1970-01-01 00:00:00.000000001"])
def test_throws_exception(self): when2(wm.write_query, "foo", ANY).thenReturn(True) with self.assertRaises(ValueError): wm.write_multiple_values("foo", [1, 2], value_name=["my_val"])