Skip to content

Commit 3cac3c1

Browse files
author
marter11
committed
initial testing setup
1 parent fdb4ad6 commit 3cac3c1

File tree

8 files changed

+132
-3
lines changed

8 files changed

+132
-3
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ flask-dance = "*"
1515
pyopenssl = "*"
1616
flask-swagger = "*"
1717
flask-swagger-ui = "*"
18+
pytest = "*"
1819

1920
[requires]
2021
python_version = "3.7"

Pipfile.lock

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

src/tests/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
from sqlalchemy_utils import database_exists, create_database
3+
from api import app
4+
from api.models import db
5+
from api.models import User
6+
from os import environ
7+
8+
"""
9+
todo: change this importing solution if the tests/ won't be under src/
10+
import sys
11+
import os
12+
sys.path.insert(0, os.getcwd()+'/src')
13+
import api
14+
sys.path.insert(0, os.getcwd()+'/tests')
15+
"""
16+
17+
@pytest.fixture
18+
def client():
19+
20+
# delete table entries before each test
21+
for model in db.Model._decl_class_registry.values():
22+
try:
23+
db.session.query(model).delete()
24+
db.session.commit()
25+
except:
26+
pass
27+
28+
with app.test_client() as test_client:
29+
yield test_client

src/tests/api/views/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from tests import client
2+
3+
def test_create_project(client):
4+
response = client.get('/projects')
5+
assert response.status_code == 405
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from tests import client
2+
3+
def test_create_user(client):
4+
send_data = {
5+
'name': 'L Jone',
6+
'bio': 'coding...',
7+
'languages': 'FR',
8+
'interests': 'Nothing',
9+
'location': 'X',
10+
'occupation': 'cashier'
11+
}
12+
13+
response = client.post('/users', json=send_data)
14+
assert response.status_code == 201
15+
# assert response.get_json() ==

src/tests/runtests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
response = """
2+
3+
Use: pipenv run pytest src/tests/
4+
5+
"""
6+
7+
print(response)

0 commit comments

Comments
 (0)