def test_get_template_id_from_db(self, _mock_api, mock_redis): """ Should get the template ID from the database. """ mock_redis.Redis().get = MagicMock(return_value=b"2") client = RedisClient() template_id = client.get_template_id() mock_redis.Redis().get.assert_called_once() mock_redis.Redis().get.assert_called_with("template_id") self.assertEqual(template_id, "2")
def test_get_template_id_from_db(self, mock_api, _mock_redis, mock_uuid): """ Should get the template ID from the database. """ mock_api.create_device = MagicMock(return_value="4") mock_uuid.return_value = "test-UUID" client = RedisClient() client.get_template_id = MagicMock(return_value="3") client.get_jwt = MagicMock(return_value="testJWT") device_id = client.get_device_id() client.get_template_id.assert_called_once() mock_api.create_device.assert_called_once_with( "testJWT", "3", "CargoContainer_testUUID") self.assertEqual(device_id, "4")
def test_create_new_template(self, mock_api, mock_redis): """ Should create a new template. """ mock_redis.Redis().get = MagicMock(return_value=b"-1") mock_redis.Redis().set = MagicMock() mock_api.create_template = MagicMock(return_value="1") client = RedisClient() client.get_jwt = MagicMock(return_value="testJWT") template_id = client.get_template_id() mock_redis.Redis().get.assert_called_once() mock_redis.Redis().get.assert_called_with("template_id") mock_api.create_template.assert_called_once() mock_api.create_template.assert_called_with("testJWT") mock_redis.Redis().set.assert_called_once() mock_redis.Redis().set.assert_called_with("template_id", "1") self.assertEqual(template_id, "1")