Skip to content

Commit 3ccbc09

Browse files
committed
wrote tests for signup and login
1 parent 7f37a40 commit 3ccbc09

File tree

9 files changed

+72
-24
lines changed

9 files changed

+72
-24
lines changed

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: python
2+
3+
python:
4+
- '3.6'
5+
6+
install:
7+
- pip install pipenv
8+
- pipenv install
9+
10+
services:
11+
- postgresql
12+
13+
before_script:
14+
- psql -c 'create database diary_test;' -U postgres
15+
- pipenv run python3 manage.py db upgrade
16+
17+
script:
18+
- pipenv run pytest

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ verify_ssl = true
66
[dev-packages]
77
autopep8 = "*"
88
pep8 = "*"
9-
pytest = "==5.1.3"
109

1110
[packages]
11+
pytest = "==5.1.3"
1212
alembic = "==1.0.10"
1313
aniso8601 = "==6.0.0"
1414
appdirs = "==1.4.3"

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: gunicorn app:app
2+
release: python manage.py db upgrade

app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ def handle_exception(error):
5656
return app
5757

5858

59-
app = create_app(os.getenv("FLASK_ENV") or "dev")
60-
app.app_context().push()
59+
# app = create_app(os.getenv("FLASK_ENV") or "dev")
60+
# app.app_context().push()

conftest.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import pytest
22
from app import create_app, db
3+
from models.diary_model import *
4+
from models.user_model import *
35

4-
5-
@pytest.fixture(scope='module')
6-
def init_db():
7-
# Create the database and the database table
8-
db.create_all()
9-
print("setup DB>>>>>>>")
10-
yield db
11-
print("teardown DB>>>>>>>")
12-
# db.drop_all()
6+
pytest_plugins = [
7+
"test.entities.test_user_resource"
8+
]
139

1410

1511
@pytest.fixture(scope='module')
1612
def client():
1713
app = create_app('test')
18-
with app.test_client() as client:
19-
yield client
14+
testing_client = app.test_client()
15+
16+
with app.app_context():
17+
db.create_all()
18+
yield testing_client
19+
db.session.close()
20+
db.drop_all()

manage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from flask_migrate import Migrate, MigrateCommand
33
from flask_script import Manager
44

5-
from app import app, db
5+
from app import db, create_app
66
from models import user_model, diary_model
77

8+
app = create_app(os.getenv("FLASK_ENV") or "dev")
9+
app.app_context().push()
810

911
manager = Manager(app)
1012
migrate = Migrate(app, db)

test/entities/test_user_resource.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@
22

33

44
class TestUserResourceEndpoints:
5-
def test_user_signup(self, client, init_db):
6-
# response = client.post('/api/v1/auth/signup', data=json.dumps({
7-
# "email": "blah@blah.com",
8-
# "password": "inflames",
9-
# "fullname": "Jesse James"
10-
# }))
11-
# print(response.data.decode('utf-8'))
12-
assert 1 == 1
13-
# print(init_db)
5+
def test_user_signup_successfull(self, client, ):
6+
'''' Test for a successful user signup'''
7+
8+
response = client.post('/api/v1/auth/signup', data=json.dumps({
9+
"email": "blah@blah.com",
10+
"password": "inflames",
11+
"fullname": "Jesse James"
12+
}))
13+
14+
resp = response.get_json()
15+
assert response.status_code == 201
16+
assert resp['message'] == "Your account has been created successfully"
17+
assert resp['data']['email'] == "blah@blah.com"
18+
assert resp['data']['fullname'] == "Jesse James"
19+
20+
def test_user_login_successful(self, client):
21+
'''' Test for a successful user login'''
22+
23+
response = client.post('/api/v1/auth/login', data=json.dumps({
24+
"email": "blah@blah.com",
25+
"password": "inflames",
26+
}))
27+
28+
resp = response.get_json()
29+
assert response.status_code == 200
30+
assert resp['message'] == 'Logged in successfuly'
31+
assert 'token' in resp['data'].keys()
File renamed without changes.

test/fixtures/user_fixtures.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
from models.user_model import User
3+
4+
5+
@pytest.fixture(scope='module')
6+
def new_user():
7+
pass

0 commit comments

Comments
 (0)