-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
46 lines (35 loc) · 1.51 KB
/
test_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""This test_api.py file will hold all of the api tests for this application"""
import pytest
import random
import string
from faker import Faker
from app import app
fake = Faker()
Faker.seed(random.randint(0, 300))
@pytest.fixture()
def client():
app.config["TESTING"] = True
return app.test_client()
def test_login_existing_user_api(client):
"""This test will confirm the existing users login information is correct using the api"""
response = client.get("/api/login?username=JohnDoe123&password=password123")
assert response.status_code == 200
def test_login_non_existent_user_api(client):
"""This test will confirm the non-existent users login information is incorrect using the api"""
random_string = "".join(random.choices(string.ascii_letters + string.digits, k=10))
response = client.get(
f"/api/login?username={random_string}&password={random_string}"
)
assert response.status_code == 404
def test_create_new_user(client):
"""This test will confirm that the new user was created"""
response = client.get(
f"/api/new/account?username={fake.user_name()}&password={fake.password()}&email={fake.email()}&name={fake.name()}"
)
assert response.status_code == 200
def test_create_existing_user(client):
"""This test will confirm that a user already exists when it was being created"""
response = client.get(
"/api/new/account?username=JohnDoe123&password=password123&[email protected]&name=John Doe"
)
assert response.status_code == 404