from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from pydantic.dataclasses import dataclass
# Create engine and session
engine = create_engine('sqlite:///example.db')
Session = sessionmaker(bind=engine)
session = Session()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| class TState: | |
| def __new__(cls): | |
| if not hasattr(cls, "instance"): | |
| cls.instance = super(TState, cls).__new__(cls) | |
| return cls.instance | |
| def add(self, name, value): | |
| setattr(self, name, value) |
There are a few options how to change app config for tests. According to FastAPI docs, it's recommended to use `dependency_overrides`, but there might be a case where we need to change the entire app settings (using Pydantic's BaseSettings here).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlalchemy import TIMESTAMP, UUID, Column | |
| from sqlalchemy.orm import declarative_mixin | |
| from sqlalchemy.orm import declarative_base | |
| # MIXINS: | |
| @declarative_mixin | |
| class IDMixin: | |
| id = Column(UUID, primary_key=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| command: | |
| [ | |
| "/bin/sh", | |
| "-c", | |
| "cd /workspace ; poetry install ; while sleep 1000; do :; done" | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def run_script_in_container(script_name: str, console_output: bool = False) -> str | None: | |
| """Run script within the devcontainer to gather application metadata.""" | |
| # Add Python file suffix if not present | |
| if script_name[-3:] != ".py": | |
| script_name = f'{script_name}.py' | |
| # Command | |
| cmd = ['python', f'/workspace/scripts/{script_name}'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def extract_files_from_xml(xml_element: etree.Element) -> list[BytesIO]: | |
| """Extract files from XML element""" | |
| output = [] | |
| elements_with_file = ["bArray", "ByteArray"] | |
| for file_element in elements_with_file: | |
| # Locate element |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Black watcher: | |
| Program: $PyInterpreterDirectory$/black | |
| Arguments: $FilePath$ | |
| Output paths to refresh: $FilePath$ | |
| Working directory: $ProjectFileDir$ | |
| iSort watcher: | |
| Program: $PyInterpreterDirectory$/isort | |
| Arguments: $FilePath$ | |
| Output paths to refresh: $FilePath$ |
NewerOlder