Skip to content

Commit

Permalink
Change id to element_id for Cypher queries.
Browse files Browse the repository at this point in the history
Update `test_register` and auth `resgister` route
  • Loading branch information
DMalone87 committed Oct 13, 2024
1 parent a8a48ae commit c15f16f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion backend/routes/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def register():
missing_fields.append(key)
return {
"status": "Unprocessable Entity",
"message": "Failed to register. Please include the following"
"message": "Invalid request body. Please include the following"
" fields: " + ", ".join(missing_fields),
}, 422

Expand Down
12 changes: 6 additions & 6 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ def app(test_db_driver):

# This function must be called for every new test node created
def add_test_label(node):
query = "MATCH (n) WHERE id(n) = $node_id SET n:TestData"
params = {'node_id': node.id}
query = "MATCH (n) WHERE elementId(n) = $node_id SET n:TestData"
params = {'node_id': node.element_id}
db.cypher_query(query, params)


# This function must be called for every new test relationship created
def add_test_property_to_rel(start_node, rel_type, end_node):
query = f"""
MATCH (a)-[r:{rel_type}]-(b)
WHERE id(a) = $start_id AND id(b) = $end_id
WHERE elementId(a) = $start_id AND elementId(b) = $end_id
SET r.test_data = true
"""
params = {
'start_id': start_node.id,
'end_id': end_node.id
'start_id': start_node.element_id,
'end_id': end_node.element_id
}
db.cypher_query(query, params)

Expand Down Expand Up @@ -153,7 +153,7 @@ def example_partner_member(example_user: User):
contact_email="[email protected]",
member_association=[
PartnerMember(
user_id=example_user.id,
user_id=example_user.uid,
role=MemberRole.MEMBER.value,
date_joined=datetime.now(),
is_active=True,
Expand Down
17 changes: 9 additions & 8 deletions backend/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
],
)
def test_register(
db_session, client, email, password,
db_session, client, example_user, email, password,
firstname, lastname, phone_number,
expected_status_code
):
if email == "[email protected]":
email = example_user.email
res = client.post(
"api/v1/auth/register",
json={
Expand All @@ -35,9 +37,8 @@ def test_register(
assert res.status_code == expected_status_code

if expected_status_code == 200:
assert res.json["status"] == "ok"
assert res.json["status"] == "OK"
assert res.json["message"] == "Successfully registered."
assert res.json["access_token"] == "mocked_access_token"
assert "Set-Cookie" in res.headers
elif expected_status_code == 409 and email == "[email protected]":
assert res.json["status"] == "Conflict"
Expand All @@ -55,7 +56,7 @@ def test_register(
[("my_password", 200), ("bad_password", 401), (None, 422)],
)
def test_login(
mock_db_session,
db_session,
client, example_user, password, expected_status_code
):
with patch('backend.database.User.get_by_email') as mock_get_by_email:
Expand All @@ -73,7 +74,7 @@ def test_login(
assert res.status_code == expected_status_code


def test_jwt(client, mock_db_session, example_user, mock_access_token):
def test_jwt(client, db_session, example_user, mock_access_token):
with patch('backend.database.User.nodes.get_or_none') as mock_get_or_none, \
patch('flask_jwt_extended.decode_token') as mock_decode_token:

Expand All @@ -98,7 +99,7 @@ def test_jwt(client, mock_db_session, example_user, mock_access_token):


def test_auth_test_header(
mock_db_session, client, example_user, mock_access_token):
db_session, client, example_user, mock_access_token):
login_res = client.post(
"api/v1/auth/login",
json={"email": example_user.email, "password": "my_password"},
Expand All @@ -118,7 +119,7 @@ def test_auth_test_header(
assert test_res.status_code == 200


def test_auth_test_cookie(mock_db_session, client, example_user):
def test_auth_test_cookie(db_session, client, example_user):
client.post(
"api/v1/auth/login",
json={"email": example_user.email, "password": "my_password"},
Expand All @@ -133,7 +134,7 @@ def test_auth_test_cookie(mock_db_session, client, example_user):
assert test_res.status_code == 200


def test_access_token_fixture(mock_db_session, mock_access_token):
def test_access_token_fixture(db_session, mock_access_token):
assert len(mock_access_token) > 0


Expand Down

0 comments on commit c15f16f

Please sign in to comment.