arnavam commited on
Commit
8b23235
·
1 Parent(s): 09083dc

fixig some things

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. test/test_audio_api.py +1 -0
  3. test/test_create_user.py +97 -0
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
test/test_audio_api.py CHANGED
@@ -6,6 +6,7 @@ import base64
6
 
7
  # Test locally - change to HF URL when deployed
8
  BASE_URL = "localhost:8000"
 
9
  # BASE_URL = "arnavam-afs-backend.hf.space"
10
 
11
  async def test_audio():
 
6
 
7
  # Test locally - change to HF URL when deployed
8
  BASE_URL = "localhost:8000"
9
+ # BASE_URL = "localhost:7860"
10
  # BASE_URL = "arnavam-afs-backend.hf.space"
11
 
12
  async def test_audio():
test/test_create_user.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Test user registration and session creation in MongoDB."""
3
+ import asyncio
4
+ import os
5
+ from pymongo import AsyncMongoClient
6
+ from passlib.context import CryptContext
7
+ from dotenv import load_dotenv
8
+
9
+ # Load environment variables
10
+ load_dotenv()
11
+
12
+ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
13
+
14
+ async def test_create_user():
15
+ """Test creating a user in the database."""
16
+ mongo_uri = os.getenv("MONGODB_URI", "mongodb://localhost:27017")
17
+ mongo_db_name = os.getenv("MONGODB_DB", "afs")
18
+
19
+ print(f"Testing user creation in MongoDB...")
20
+ print(f"Database: {mongo_db_name}")
21
+
22
+ try:
23
+ # Connect
24
+ print("\n1. Connecting to MongoDB...")
25
+ client = AsyncMongoClient(mongo_uri, serverSelectionTimeoutMS=5000)
26
+ db = client[mongo_db_name]
27
+ users_collection = db["users"]
28
+
29
+ # Create index
30
+ print("2. Creating email index...")
31
+ await users_collection.create_index("email", unique=True)
32
+
33
+ # Create test user
34
+ test_email = "test@example.com"
35
+ test_username = "testuser"
36
+ test_password = "test123" # Shorter password to avoid bcrypt issues
37
+
38
+ print(f"\n3. Creating user '{test_username}'...")
39
+
40
+ # Check if user exists
41
+ existing = await users_collection.find_one({"email": test_email})
42
+ if existing:
43
+ print(f"⚠️ User already exists. Deleting old user...")
44
+ await users_collection.delete_one({"email": test_email})
45
+
46
+ # Hash password
47
+ hashed_password = pwd_context.hash(test_password)
48
+
49
+ # Insert user
50
+ user_doc = {
51
+ "email": test_email,
52
+ "username": test_username,
53
+ "hashed_password": hashed_password,
54
+ "created_at": "2026-04-05T19:15:00Z"
55
+ }
56
+
57
+ result = await users_collection.insert_one(user_doc)
58
+ print(f"✅ User created with ID: {result.inserted_id}")
59
+
60
+ # Verify user
61
+ print("\n4. Verifying user...")
62
+ user = await users_collection.find_one({"email": test_email})
63
+ print(f"✅ User found:")
64
+ print(f" Email: {user['email']}")
65
+ print(f" Username: {user['username']}")
66
+ print(f" ID: {user['_id']}")
67
+
68
+ # Test password verification
69
+ print("\n5. Testing password verification...")
70
+ if pwd_context.verify(test_password, user['hashed_password']):
71
+ print("✅ Password verified!")
72
+ else:
73
+ print("❌ Password verification failed!")
74
+
75
+ # List all users
76
+ print("\n6. Listing all users...")
77
+ all_users = await users_collection.find().to_list(length=10)
78
+ print(f"✅ Total users in database: {len(all_users)}")
79
+ for u in all_users:
80
+ print(f" - {u['username']} ({u['email']})")
81
+
82
+ print("\n✅ User creation test passed!")
83
+ print(f"\nYou can now login with:")
84
+ print(f" Email: {test_email}")
85
+ print(f" Password: {test_password}")
86
+
87
+ client.close()
88
+ return True
89
+
90
+ except Exception as e:
91
+ print(f"\n❌ Test failed: {e}")
92
+ print(f"Error type: {type(e).__name__}")
93
+ return False
94
+
95
+ if __name__ == "__main__":
96
+ success = asyncio.run(test_create_user())
97
+ exit(0 if success else 1)