Skip to content
This repository was archived by the owner on Dec 19, 2021. It is now read-only.

Commit 74bf86e

Browse files
authored
Merge branch 'development' into issue526-ticket-author
2 parents e9017c3 + 2a0cdfe commit 74bf86e

File tree

7 files changed

+68
-64
lines changed

7 files changed

+68
-64
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
SECRET_KEY='dwellingly'
22
PYTHONPATH=${PWD}:${PYTHONPATH}
3+
4+
# To set the database to postgresql. Uncomment the env vars below
5+
# DEV_DATABASE_URL=postgresql://localhost/dwellingly_development
6+
# TEST_DATABASE_URL=postgresql://localhost/dwellingly_test

.github/workflows/pytest.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,31 @@ on:
88
branches:
99
- development
1010

11+
12+
env:
13+
POSTGRES_HOST_AUTH_METHOD: trust
14+
PGUSER: postgres
15+
PGHOST: localhost
16+
SECRET_KEY: dwellingly
17+
TEST_DATABASE_URL: postgresql://localhost/dwellingly_test
18+
FLASK_ENV: testing
19+
1120
jobs:
1221
pytest:
1322

1423
runs-on: ubuntu-latest
15-
env:
16-
SECRET_KEY: dwellingly
24+
services:
25+
postgres:
26+
image: postgres
27+
env:
28+
POSTGRES_HOST_AUTH_METHOD: trust
29+
ports:
30+
- 5432:5432
31+
options: >-
32+
--health-cmd pg_isready
33+
--health-interval 10s
34+
--health-timeout 5s
35+
--health-retries 5
1736
1837
steps:
1938
- uses: actions/checkout@v2
@@ -25,8 +44,8 @@ jobs:
2544
- name: Install dependecies
2645
run: pipenv run dev-install
2746

28-
- name: Setup Database
29-
run: pipenv run flask db create
47+
- name: Create db
48+
run: createdb dwellingly_test
3049

3150
- name: Test
3251
run: |

CONTRIBUTING.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ A resource's main job is to coordinate a response for the incoming request. If d
6363
Each resource will usually have one test for each action (GET, POST, DELETE, etc...). When the Models and Schemas have unit tests, and when the resource uses the models and schemas appropriately, then **generally** only a successful response (The Happy Path) needs to be tested. All other responses that can occur are already tested elsewhere, including validation errors or database rows that cannot be found. Errors such as these should not be tested, as they're already built into the architecture of the app and happen automatically as long as the schemas are used along with the appropriate methods defined in the BaseModel. Tests for the resources can be found in the `tests/integration` directory.
6464

6565
## Installation
66-
Set up Dwelling Flask Testing Backend (for the first time)
67-
NOTE: Database is SQLite3 via SQLAlchemy
66+
NOTE: Default development database is SQLite3. (Optionally setup and use [PostgreSQL](#PostgreSQL-Setup) as the database.)
6867

6968
[Note for Windows users](#Note-For-Windows-Users)
7069

@@ -110,6 +109,17 @@ NOTE: Database is SQLite3 via SQLAlchemy
110109
Queries can be made with the Postman Collection link ( https://www.getpostman.com/collections/a86a292798c7895425e2 )
111110
[![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/0078de8f58d4ea0b78eb)
112111

112+
### PostgreSQL Setup
113+
1. Install [PostgreSQL](https://www.postgresql.org/download/).
114+
2. Manually create the database.
115+
- From a linux or mac command line run the following:
116+
```shell
117+
createdb dwellingly_development
118+
createdb dwellingly_test
119+
```
120+
3. Open up `.env` and uncomment the `DEV_DATABASE_URL` and `TEST_DATABASE_URL` env vars.
121+
4. Run `pipenv run flask db create`.
122+
113123
### Note For Windows Users
114124

115125
Python does not come by default for Windows users. Sometimes the PATH variable in Windows will point to the wrong path and you will have trouble running the `python` and `pipenv` commands. If you don't have Python installed then follow these steps. If the steps listed above did not work for you, try the following.
@@ -130,7 +140,7 @@ If you don't see something similar, you may have several versions of Python inst
130140

131141
### Database migrations.
132142

133-
Database migrations are not used for development. Please ignore do not use migrations during development.
143+
Database migrations are currently not used. We will start using them soon.
134144

135145
Database migrations are managed through [Alembic](https://alembic.sqlalchemy.org/en/latest/index.html). After making a change to a model, a database migration is necessary.
136146

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ PyJWT = "==2.1.0"
2828
Werkzeug = "==2.0.1"
2929
Flask-Mailman = "==0.2.4"
3030
Flask-Cors = "*"
31-
psycopg2-binary = "*"
3231
bcrypt = "==3.2.0"
3332
flask-marshmallow = "*"
3433
marshmallow-sqlalchemy = "*"
3534
alembic = "*"
35+
psycopg2 = "*"
3636

3737
[requires]
3838
python_version = "3.8"

Pipfile.lock

Lines changed: 24 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Default(object):
2727

2828

2929
class Development(Default):
30-
SQLALCHEMY_DATABASE_URI = os.environ.get(
30+
SQLALCHEMY_DATABASE_URI = os.getenv(
3131
"DEV_DATABASE_URL"
3232
) or "sqlite:///" + os.path.join(basedir, "data-dev.sqlite")
3333
JWT_ACCESS_TOKEN_EXPIRES = False
@@ -40,7 +40,7 @@ class Development(Default):
4040

4141
class Testing(Default):
4242
TESTING = True
43-
SQLALCHEMY_DATABASE_URI = os.environ.get("TEST_DATABASE_URL") or "sqlite://"
43+
SQLALCHEMY_DATABASE_URI = os.getenv("TEST_DATABASE_URL") or "sqlite://"
4444
WORK_FACTOR = 4
4545
JWT_ACCESS_TOKEN_EXPIRES = False
4646
JWT_REFRESH_TOKEN_EXPIRES = False

conftest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ def _pm_header(pm=None):
7171

7272
@pytest.fixture
7373
def empty_test_db(app):
74-
db.create_all()
75-
76-
yield
77-
7874
db.drop_all()
75+
db.create_all()
7976

8077

8178
# ------------- NON-FIXTURE FUNCTIONS --------------------

0 commit comments

Comments
 (0)