import pytest
from django.contrib.auth import get_user_model
from apps.resumes.models import Resume

User = get_user_model()


@pytest.fixture
def seeker():
    return User.objects.create_user(username='seeker1', password='pass', role='seeker')


@pytest.mark.django_db
class TestResumeModel:
    def test_create_resume(self, seeker):
        resume = Resume.objects.create(
            user=seeker,
            name='张三',
            gender='male',
            education=[{'school': '北京大学', 'degree': '本科', 'major': '计算机'}],
            experience=[{'company': 'ABC公司', 'position': '工程师', 'duration': '2年'}],
        )
        assert resume.name == '张三'
        assert len(resume.education) == 1
        assert len(resume.experience) == 1

    def test_seeker_has_one_resume(self, seeker):
        Resume.objects.create(user=seeker, name='张三')
        assert Resume.objects.filter(user=seeker).count() == 1
