sql_app: tests: Add basic unit tests (User Create)

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-06-06 19:26:48 +03:00
parent 868c97fe73
commit 1006baa212
Signed by: Hesham
GPG Key ID: 74876157D199B09E
3 changed files with 63 additions and 0 deletions

View File

@ -4,7 +4,9 @@ asgiref==3.5.0
attrs==21.4.0
bitlist==0.6.2
cbor2==5.4.2.post1
certifi==2022.5.18.1
cffi==1.15.0
charset-normalizer==2.0.12
click==8.0.4
cryptography==36.0.1
Cython==0.29.28
@ -34,6 +36,7 @@ python-decouple==3.6
python-dotenv==0.19.2
python-multipart==0.0.5
PyYAML==6.0
requests==2.27.1
six==1.16.0
sniffio==1.2.0
SQLAlchemy==1.4.31
@ -41,6 +44,7 @@ starlette==0.17.1
termcolor==1.1.0
tomli==2.0.1
typing_extensions==4.1.1
urllib3==1.26.9
uvicorn==0.17.5
uvloop==0.16.0
watchgod==0.7

View File

View File

@ -0,0 +1,59 @@
from sys import path
import random
import string
from fastapi.testclient import TestClient
from ..main import app
from ..schemas import UserCreate
MAX_ASCII = 255
RAND_CHAR_SET = string.ascii_letters
client = TestClient(app)
def gen_rand_str(size: int) -> str:
return ''.join(random.choice(RAND_CHAR_SET) for x in range(size))
def gen_new_user_dict() -> UserCreate:
noune = gen_rand_str(16)
new_user = UserCreate(email=f"testuser{noune}@mail.none",
username=f"testuser{noune}",
password=noune)
return new_user
test_user : UserCreate = gen_new_user_dict()
common_headres = {
'accept': 'application/json',
'Content-Type': 'application/json'
}
def test_create_user():
new_user_json = {
"email" : test_user.email,
"username": test_user.username,
"password": test_user.password
}
response = client.request("POST", "/users/reg",
json=new_user_json,
headers=common_headres)
assert response.status_code == 200
def test_create_user_duplicate_fields():
# Assumed that this test runs after test_create_user()
new_user_json = {
"email" : test_user.email,
"username": test_user.username,
"password": test_user.password
}
response = client.request("POST", "/users/reg",
json=new_user_json,
headers=common_headres)
assert response.status_code == 400
def test_create_iot_entity():
pass