Skip to content

Commit 1e5462b

Browse files
cyplasdanmash
authored andcommitted
replaced registry cypress tests with equivalent pytest (#402)
1 parent 1ee19f0 commit 1e5462b

File tree

2 files changed

+77
-431
lines changed

2 files changed

+77
-431
lines changed

app/auth/tests/test_auth_routes.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,83 @@ def test_logout(m_unset_jwt_cookies, client):
5353
m_unset_jwt_cookies.assert_called_once()
5454

5555

56+
@pytest.mark.integration
57+
def test_successful_registry_basic(client):
58+
data = get_fake_registration_json()
59+
response = client.post(url_for("auth.register"), json=data)
60+
assert response.status_code == 201
61+
header_map = {name.lower(): value.lower() for (name, value) in response.headers}
62+
assert header_map["access-control-allow-origin"] == "http://0.0.0.0:3000"
63+
assert header_map["content-type"] == "application/json"
64+
assert isinstance(response.json, dict), "Response must be a dict"
65+
assert (
66+
response.json["message"] == "Successfully created user"
67+
), "Response must have appropriate message"
68+
69+
70+
@pytest.mark.integration
71+
def test_successful_registry_second_user(client):
72+
client.post(
73+
url_for("auth.register", json=get_fake_registration_json())
74+
) # first user
75+
response = client.post(
76+
url_for("auth.register"), json=get_fake_registration_json()
77+
) # another user
78+
assert response.status_code == 201
79+
header_map = {name.lower(): value.lower() for (name, value) in response.headers}
80+
assert header_map["access-control-allow-origin"] == "http://0.0.0.0:3000"
81+
assert header_map["content-type"] == "application/json"
82+
assert isinstance(response.json, dict), "Response must be a dict"
83+
assert (
84+
response.json["message"] == "Successfully created user"
85+
), "Response must have appropriate success message"
86+
87+
88+
@pytest.mark.parametrize(
89+
"missing_field",
90+
[
91+
"firstName",
92+
"lastName",
93+
"email",
94+
"password",
95+
"quizId",
96+
],
97+
)
98+
@pytest.mark.integration
99+
def test_failed_registry_missing_field(missing_field, client):
100+
data = get_fake_registration_json()
101+
data.pop(missing_field)
102+
response = client.post(url_for("auth.register"), json=data)
103+
assert response.status_code == 400
104+
header_map = {name.lower(): value.lower() for (name, value) in response.headers}
105+
assert header_map["content-type"] == "application/json"
106+
assert response.json == {
107+
"error": "{} must be included in the request body.".format(missing_field)
108+
}
109+
110+
111+
@pytest.mark.integration
112+
def test_failed_registry_missing_body(client):
113+
response = client.post(url_for("auth.register"))
114+
assert response.status_code == 400
115+
header_map = {name.lower(): value.lower() for (name, value) in response.headers}
116+
assert header_map["content-type"] == "application/json"
117+
assert response.json == {"error": "JSON body must be included in the request."}
118+
119+
120+
@pytest.mark.integration
121+
def test_failed_registry_reregistry(client):
122+
data = get_fake_registration_json()
123+
client.post(url_for("auth.register"), json=data) # first registry
124+
response = client.post(url_for("auth.register"), json=data) # reregistry attempt
125+
assert response.status_code == 409
126+
header_map = {name.lower(): value.lower() for (name, value) in response.headers}
127+
assert header_map["content-type"] == "application/json"
128+
assert response.json == {
129+
"error": "Cannot register email. Email already exists in the database."
130+
}, "Response must have appropriate error message"
131+
132+
56133
recaptcha_Token = "03AGdBq27Tmja4W082LAEVoYyuuALGQwMVxOuOGDduLCQSTWWFuTtc4hQsc-KUVhsJQlBzEjdtxTqs1kXHusJCk2husZjY44rA-opJLWOgJuVUIoGtXozHtYhtmR5DibuJ3idGLalZ00niqnaa0zHC73hWPzc1CtnUO258nZLh1uxePi7DI-afWQd6aa4-EuRcPabG_E500r9S4RReTg42WtP8SNrqEdFoG9UdPoIF2aGCArHD6GqhQzwOev8_jeKUzcxq_1wEvxiID2ow7rxK339PCeTgO9Zz9fPnhTZ6mKaa_tmL1bSQ2zvWvA0Z5An3YvMP3sureZVR_mhJP2r84sYw9WbuI6hRr1oUGtTGuACB-IBqqE5m-meetr870N2Gl-vp3veeEyo34HLj5iDOr6YwyIXWBKam7mDHfhjps1QeiN90291e6CxaFd-bOkeazZyu2_aEPblNwIiUBl0BobqJ2dT2HlxXCRma0QDuX4xLvwh8_ayrJGo9t6nRxQHghZ2ZEh450bM0bVFAqkIGAqYv_EvYj7_XgQ" # this is the string from the cypress test I'm replacing ...
57134
recaptcha_Token = "abcdef" # ... but any string works!
58135

0 commit comments

Comments
 (0)