def test_laod_data_read_data(self): client1 = Client(self.host, self.port, timeout=5) client2 = Client(self.host, self.port, timeout=5) try: client1.put("k.1", 0.25, timestamp=1) client2.put("k.1", 2.156, timestamp=2) client1.put("k.1", 0.35, timestamp=3) client2.put("k.2", 30, timestamp=4) client1.put("k.2", 40, timestamp=5) client1.put("k.2", 41, timestamp=5) except Exception as err: self.assertTrue( False, f"Ошибка вызова client.put(...) {err.__class__}: {err}") expected_metrics = { "k.1": [(1, 0.25), (2, 2.156), (3, 0.35)], "k.2": [(4, 30.0), (5, 41.0)], } #import pdb; pdb.set_trace() metrics = client1.get("*") self.assertTrue(metrics == expected_metrics) expected_metrics = {"k.2": [(4, 30.0), (5, 41.0)]} metrics = client2.get("k.2") self.assertTrue(metrics == expected_metrics) expected_metrics = {} metrics = client1.get("k.3") self.assertTrue(metrics == expected_metrics)
def test_put_cmd_bad_timestamp(self): key = 'cpu.cpu' bad_stamps = [-100, -1, 0] value = 2 client = Client() for bad_stamp in bad_stamps: with self.assertRaises(ClientError): client.put(key, value, bad_stamp)
def test_put_cmd_bad_key(self): bad_keys = ['cpucpu', 'cpu cpu', 'cpu.cpu.cpu', None, '*'] value = 2 timestamp = 1 client = Client() for bad_key in bad_keys: with self.assertRaises(ClientError): client.put(bad_key, value, timestamp)
def test_put_cmd_bad_value(self): key = 'cpu.cpu' timestamp = 132432 bad_values = ['434', 'fdf', '', None, 2 + 3j] client = Client() for bad_value in bad_values: with self.assertRaises(ClientError): #import pdb; pdb.set_trace() client.put(key, bad_value, timestamp)
def test_put_cmd_good_args(self): keys = ['cpu.usage', 'cpu.temp', 'mem.usage'] timestamps = [132432, 4324, 432432432] values = [1, 2, 35, 2.0, -5.0, 1e6, -1e-5, -1e10] client = Client() for key in keys: for value in values: for timestamp in timestamps: try: client.put(key, value, timestamp) except ClientError: self.assertTrue(False)
def test_put_sends_byte_str_command(self): key = 'cpu.cpu' value = 54.0 timestamp = 5435433 cmd_bytes = 'put {} {:} {:d}\n'.format(key, str(value), timestamp).encode() client = Client() #import pdb; pdb.set_trace() client.put(key, value, timestamp) sock_instance = self.MockClass.return_value sock_instance.connect.assert_called() first_call = 0 positional_args = 0 call_args = sock_instance.sendall.call_args_list[first_call][ positional_args] sended_str = call_args[0] #import pdb; pdb.set_trace() self.assertTrue(cmd_bytes == sended_str)