-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackendtest.py
More file actions
51 lines (40 loc) · 1.48 KB
/
backendtest.py
File metadata and controls
51 lines (40 loc) · 1.48 KB
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
47
48
49
50
51
import pytest
import requests
base_url = "https://chatty-pv9k.onrender.com"
api_url = f"{base_url}/api"
def test_server_running():
r = requests.get(base_url)
assert r.status_code == 200
assert "server is alive" in r.text.lower()
def test_signup():
data = {"fullname":"test user","email":"test@example.com","password":"password123"}
r = requests.post(f"{api_url}/auth/signup", json=data)
assert r.status_code in [201,400]
def test_login():
data = {"email":"test@example.com","password":"password123"}
r = requests.post(f"{api_url}/auth/login", json=data)
assert r.status_code in [200,404]
def test_invalid_login():
data = {"email":"test@example.com","password":"wrongpassword"}
r = requests.post(f"{api_url}/auth/login", json=data)
assert r.status_code == 404
def test_auth_check_without_login():
r = requests.get(f"{api_url}/auth/check")
assert r.status_code == 401
def test_users_without_auth():
r = requests.get(f"{api_url}/message/users")
assert r.status_code == 401
def test_logout():
r = requests.post(f"{api_url}/auth/logout")
assert r.status_code == 200
def test_invalid_endpoint():
r = requests.get(f"{api_url}/invalid")
assert r.status_code == 404
def test_signup_missing_data():
data = {"email":"test@test.com"}
r = requests.post(f"{api_url}/auth/signup", json=data)
assert r.status_code == 400
def test_login_missing_data():
data = {"email":"test@test.com"}
r = requests.post(f"{api_url}/auth/login", json=data)
assert r.status_code == 404