def test_add_service(): serv = Service("service1", "prod", "127.0.0.1", 50001, False) db.clear_services(session, service_table) ok = add_service(session, serv) assert ok services = all_services(session, service_table) assert len(services) == 1
def test_duplicated_service_name_stage(): serv1 = Service("service1", "prod", "127.0.0.1", 50001, False) serv2 = Service("service2", "prod", "127.0.0.1", 50002, True) serv3 = Service("service1", "prod", "127.0.0.1", 50003, False) db.clear_services(session, service_table) ok, error = add_service(session, [serv1, serv2, serv3]) assert not ok assert error.orig.args[0] == 1062 assert "Duplicate" in error.orig.args[1]
def test_add_3service(): serv1 = Service("service1", "prod", "127.0.0.1", 50001, False) serv2 = Service("service2", "prod", "127.0.0.1", 50002, True) serv3 = Service("service3", "prod", "127.0.0.1", 50003, False) db.clear_services(session, service_table) ok = add_service(session, [serv1, serv2, serv3]) assert ok services = all_services(session, service_table) assert len(services) == 3
def test_get_service_by_name_stage(): serv1 = Service("service1", "prod", "127.0.0.1", 50001, False) serv2 = Service("service3", "prod", "127.0.0.1", 50002, True) serv3 = Service("service4", "prod", "127.0.0.1", 50003, False) db.clear_services(session, service_table) ok = add_service(session, [serv1, serv2, serv3]) assert ok service1 = get_service_by_name_stage(session, "service3", "prod") assert len(service1) == 1 assert service1[0].name == "service3"
def test_deactivate_service(): serv1 = Service("service1", "prod", "127.0.0.1", 50001, False) serv2 = Service("service3", "prod", "127.0.0.1", 50002, True) serv3 = Service("service4", "prod", "127.0.0.1", 50003, False) db.clear_services(session, service_table) ok = add_service(session, [serv1, serv2, serv3]) assert ok services = all_services(session, service_table) assert len(services) == 3 ok, error = deactivate_service(session, "service1", "prod") assert ok service1 = get_service_by_name_stage(session, "service1", "prod") assert len(service1) == 1 assert not service1[0].active
async def create_service(service_in: ServiceIn, user_password_hash: str = Depends(get_current_user)): serv = Db_service(service_in.name, service_in.stage, service_in.host, service_in.port, service_in.active) ok, error = add_service(session, serv) if ok: return JSONResponse(status_code=HTTP_201_CREATED, content="Service created") else: error_content = { "success": False, "data": { "name": "Ошибка создания сервиса", "message": error.orig.args[1], "code": error.orig.args[0], "status": HTTP_400_BAD_REQUEST, "params": error.params, } } return JSONResponse(status_code=HTTP_400_BAD_REQUEST, content=error_content)