-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackend_test.py
More file actions
1755 lines (1450 loc) · 73.7 KB
/
backend_test.py
File metadata and controls
1755 lines (1450 loc) · 73.7 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import requests
import sys
import json
from datetime import datetime
class CareerLiftAPITester:
def __init__(self, base_url="https://careershift-app.preview.emergentagent.com/api"):
self.base_url = base_url
self.token = None
self.user_id = None
self.tests_run = 0
self.tests_passed = 0
self.failed_tests = []
self.analysis_id = None
def log_result(self, test_name, success, details=""):
"""Log test result"""
self.tests_run += 1
if success:
self.tests_passed += 1
print(f"✅ {test_name} - PASSED")
else:
print(f"❌ {test_name} - FAILED: {details}")
self.failed_tests.append({"test": test_name, "error": details})
def run_test(self, name, method, endpoint, expected_status, data=None, headers=None):
"""Run a single API test"""
url = f"{self.base_url}/{endpoint}"
test_headers = {'Content-Type': 'application/json'}
if self.token:
test_headers['Authorization'] = f'Bearer {self.token}'
if headers:
test_headers.update(headers)
print(f"\n🔍 Testing {name}...")
print(f" URL: {url}")
try:
if method == 'GET':
response = requests.get(url, headers=test_headers, timeout=30)
elif method == 'POST':
response = requests.post(url, json=data, headers=test_headers, timeout=30)
elif method == 'PUT':
response = requests.put(url, json=data, headers=test_headers, timeout=30)
elif method == 'DELETE':
response = requests.delete(url, headers=test_headers, timeout=30)
print(f" Status: {response.status_code}")
success = response.status_code == expected_status
if success:
self.log_result(name, True)
try:
return True, response.json()
except:
return True, response.text
else:
error_msg = f"Expected {expected_status}, got {response.status_code}"
try:
error_detail = response.json()
error_msg += f" - {error_detail}"
except:
error_msg += f" - {response.text[:200]}"
self.log_result(name, False, error_msg)
return False, {}
except requests.exceptions.Timeout:
self.log_result(name, False, "Request timeout (30s)")
return False, {}
except Exception as e:
self.log_result(name, False, f"Request error: {str(e)}")
return False, {}
def test_health_check(self):
"""Test API health endpoint"""
success, response = self.run_test(
"Health Check",
"GET",
"health",
200
)
if success:
print(f" Claude configured: {response.get('claude_configured', False)}")
return success
def test_get_roles(self):
"""Test getting AI roles - Should return 21 roles after data extraction"""
success, response = self.run_test(
"Get AI Roles",
"GET",
"roles",
200
)
if success:
roles = response.get('roles', [])
print(f" Found {len(roles)} roles")
if len(roles) != 21:
self.log_result("Roles Count Validation", False, f"Expected 21 roles, got {len(roles)}")
return False
else:
self.log_result("Roles Count Validation", True)
return success
def test_register_user(self):
"""Test user registration"""
timestamp = datetime.now().strftime('%H%M%S')
test_user_data = {
"name": f"Test User {timestamp}",
"email": f"test{timestamp}@example.com",
"password": "TestPass123!"
}
success, response = self.run_test(
"User Registration",
"POST",
"auth/register",
200,
data=test_user_data
)
if success:
self.token = response.get('access_token')
self.user_id = response.get('user', {}).get('id')
print(f" User ID: {self.user_id}")
print(f" Token received: {'Yes' if self.token else 'No'}")
return success
def test_login_user(self):
"""Test user login with existing credentials"""
# Try to login with the registered user
if not hasattr(self, 'test_email'):
# Use a test account
login_data = {
"email": "test@example.com",
"password": "TestPass123!"
}
else:
login_data = {
"email": self.test_email,
"password": "TestPass123!"
}
success, response = self.run_test(
"User Login",
"POST",
"auth/login",
200,
data=login_data
)
if success:
self.token = response.get('access_token')
self.user_id = response.get('user', {}).get('id')
return success
def test_get_me(self):
"""Test getting current user info"""
if not self.token:
self.log_result("Get Current User", False, "No auth token available")
return False
success, response = self.run_test(
"Get Current User",
"GET",
"auth/me",
200
)
return success
def test_resume_parse_text(self):
"""Test resume parsing with text"""
sample_resume = """
John Doe
Software Engineer
Experience:
- 5 years of experience in Python development
- Worked with machine learning frameworks like TensorFlow and PyTorch
- Built REST APIs using FastAPI and Django
- Experience with AWS cloud services
Education:
Bachelor's degree in Computer Science
Skills: Python, JavaScript, React, SQL, Docker, Kubernetes, Machine Learning
"""
# Test with form data (text)
url = f"{self.base_url}/resume/parse"
headers = {}
if self.token:
headers['Authorization'] = f'Bearer {self.token}'
form_data = {'text': sample_resume}
try:
response = requests.post(url, data=form_data, headers=headers, timeout=30)
success = response.status_code == 200
if success:
self.log_result("Resume Parse (Text)", True)
result = response.json()
resume_data = result.get('resume_data', {})
print(f" Skills detected: {len(resume_data.get('skills', []))}")
print(f" Years experience: {resume_data.get('years_experience', 'Not detected')}")
return True, result
else:
error_msg = f"Status {response.status_code}: {response.text[:200]}"
self.log_result("Resume Parse (Text)", False, error_msg)
return False, {}
except Exception as e:
self.log_result("Resume Parse (Text)", False, str(e))
return False, {}
def test_career_analysis(self):
"""Test career analysis endpoint"""
if not self.token:
self.log_result("Career Analysis", False, "No auth token available")
return False
# First get resume data
resume_success, resume_response = self.test_resume_parse_text()
if not resume_success:
self.log_result("Career Analysis", False, "Resume parsing failed")
return False
resume_data = resume_response.get('resume_data', {})
analysis_request = {
"resume_data": resume_data,
"target_role_id": "ai_ml_engineer", # Use first role from the list
"background_context": {
"current_role": "Software Engineer",
"years_experience": 5,
"education_level": "Bachelor's in Computer Science",
"primary_skills": ["Python", "Machine Learning", "FastAPI"],
"career_goals": "Transition to AI/ML Engineer role"
}
}
success, response = self.run_test(
"Career Analysis",
"POST",
"analyze",
200,
data=analysis_request
)
if success:
self.analysis_id = response.get('analysis_id')
print(f" Analysis ID: {self.analysis_id}")
analysis_result = response.get('analysis', {})
career_fit = analysis_result.get('career_fit', {})
print(f" Career fit score: {career_fit.get('score', 'N/A')}")
print(f" Career fit rating: {career_fit.get('rating', 'N/A')}")
return success
def test_get_analysis(self):
"""Test getting analysis by ID"""
if not self.token or not self.analysis_id:
self.log_result("Get Analysis", False, "No auth token or analysis ID available")
return False
success, response = self.run_test(
"Get Analysis by ID",
"GET",
f"analyses/{self.analysis_id}",
200
)
return success
def test_get_analyses_list(self):
"""Test getting user's analyses list"""
if not self.token:
self.log_result("Get Analyses List", False, "No auth token available")
return False
success, response = self.run_test(
"Get Analyses List",
"GET",
"analyses",
200
)
if success:
analyses = response.get('analyses', [])
print(f" Found {len(analyses)} analyses")
return success
def test_get_usage(self):
"""Test getting usage statistics"""
if not self.token:
self.log_result("Get Usage Stats", False, "No auth token available")
return False
success, response = self.run_test(
"Get Usage Statistics",
"GET",
"usage",
200
)
if success:
print(f" Analyses used: {response.get('analyses_used', 0)}/{response.get('analyses_limit', 0)}")
print(f" CV generations used: {response.get('cv_generations_used', 0)}/{response.get('cv_generations_limit', 0)}")
return success
def test_mock_upgrade(self):
"""Test mock upgrade endpoint"""
if not self.token:
self.log_result("Mock Upgrade", False, "No auth token available")
return False
success, response = self.run_test(
"Mock Upgrade to Pro",
"POST",
"payments/mock-upgrade",
200
)
if success:
print(f" New subscription tier: {response.get('subscription_tier', 'N/A')}")
return success
def test_mock_checkout(self):
"""Test mock checkout endpoint"""
if not self.token:
self.log_result("Mock Checkout", False, "No auth token available")
return False
# Use query parameter instead of request body
success, response = self.run_test(
"Mock Checkout",
"POST",
"payments/checkout?product_type=pro_subscription",
200
)
if success:
print(f" Checkout URL: {response.get('checkout_url', 'N/A')}")
return success
def test_interview_question_generation(self):
"""Test interview question generation endpoint (uses Haiku)"""
if not self.token:
self.log_result("Interview Question Generation", False, "No auth token available")
return False
# Test basic question generation
request_data = {
"role_id": "ml_engineer",
"categories": ["technical", "behavioral", "system_design"],
"count": 10
}
success, response = self.run_test(
"Interview Question Generation (Basic)",
"POST",
"interview-prep/generate",
200,
data=request_data
)
if success:
questions = response.get('questions', [])
category_breakdown = response.get('category_breakdown', {})
print(f" Generated {len(questions)} questions")
print(f" Category breakdown: {category_breakdown}")
# Validate response structure
if len(questions) != 10:
self.log_result("Question Count Validation", False, f"Expected 10 questions, got {len(questions)}")
return False
# Check if questions have required fields
for i, q in enumerate(questions[:3]): # Check first 3 questions
required_fields = ['question', 'category', 'id']
missing_fields = [field for field in required_fields if field not in q]
if missing_fields:
self.log_result("Question Structure Validation", False, f"Question {i} missing fields: {missing_fields}")
return False
self.log_result("Question Structure Validation", True)
return success
def test_interview_question_generation_with_company(self):
"""Test interview question generation with company context"""
if not self.token:
self.log_result("Interview Question Generation (Company)", False, "No auth token available")
return False
# Test with company-specific questions
request_data = {
"role_id": "ai_engineer",
"categories": ["technical", "behavioral"],
"count": 10,
"company": "google"
}
success, response = self.run_test(
"Interview Question Generation (Company-specific)",
"POST",
"interview-prep/generate",
200,
data=request_data
)
if success:
questions = response.get('questions', [])
print(f" Generated {len(questions)} company-specific questions")
# Check if any questions are company-specific
company_questions = [q for q in questions if q.get('company') or q.get('source') == 'company']
print(f" Company-specific questions: {len(company_questions)}")
return success
def test_interview_feedback(self):
"""Test interview feedback endpoint (uses Sonnet - Premium)"""
if not self.token:
self.log_result("Interview Feedback", False, "No auth token available")
return False
# Test feedback generation
request_data = {
"question": "Explain the bias-variance tradeoff",
"answer": "The bias-variance tradeoff is about balancing model complexity. High bias means underfitting, high variance means overfitting. We use techniques like cross-validation to find the right balance.",
"role_id": "ml_engineer",
"category": "technical"
}
success, response = self.run_test(
"Interview Feedback Generation",
"POST",
"interview-prep/feedback",
200,
data=request_data
)
if success:
score = response.get('score', 0)
strengths = response.get('strengths', [])
improvements = response.get('improvements', [])
sample_answer = response.get('sample_answer', '')
print(f" Score: {score}/100")
print(f" Strengths: {len(strengths)} items")
print(f" Improvements: {len(improvements)} items")
print(f" Sample answer provided: {'Yes' if sample_answer else 'No'}")
# Validate response structure
required_fields = ['score', 'strengths', 'improvements', 'sample_answer']
missing_fields = [field for field in required_fields if field not in response]
if missing_fields:
self.log_result("Feedback Structure Validation", False, f"Missing fields: {missing_fields}")
return False
# Validate score is reasonable
if not isinstance(score, (int, float)) or score < 0 or score > 100:
self.log_result("Feedback Score Validation", False, f"Invalid score: {score}")
return False
self.log_result("Feedback Structure Validation", True)
self.log_result("Feedback Score Validation", True)
return success
def test_interview_history(self):
"""Test interview history endpoint"""
if not self.token:
self.log_result("Interview History", False, "No auth token available")
return False
success, response = self.run_test(
"Interview History",
"GET",
"interview-prep/history",
200
)
if success:
history = response.get('history', [])
stats = response.get('stats', {})
print(f" History entries: {len(history)}")
print(f" Total practiced: {stats.get('total_practiced', 0)}")
print(f" Average score: {stats.get('avg_score', 0)}")
print(f" Current streak: {stats.get('streak', 0)}")
# Validate response structure
required_fields = ['history', 'stats']
missing_fields = [field for field in required_fields if field not in response]
if missing_fields:
self.log_result("History Structure Validation", False, f"Missing fields: {missing_fields}")
return False
# Validate stats structure
stats_fields = ['total_practiced', 'avg_score', 'streak']
missing_stats = [field for field in stats_fields if field not in stats]
if missing_stats:
self.log_result("History Stats Validation", False, f"Missing stats: {missing_stats}")
return False
self.log_result("History Structure Validation", True)
self.log_result("History Stats Validation", True)
return success
def test_interview_companies(self):
"""Test getting companies list endpoint"""
success, response = self.run_test(
"Get Interview Companies",
"GET",
"interview-prep/companies",
200
)
if success:
companies = response.get('companies', [])
print(f" Available companies: {len(companies)}")
# Check structure of first company if available
if companies:
first_company = companies[0]
required_fields = ['id', 'name']
missing_fields = [field for field in required_fields if field not in first_company]
if missing_fields:
self.log_result("Company Structure Validation", False, f"Missing fields: {missing_fields}")
return False
print(f" Sample company: {first_company.get('name', 'N/A')}")
self.log_result("Company Structure Validation", True)
return success
def test_get_specific_role(self):
"""Test getting specific role details"""
success, response = self.run_test(
"Get ML Engineer Role",
"GET",
"roles/ml_engineer",
200
)
if success:
role_name = response.get('name', '')
salary_range = response.get('salary_range', '')
top_skills = response.get('top_skills', [])
hiring_patterns = response.get('hiring_patterns', {})
print(f" Role: {role_name}")
print(f" Salary: {salary_range}")
print(f" Skills: {len(top_skills)} listed")
print(f" Hiring patterns: {len(hiring_patterns)} regions")
# Validate required fields
required_fields = ['id', 'name', 'description', 'salary_range', 'top_skills']
missing_fields = [field for field in required_fields if field not in response]
if missing_fields:
self.log_result("Role Structure Validation", False, f"Missing fields: {missing_fields}")
return False
self.log_result("Role Structure Validation", True)
return success
def test_hiring_patterns(self):
"""Test getting hiring patterns"""
success, response = self.run_test(
"Get Hiring Patterns",
"GET",
"hiring-patterns",
200
)
if success:
patterns = response.get('hiring_patterns', {})
print(f" Regions covered: {len(patterns)}")
# Check structure
if patterns:
first_region = list(patterns.keys())[0]
region_data = patterns[first_region]
required_fields = ['companies', 'preference']
missing_fields = [field for field in required_fields if field not in region_data]
if missing_fields:
self.log_result("Hiring Patterns Structure Validation", False, f"Missing fields: {missing_fields}")
return False
print(f" Sample region ({first_region}): {len(region_data.get('companies', []))} companies")
self.log_result("Hiring Patterns Structure Validation", True)
return success
def test_user_profile(self):
"""Test getting user profile"""
if not self.token:
self.log_result("User Profile", False, "No auth token available")
return False
success, response = self.run_test(
"Get User Profile",
"GET",
"user/profile",
200
)
if success:
user_data = response.get('user', {})
usage_data = response.get('usage', {})
stats_data = response.get('stats', {})
print(f" User: {user_data.get('email', 'N/A')}")
print(f" Subscription: {user_data.get('subscription_tier', 'N/A')}")
print(f" Total CVs: {stats_data.get('total_cv_generations', 0)}")
print(f" Total Analyses: {stats_data.get('total_analyses', 0)}")
# Validate structure
required_sections = ['user', 'usage', 'stats']
missing_sections = [section for section in required_sections if section not in response]
if missing_sections:
self.log_result("Profile Structure Validation", False, f"Missing sections: {missing_sections}")
return False
self.log_result("Profile Structure Validation", True)
return success
def test_analytics_dashboard(self):
"""Test getting analytics dashboard"""
if not self.token:
self.log_result("Analytics Dashboard", False, "No auth token available")
return False
success, response = self.run_test(
"Get Analytics Dashboard",
"GET",
"analytics/dashboard",
200
)
if success:
cv_count = response.get('cv_generations', 0)
lp_count = response.get('learning_paths', 0)
analysis_count = response.get('analyses', 0)
downloads = response.get('total_downloads', 0)
print(f" CV Generations: {cv_count}")
print(f" Learning Paths: {lp_count}")
print(f" Analyses: {analysis_count}")
print(f" Downloads: {downloads}")
# Validate required fields
required_fields = ['cv_generations', 'learning_paths', 'analyses', 'total_downloads']
missing_fields = [field for field in required_fields if field not in response]
if missing_fields:
self.log_result("Analytics Structure Validation", False, f"Missing fields: {missing_fields}")
return False
self.log_result("Analytics Structure Validation", True)
return success
def test_cv_generation(self):
"""Test CV generation with Superior Hybrid Resume model"""
if not self.token:
self.log_result("CV Generation", False, "No auth token available")
return False
# Sample resume data for testing (must be at least 100 characters)
cv_request = {
"resume_text": """John Doe
Software Engineer with 5 years experience
Experience:
- Senior Software Engineer at TechCorp (2020-2024)
- Built ML pipelines using Python and TensorFlow
- Developed REST APIs with FastAPI and Django
- Worked with AWS cloud services including EC2, S3, and Lambda
- Led a team of 3 developers on machine learning projects
- Implemented CI/CD pipelines using Docker and Kubernetes
Education:
Bachelor's degree in Computer Science from State University
Skills: Python, JavaScript, React, SQL, Docker, Kubernetes, Machine Learning, TensorFlow, PyTorch, AWS, FastAPI, Django""",
"target_role_id": "ml_engineer",
"region": "us",
"settings": {
"style": "modern",
"color_scheme": "blue"
}
}
success, response = self.run_test(
"CV Generation (Superior Hybrid Resume)",
"POST",
"cv/generate",
200,
data=cv_request
)
if success:
cv_id = response.get('cv_id', '')
target_role = response.get('target_role', '')
versions = response.get('versions', [])
print(f" CV ID: {cv_id}")
print(f" Target Role: {target_role}")
print(f" Versions: {len(versions)}")
# Validate structure - the actual response format
required_fields = ['cv_id', 'target_role', 'versions']
missing_fields = [field for field in required_fields if field not in response]
if missing_fields:
self.log_result("CV Generation Structure Validation", False, f"Missing fields: {missing_fields}")
return False
# Check if versions contain the Superior Hybrid Resume
hybrid_version = None
for version in versions:
if version.get('name') == 'Superior Hybrid Resume':
hybrid_version = version
break
if not hybrid_version:
self.log_result("CV Superior Hybrid Model Validation", False, "Superior Hybrid Resume version not found")
return False
print(f" Superior Hybrid Resume found: {hybrid_version.get('type', 'N/A')}")
self.log_result("CV Generation Structure Validation", True)
self.log_result("CV Superior Hybrid Model Validation", True)
return success
def test_cv_history(self):
"""Test getting CV generation history"""
if not self.token:
self.log_result("CV History", False, "No auth token available")
return False
success, response = self.run_test(
"Get CV History",
"GET",
"cv/history",
200
)
if success:
history = response.get('history', [])
print(f" CV History entries: {len(history)}")
# If there are entries, validate structure
if history:
first_entry = history[0]
required_fields = ['id', 'target_role', 'created_at']
missing_fields = [field for field in required_fields if field not in first_entry]
if missing_fields:
self.log_result("CV History Structure Validation", False, f"Missing fields: {missing_fields}")
return False
print(f" Latest CV: {first_entry.get('target_role', 'N/A')}")
self.log_result("CV History Structure Validation", True)
return success
def test_get_courses(self):
"""Test getting courses - Should return 44 courses (16 Scrimba, 23 free)"""
success, response = self.run_test(
"Get All Courses",
"GET",
"courses",
200
)
if success:
courses = response.get('courses', [])
print(f" Found {len(courses)} total courses")
# Count Scrimba courses
scrimba_courses = [c for c in courses if c.get('platform') == 'Scrimba']
print(f" Scrimba courses: {len(scrimba_courses)}")
# Count free courses
free_courses = [c for c in courses if 'free' in c.get('cost', '').lower()]
print(f" Free courses: {len(free_courses)}")
# Validate total count
if len(courses) != 44:
self.log_result("Courses Count Validation", False, f"Expected 44 courses, got {len(courses)}")
return False
# Validate Scrimba count
if len(scrimba_courses) != 16:
self.log_result("Scrimba Courses Count Validation", False, f"Expected 16 Scrimba courses, got {len(scrimba_courses)}")
return False
# Validate free courses count
if len(free_courses) != 27:
self.log_result("Free Courses Count Validation", False, f"Expected 27 free courses, got {len(free_courses)}")
return False
self.log_result("Courses Count Validation", True)
self.log_result("Scrimba Courses Count Validation", True)
self.log_result("Free Courses Count Validation", True)
return success
def test_get_scrimba_courses(self):
"""Test getting Scrimba courses specifically - Should return 16 courses"""
success, response = self.run_test(
"Get Scrimba Courses",
"GET",
"courses/scrimba",
200
)
if success:
courses = response.get('courses', [])
print(f" Found {len(courses)} Scrimba courses")
# Validate count
if len(courses) != 16:
self.log_result("Scrimba Courses Endpoint Count Validation", False, f"Expected 16 Scrimba courses, got {len(courses)}")
return False
# Validate all are Scrimba courses
non_scrimba = [c for c in courses if c.get('platform') != 'Scrimba']
if non_scrimba:
self.log_result("Scrimba Courses Platform Validation", False, f"Found {len(non_scrimba)} non-Scrimba courses in Scrimba endpoint")
return False
# Check for recommended courses
recommended_courses = [c for c in courses if c.get('recommended', False)]
print(f" Recommended Scrimba courses: {len(recommended_courses)}")
self.log_result("Scrimba Courses Endpoint Count Validation", True)
self.log_result("Scrimba Courses Platform Validation", True)
return success
def test_get_pricing(self):
"""Test getting pricing tiers"""
success, response = self.run_test(
"Get Pricing Tiers",
"GET",
"payments/pricing",
200
)
if success:
pricing = response.get('pricing', {})
free_limits = response.get('free_limits', {})
print(f" Pricing tiers: {len(pricing)}")
print(f" Free limits defined: {len(free_limits)}")
# Validate pricing structure
expected_pricing_keys = ['pro_monthly', 'cv_single', 'cv_bulk_50']
missing_pricing = [key for key in expected_pricing_keys if key not in pricing]
if missing_pricing:
self.log_result("Pricing Structure Validation", False, f"Missing pricing tiers: {missing_pricing}")
return False
# Validate free limits structure
expected_limits_keys = ['cv_generations', 'learning_paths', 'analyses']
missing_limits = [key for key in expected_limits_keys if key not in free_limits]
if missing_limits:
self.log_result("Free Limits Structure Validation", False, f"Missing free limits: {missing_limits}")
return False
# Check pro monthly pricing
pro_monthly = pricing.get('pro_monthly', {})
if pro_monthly.get('price') != 29:
self.log_result("Pro Monthly Price Validation", False, f"Expected $29, got ${pro_monthly.get('price')}")
return False
self.log_result("Pricing Structure Validation", True)
self.log_result("Free Limits Structure Validation", True)
self.log_result("Pro Monthly Price Validation", True)
return success
def test_resume_scanner(self):
"""Test Resume Scanner feature - POST /api/resume/scan"""
if not self.token:
self.log_result("Resume Scanner", False, "No auth token available")
return False
# Sample resume text for scanning (must be realistic)
resume_text = """Sarah Johnson
Senior Software Engineer
Experience:
• Senior Software Engineer at Microsoft (2020-2024)
- Led development of cloud-based ML solutions using Python and Azure
- Built scalable APIs serving 1M+ requests daily using FastAPI
- Implemented CI/CD pipelines reducing deployment time by 60%
- Mentored 5 junior developers on machine learning best practices
• Software Engineer at Google (2018-2020)
- Developed recommendation systems using TensorFlow and PyTorch
- Optimized database queries improving performance by 40%
- Collaborated with cross-functional teams on AI product features
Education:
Master's in Computer Science, Stanford University (2018)
Bachelor's in Software Engineering, UC Berkeley (2016)
Skills: Python, JavaScript, React, Node.js, TensorFlow, PyTorch, AWS, Azure, Docker, Kubernetes, SQL, MongoDB, Machine Learning, Deep Learning, REST APIs, Microservices, Agile, Git"""
scan_request = {
"resume_text": resume_text,
"target_role_id": "ai_ml_engineer" # Fixed: use target_role_id instead of target_role
}
success, response = self.run_test(
"Resume Scanner (ATS Analysis)",
"POST",
"resume/scan",
200,
data=scan_request
)
if success:
ats_score = response.get('ats_score', 0)
human_appeal_score = response.get('human_appeal_score', 0)
keywords_found = response.get('keywords_found', [])
keywords_missing = response.get('keywords_missing', [])
quick_wins = response.get('quick_wins', [])
overall_grade = response.get('overall_grade', '')
print(f" ATS Score: {ats_score}/100")
print(f" Human Appeal Score: {human_appeal_score}/100")
print(f" Overall Grade: {overall_grade}")
print(f" Keywords found: {len(keywords_found)}")
print(f" Keywords missing: {len(keywords_missing)}")
print(f" Quick wins: {len(quick_wins)}")
# Validate response structure based on actual API
required_fields = ['ats_score', 'human_appeal_score', 'keyword_match_percent', 'overall_grade',
'keywords_found', 'keywords_missing', 'strengths', 'improvements',
'formatting_issues', 'quick_wins', 'target_role', 'scan_id']
missing_fields = [field for field in required_fields if field not in response]
if missing_fields:
self.log_result("Resume Scanner Structure Validation", False, f"Missing fields: {missing_fields}")
return False
# Validate scores are reasonable
if not isinstance(ats_score, (int, float)) or ats_score < 0 or ats_score > 100:
self.log_result("Resume Scanner ATS Score Validation", False, f"Invalid ATS score: {ats_score}")
return False
if not isinstance(human_appeal_score, (int, float)) or human_appeal_score < 0 or human_appeal_score > 100:
self.log_result("Resume Scanner Human Appeal Validation", False, f"Invalid human appeal score: {human_appeal_score}")
return False
self.log_result("Resume Scanner Structure Validation", True)
self.log_result("Resume Scanner ATS Score Validation", True)
self.log_result("Resume Scanner Human Appeal Validation", True)
return success
def test_resume_scanner_usage(self):
"""Test Resume Scanner usage tracking - GET /api/resume/scan/usage"""
if not self.token:
self.log_result("Resume Scanner Usage", False, "No auth token available")
return False
success, response = self.run_test(
"Resume Scanner Usage Tracking",
"GET",
"resume/scan/usage",
200
)
if success:
scans_used = response.get('scans_used', 0)
scans_limit = response.get('scans_limit', 0)
is_pro = response.get('is_pro', False)
can_scan = response.get('can_scan', False)
print(f" Scans used: {scans_used}/{scans_limit}")
print(f" Is Pro: {is_pro}")
print(f" Can scan: {can_scan}")