Skip to content

Commit 0d5acb9

Browse files
author
marter11
committed
shared functions
1 parent 9871df7 commit 0d5acb9

File tree

10 files changed

+46
-33
lines changed

10 files changed

+46
-33
lines changed

src/tests/api/models/test_FeedbackFlow.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/tests/api/models/test_UserModel.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/tests/api/views/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import sys
22
import os
33

4-
# sys.path.insert(0, os.getcwd()+'/src')
4+
sys.path.insert(0, os.getcwd()+'/src')
55

66
from api import app
77
from api.models import db
88
from api.models import User, Project, UserFeedback, ProjectFeedback, UserLink, ProjectLink
99

10-
# sys.path.insert(0, os.getcwd()+'/tests')
10+
sys.path.insert(0, os.getcwd()+'/tests')
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
44
Creates valid model objects for testing purposes:
55
6-
- these functions will give back the object's id
6+
- insert data to the database which could be used for testing
77
8-
- if you want to access the object properties, then run a query on the model with the given id
9-
example: User.query.filter_by(id=returned_id)
8+
- these functions will give back the created objects in dict format which is hardcoded at every model's as_dict instance method
109
11-
12-
-Call these function form any test case.
10+
- call these functions form any test case.
1311
1412
"""
1513

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,34 @@ def test_get_all_users(self, client):
8383
response = client.get('/users')
8484
assert response.status_code == 200
8585
assert response.get_json() == [users_dict[1]]
86+
87+
# notice: Why do we need name in UserLink?
88+
# notice: Won't the API will provide the UserLink, then why the endpoint expects a UserLink specification?
89+
def test_create_user_link(self, client):
90+
user = create_user_for_test_cases(self.valid_data)
91+
url = '/users/{}/links'.format(user["id"])
92+
93+
response = client.post(url, json={"user_id": user["id"]})
94+
assert response.status_code == 400
95+
96+
# response = client.post(url, )
97+
# assert 1 == 1
98+
99+
def test_create_user_feedback(self, client):
100+
user1 = create_user_for_test_cases(self.valid_data)
101+
102+
self.valid_data["name"] = "Other name"
103+
user2 = create_user_for_test_cases(self.valid_data)
104+
105+
url = '/users/{}/feedbacks'.format(user2["id"])
106+
response = client.post(url, json={"user_id": user2["id"]})
107+
assert response.status_code == 400
108+
109+
feedback = {
110+
"author_id": int(user1["id"]),
111+
"rating": 5,
112+
"description": "Cool guy!",
113+
}
114+
115+
response = client.post(url, json=feedback)
116+
assert response.status_code == 201
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import pytest
2-
from sqlalchemy_utils import database_exists, create_database
3-
from os import environ
4-
from tests import app, db
51

62
"""
73
4+
When the testing process is starting this file will run at first.
5+
6+
This should contain all the neccessary functions for the test flow or at least should be imported here.
7+
88
"""
99

10+
import pytest
11+
from sqlalchemy_utils import database_exists, create_database
12+
from os import environ
13+
from tests import app, db
14+
15+
# Provide default test client for testing endpoints
1016
@pytest.fixture
1117
def client():
1218

File renamed without changes.

0 commit comments

Comments
 (0)