File size: 6,274 Bytes
ab028ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test PDF generation with actual model structure.
"""

from datetime import datetime
import uuid
from pdf_generator import create_pdf_resume
from utils import log_info, log_error

# Test with mock objects that mimic the model structure
class MockWorkExperience:
    def __init__(self, title, organization, start_month, start_year, end_month=None, end_year=None, remarks=""):
        self.title = title
        self.organization = organization
        self.start_month = start_month
        self.start_year = start_year
        self.end_month = end_month
        self.end_year = end_year
        self.remarks = remarks

class MockProject:
    def __init__(self, title, organization, start_month, start_year, end_month=None, end_year=None, remarks=""):
        self.title = title
        self.organization = organization
        self.start_month = start_month
        self.start_year = start_year
        self.end_month = end_month
        self.end_year = end_year
        self.remarks = remarks

class MockEducation:
    def __init__(self, title, organization, start_month, start_year, end_month=None, end_year=None, remarks=""):
        self.title = title
        self.organization = organization
        self.start_month = start_month
        self.start_year = start_year
        self.end_month = end_month
        self.end_year = end_year
        self.remarks = remarks

class MockSkill:
    def __init__(self, skill):
        self.skill = skill

class MockAchievement:
    def __init__(self, achievement):
        self.achievement = achievement

def test_with_mock_models():
    """Test PDF generation with mock model objects."""
    log_info("Testing PDF generation with mock model structure...")
    
    # Create mock data
    work_experiences = [
        MockWorkExperience("Software Engineer", "Tech Corp", 1, 2022, None, None, "Developing web applications"),
        MockWorkExperience("Junior Developer", "StartupXYZ", 6, 2020, 12, 2021, "Built mobile apps")
    ]
    
    projects = [
        MockProject("E-commerce Platform", "Personal", 3, 2023, 5, 2023, "Full-stack development")
    ]
    
    educations = [
        MockEducation("BS Computer Science", "University", 9, 2016, 5, 2020, "Graduated with honors")
    ]
    
    skills = [
        MockSkill("Python"),
        MockSkill("JavaScript"),
        MockSkill("React"),
        MockSkill("Node.js")
    ]
    
    achievements = [
        MockAchievement("Employee of the Year 2023"),
        MockAchievement("Best Project Award")
    ]
    
    # Test data conversion (same as in app.py)
    import calendar
    
    def format_date(month, year):
        """Format month and year as 'Month Year'"""
        if month and year:
            try:
                month_name = calendar.month_name[int(month)]
                return f"{month_name[:3]} {year}"
            except:
                return f"{month}/{year}"
        return ""
    
    # Prepare data for PDF generation
    work_exp_list = []
    for exp in work_experiences:
        start_date = format_date(exp.start_month, exp.start_year)
        end_date = "Present" if not exp.end_month or not exp.end_year else format_date(exp.end_month, exp.end_year)
        
        work_exp_list.append({
            'title': exp.title,
            'organization': exp.organization,
            'start_date': start_date,
            'end_date': end_date,
            'remarks': exp.remarks or ''
        })
    
    projects_list = []
    for proj in projects:
        start_date = format_date(proj.start_month, proj.start_year)
        end_date = "Present" if not proj.end_month or not proj.end_year else format_date(proj.end_month, proj.end_year)
        
        projects_list.append({
            'title': proj.title,
            'organization': proj.organization,
            'start_date': start_date,
            'end_date': end_date,
            'remarks': proj.remarks or ''
        })
    
    education_list = []
    for edu in educations:
        start_date = format_date(edu.start_month, edu.start_year)
        end_date = "Present" if not edu.end_month or not edu.end_year else format_date(edu.end_month, edu.end_year)
        
        education_list.append({
            'title': edu.title,
            'organization': edu.organization,
            'start_date': start_date,
            'end_date': end_date,
            'remarks': edu.remarks or ''
        })
    
    # Convert skills and achievements to comma-separated strings
    skills_text = ', '.join([skill.skill for skill in skills]) if skills else ''
    achievements_text = ', '.join([achievement.achievement for achievement in achievements]) if achievements else ''
    
    # Create data dictionary
    data = {
        'name': 'John Doe',
        'email': '[email protected]',
        'phone': '+1 (555) 123-4567',
        'linkedin': 'johndoe',
        'github': 'johndoe',
        'website': 'https://johndoe.com',
        'summary': 'Experienced software developer with expertise in full-stack development.',
        'work_experience': work_exp_list,
        'projects': projects_list,
        'education': education_list,
        'skills': skills_text,
        'achievements': achievements_text,
        'sections_order': ['work_experience', 'projects', 'education', 'skills', 'achievements']
    }
    
    # Test PDF generation
    try:
        log_info("Generating standard PDF...")
        pdf_bytes = create_pdf_resume(data, "standard")
        if pdf_bytes:
            with open('test_mock_standard.pdf', 'wb') as f:
                f.write(pdf_bytes)
            log_info("βœ“ Standard PDF generated successfully: test_mock_standard.pdf")
        else:
            log_info("βœ— Failed to generate standard PDF")
        
        log_info("Generating modern PDF...")
        pdf_bytes = create_pdf_resume(data, "modern")
        if pdf_bytes:
            with open('test_mock_modern.pdf', 'wb') as f:
                f.write(pdf_bytes)
            log_info("βœ“ Modern PDF generated successfully: test_mock_modern.pdf")
        else:
            log_info("βœ— Failed to generate modern PDF")
            
    except Exception as e:
        log_error(f"Test failed: {str(e)}", e)

if __name__ == "__main__":
    test_with_mock_models()