diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 6a1def0..0d43231 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -13,6 +13,7 @@ def move_db_files(db_resource: str): """ if "postgres" in db_resource: + logging.debug("Postgres selected. Renaming postgres files") shutil.move( "src/db/postgres_models.py", "src/flask/flaskapp/models.py" @@ -21,7 +22,15 @@ def move_db_files(db_resource: str): "src/db/postgres_seeder.py", "src/flask/flaskapp/seeder.py", ) + shutil.move( + ".github/workflows/test_postgres.yml", + ".github/workflows/test.yml" + ) + else: + pathlib.Path(".github/workflows/test_postgres.yml").unlink() + if "mongo" in db_resource: + logging.debug("MongoDB selected. Renaming MongoDB files") shutil.move( "src/db/mongo_models.py", "src/flask/flaskapp/models.py" @@ -30,7 +39,12 @@ def move_db_files(db_resource: str): "src/db/mongo_seeder.py", "src/flask/flaskapp/seeder.py", ) - + shutil.move( + ".github/workflows/test_mongodb.yml", + ".github/workflows/test.yml" + ) + else: + pathlib.Path(".github/workflows/test_mongodb.yml").unlink() def remove_aca_files() -> None: """Removes unneeded files if aca is not selected""" file_names = ( diff --git a/{{cookiecutter.__src_folder_name}}/.github/workflows/test_mongodb.yml b/{{cookiecutter.__src_folder_name}}/.github/workflows/test_mongodb.yml new file mode 100644 index 0000000..0c46e29 --- /dev/null +++ b/{{cookiecutter.__src_folder_name}}/.github/workflows/test_mongodb.yml @@ -0,0 +1,61 @@ +name: Run Python E2E tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test_package: + {% raw %} + name: Test ${{ matrix.os }} Python ${{ matrix.python_version }} + runs-on: ${{ matrix.os }} + {% endraw %} + strategy: + fail-fast: false + matrix: + os: ["ubuntu-20.04"] + python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + services: + db: + {% if "mongo" in cookiecutter.db_resource %} + image: mongo:4.2.24 + ports: + - 27017:27017 + env: + MONGO_INITDB_ROOT_USERNAME: mongodb + MONGO_INITDB_ROOT_PASSWORD: mongodb + MONGO_INITDB_DATABASE: relecloud + options: >- + --health-cmd mongo + --health-start-period 20s + --health-interval 10s + --health-timeout 5s + --health-retries 5 + {% endif %} + steps: + - uses: actions/checkout@v3 + - name: Setup python + uses: actions/setup-python@v2 + with: + {% raw %} + python-version: ${{ matrix.python_version }} + architecture: x64 + {% endraw %} + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements-dev.txt + playwright install chromium --with-deps + python3 -m pip install -e src + - name: Seed data and run Pytest tests + run: | + python3 -m flask --app src.flaskapp seed --filename="src/seed_data.json" --drop + python3 -m pytest + env: + MONGODB_HOST: localhost + MONGODB_USERNAME: mongodb + MONGODB_PASSWORD: mongodb + MONGODB_DATABASE: relecloud + MONGODB_PORT: 27017 diff --git a/{{cookiecutter.__src_folder_name}}/.github/workflows/tests.yml b/{{cookiecutter.__src_folder_name}}/.github/workflows/test_postgres.yml similarity index 64% rename from {{cookiecutter.__src_folder_name}}/.github/workflows/tests.yml rename to {{cookiecutter.__src_folder_name}}/.github/workflows/test_postgres.yml index 9b32140..d1931e8 100644 --- a/{{cookiecutter.__src_folder_name}}/.github/workflows/tests.yml +++ b/{{cookiecutter.__src_folder_name}}/.github/workflows/test_postgres.yml @@ -19,22 +19,6 @@ jobs: python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"] services: db: - {% if "mongo" in cookiecutter.db_resource %} - image: mongo:4.2.24 - ports: - - 27017:27017 - env: - MONGO_INITDB_ROOT_USERNAME: mongodb - MONGO_INITDB_ROOT_PASSWORD: mongodb - MONGO_INITDB_DATABASE: relecloud - options: >- - --health-cmd mongo - --health-start-period 20s - --health-interval 10s - --health-timeout 5s - --health-retries 5 - {% endif %} - {% if "postgres" in cookiecutter.db_resource %} image: postgres:14 env: POSTGRES_PASSWORD: postgres @@ -42,7 +26,6 @@ jobs: - 5432:5432 # needed because the postgres container does not provide a healthcheck options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - {% endif %} steps: - uses: actions/checkout@v3 - name: Setup python @@ -67,29 +50,15 @@ jobs: python3 src/manage.py loaddata src/seed_data.json {% endif %} {% if cookiecutter.project_backend == "flask" %} - {% if "postgres" in cookiecutter.db_resource %} python3 -m flask --app src.flaskapp db upgrade --directory src/flaskapp/migrations python3 -m flask --app src.flaskapp seed --filename src/seed_data.json {% endif %} - {% if "mongodb" in cookiecutter.db_resource %} - python3 -m flask --app src.flaskapp seed --filename="src/seed_data.json" --drop - {% endif %} - {% endif %} {% if cookiecutter.project_backend == "fastapi" %} python3 src/fastapi_app/seed_data.py {% endif %} python3 -m pytest env: - {% if "postgres" in cookiecutter.db_resource %} POSTGRES_HOST: localhost POSTGRES_USERNAME: postgres POSTGRES_PASSWORD: postgres - POSTGRES_DATABASE: postgres - {% endif %} - {% if "mongodb" in cookiecutter.db_resource %} - MONGODB_HOST: localhost - MONGODB_USERNAME: mongodb - MONGODB_PASSWORD: mongodb - MONGODB_DATABASE: relecloud - MONGODB_PORT: 27017 - {% endif %} + POSTGRES_DATABASE: postgres \ No newline at end of file