Giter VIP home page Giter VIP logo

Comments (8)

seapagan avatar seapagan commented on June 16, 2024 1

This is planned.

I have this functionality already written (but commented out) in the conftest.py, and the settings.py is set up to read test database variables from the environment :

# Setup the TEST Postgresql database.
test_db_user = "my_db_username"
test_db_password = "Sup3rS3cr3tP455w0rd"
test_db_address = "localhost"
test_db_port = "5432"
test_db_name = "api-template-test"

SQLite is a much easier system to set up as most users don't have a local Postgres database (yes, Docker makes that easier but again not everyone uses, can use, even or wants to use that).

I have been (and still am) concentrating on writing the tests. Once that is done, I will open the option to use Postgres for testing myself 👍

from fastapi-template.

seapagan avatar seapagan commented on June 16, 2024 1

Just an update on this ticket.

I'm working on PR #140, converting the database system to SQLAlchemy ORM (from encode/databases), which seems a better and more maintained way of getting Async database usage. I've also upgraded to SQLAlchemy 2.0, necessitating some fair code changes.

I'm currently working on getting the tests running. When that is merged, I'll back-port the Postgres testing from #125 as well which should finally close this ticket.

from fastapi-template.

seapagan avatar seapagan commented on June 16, 2024

I was thinking about this just now as my brain was idling while boiling the kettle.

GitHub has the ability to run a Postgresql service during a GitHub action, so I can update the Tests Action to create and use this. A simple check in the conftest.py can detect if running under CI and switch to using that Postgres service.

I prefer to keep the local tests running SQLite by default - all access goes through the same ORM commands regardless of whether we are using Postgres or SQLite. The ORM maintainer updates the relevant driver as needed so there should not be breaking changes (and if so the online CI would catch it). The simple fact is not everyone can run a local Postgresql server or Docker.

However, I also will add an env variable like FORCE_TEST_POSTGRESQL or whatever that will switch to using Postgresql locally as well and can be picked up by the Docker container.

I also plan to remove all TEST_DB_xxx variables except the TEST_DB_NAME, since they should be the same anyway.

Let me know if you see any issues with this, I'll prob get this into a feature branch and PR tomorrow

from fastapi-template.

seapagan avatar seapagan commented on June 16, 2024

All the above was easily done, Postgres is working fine on GitHub actions and the tests will use it if in CI or the variable TEST_WITH_POSTGRES is True.
The issue is that many tests fail (or async hang) under Postgres either locally or remotely. 😭

It is not an issue with the test cases or database incompatibility, but the way I am using async tests with the patched database. Hope to fix this today depending on time.

GitHub has the ability to run a Postgresql service during a GitHub action, so I can update the Tests Action to create and use this. A simple check in the conftest.py can detect if running under CI and switch to using that Postgres service.

I prefer to keep the local tests running SQLite by default - all access goes through the same ORM commands regardless of whether we are using Postgres or SQLite. The ORM maintainer updates the relevant driver as needed so there should not be breaking changes (and if so the online CI would catch it). The simple fact is not everyone can run a local Postgresql server or Docker.

However, I also will add an env variable like FORCE_TEST_POSTGRESQL or whatever that will switch to using Postgresql locally as well and can be picked up by the Docker container.

I also plan to remove all TEST_DB_xxx variables except the TEST_DB_NAME, since they should be the same anyway.

from fastapi-template.

pdrivom avatar pdrivom commented on June 16, 2024

Hey @seapagan, yeah, I remember that, while playing around with tests.

Let me know if you need some help/ideas.

from fastapi-template.

seapagan avatar seapagan commented on June 16, 2024

Hey @seapagan, yeah, I remember that, while playing around with tests.

Let me know if you need some help/ideas.

I got sidetracked over the weekend on other projects and also completing #126 and implementing #127 (discussion at #128),

It's prob a simple fix to the get_db fixture and database provisioning, I hope to get back to this PR soonest.

from fastapi-template.

seapagan avatar seapagan commented on June 16, 2024

Another update 😁

GitHub actions are working fine on the 'develop' branch under Postgres. However, the Integration tests are turned off until I fix a few issues (Unit tests ok). I am overhauling the pytest setup/teardown config. I should get that sorted when I have time to work on it.

from fastapi-template.

seapagan avatar seapagan commented on June 16, 2024

This has been completed with the 0.5.0 release. closing.

from fastapi-template.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.