Skip to content

Commit

Permalink
Fix: Resolve test bugs due to missing CORS origin specification
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullah-alnahas committed May 14, 2024
1 parent 5667f70 commit ab120b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_answer_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def is_correct(row):

def test_ansari_agent(data):
df, q_temp, cache = data
df = df.sample(10)
#df = df.sample(10)
# For cost and efficiency reasons, we will only test 10 questions
df["json_prediction"] = df.apply(
lambda row: answer_question(row, q_temp, cache), axis=1
Expand Down
9 changes: 7 additions & 2 deletions tests/test_main_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def login_user(register_user):
# Log in the user before each test that requires a valid token
response = client.post(
"/api/v2/users/login",
headers={"x-mobile-ansari": "ANSARI"},
json={
"email": register_user["email"],
"password": valid_password,
Expand All @@ -80,6 +81,7 @@ def login_another_user(register_another_user):
# Log in the user before each test that requires a valid token
response = client.post(
"/api/v2/users/login",
headers={"x-mobile-ansari": "ANSARI"},
json={
"email": register_another_user["email"],
"password": valid_password,
Expand Down Expand Up @@ -165,6 +167,7 @@ async def test_login_valid_credentials(register_user):
# Test logging in with valid credentials
response = client.post(
"/api/v2/users/login",
headers={"x-mobile-ansari": "ANSARI"},
json={
"email": register_user["email"],
"password": valid_password,
Expand All @@ -180,6 +183,7 @@ async def test_login_invalid_credentials():
# Test logging in with invalid credentials
response = client.post(
"/api/v2/users/login",
headers={"x-mobile-ansari": "ANSARI"},
json={
"email": "invalid@example.com",
"password": "wrongpassword",
Expand All @@ -194,6 +198,7 @@ async def test_login_from_several_devices(register_user, login_user):
time.sleep(1)
response = client.post(
"/api/v2/users/login",
headers={"x-mobile-ansari": "ANSARI"},
json={
"email": register_user["email"],
"password": valid_password,
Expand Down Expand Up @@ -349,7 +354,7 @@ async def test_share_thread(login_user, create_thread):
},
)
assert response.status_code == 200
assert response.json()["content"] == '{"thread_name": null, "messages": []}'
assert response.json()["content"] == {'messages': [], 'thread_name': None}
assert response.json()["status"] == "success"


Expand Down Expand Up @@ -382,7 +387,7 @@ async def test_thread_access(
@pytest.mark.asyncio
async def test_cors():
# Test CORS
allowed_origin = "https://beta.ansari.chat"
allowed_origin = "https://ansari.chat"
disallowed_origin = "https://disallowed.com"

# Test with allowed origin
Expand Down

0 comments on commit ab120b7

Please sign in to comment.