async def _submit_new_event(self, memo_dict): answer = 'New event was successfully created 🎉' await telegram_bot.send_message( chat_id=self.chat.user_id, text=answer) # Save to database create_event( db=next(get_db()), title=memo_dict['title'], start=memo_dict['start'], end=memo_dict['end'], content=memo_dict['content'], owner_id=self.user.id, location=memo_dict['location'], ) # Delete current session del telegram_bot.MEMORY[self.chat.user_id] return answer
def test_session_db(): assert get_db() is not None
def test_get_db(): assert isinstance(next(get_db()), Session)
app.mount("/media", StaticFiles(directory=MEDIA_PATH), name="media") app.logger = logger app.add_exception_handler(status.HTTP_401_UNAUTHORIZED, auth_exception_handler) # This MUST come before the app.routers imports. set_ui_language() from app.routers import ( # noqa: E402 about_us, agenda, calendar, categories, celebrity, credits, currency, dayview, email, event, export, four_o_four, friendview, google_connect, invitation, login, logout, profile, register, search, telegram, user, weekview, whatsapp, ) json_data_loader.load_to_database(next(get_db())) @app.get("/docs", include_in_schema=False) async def custom_swagger_ui_html(): return get_swagger_ui_html( openapi_url=app.openapi_url, title=app.title + " - Swagger UI", oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url, swagger_js_url="/static/swagger/swagger-ui-bundle.js", swagger_css_url="/static/swagger/swagger-ui.css", ) @app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False) async def swagger_ui_redirect():
import os from app.database import engine, Base from app.dependencies import get_db from app.garments import crud import requests Base.metadata.create_all(bind=engine) db = next(get_db()) all_garments = crud.get_garments(db) for garment in all_garments: id = garment.id print(f"The id is :{id}") print(f"Does {id}.png exist?") try: with open(f"images/{id}.png", "rb") as f: print("YES") print("Uploading image") response = requests.post( url=os.getenv("IMAGES_SERVICE_ENDPOINT") + "/image", files={"media": f.read()}, ) print(response.text) location = response.headers["location"] garment.image = location db.commit() print(location) except IOError: print("It does not exist") name = garment.name