test_storage.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import pytest
  2. from datetime import date, datetime
  3. from job_search.job_storage import (
  4. JobStorage,
  5. JobOffer,
  6. JobOfferOrigin,
  7. ApplicationProcess,
  8. CompanyKind,
  9. ContractType,
  10. Flexibility,
  11. )
  12. @pytest.fixture(params=[JobStorage])
  13. def job_storage(request, tmp_path):
  14. return request.param(base_dir=tmp_path)
  15. @pytest.fixture(
  16. params=[
  17. JobOffer(
  18. id="linked_in_3755217595",
  19. url="https://www.linkedin.com/jobs/view/3755217595",
  20. title="Job title",
  21. company="Company",
  22. origin=JobOfferOrigin.LINKED_IN,
  23. application_process=ApplicationProcess.REGULAR,
  24. location="location",
  25. company_domain="domain",
  26. company_url="https://www.linkedin.com/company/the-company/life",
  27. publication_date=date.today(),
  28. ),
  29. JobOffer(
  30. id="linked_in_3755217595",
  31. url="https://www.linkedin.com/jobs/view/3755217595",
  32. title="Job title",
  33. company="Company",
  34. origin=JobOfferOrigin.LINKED_IN,
  35. application_process=ApplicationProcess.REGULAR,
  36. location="location",
  37. company_domain="domain",
  38. company_url="https://www.linkedin.com/company/the-company/life",
  39. publication_date=date.today(),
  40. skills=["skill1", "skill2"],
  41. tags=["tag1", "tag2"],
  42. xp_required=2,
  43. company_kind=CompanyKind.REGULAR,
  44. comment="comment",
  45. description="description",
  46. contract_type=ContractType.CDD,
  47. flexibility=Flexibility.HYBRID,
  48. alternate_url="https://www.anothersite.com/with/the/offer.html",
  49. application_date=date.today(),
  50. application_rejection_date=date.today(),
  51. ),
  52. JobOffer(
  53. id="linked_in_3755217595",
  54. url="https://www.linkedin.com/jobs/view/3755217595",
  55. title="Job title",
  56. company="Company",
  57. origin=JobOfferOrigin.LINKED_IN,
  58. application_process=ApplicationProcess.REGULAR,
  59. location="location",
  60. company_domain="domain",
  61. company_url="https://www.linkedin.com/company/the-company/life",
  62. comment="""
  63. multi
  64. line
  65. comment
  66. """,
  67. publication_date=date.today(),
  68. ),
  69. ]
  70. )
  71. def linked_in_job_offer(request):
  72. return request.param
  73. class TestJobStorage:
  74. def test_job_storage_empty_on_startup(self, job_storage):
  75. assert job_storage.read_all() == {}
  76. def test_job_addition(self, job_storage, linked_in_job_offer):
  77. job_storage.insert_record("job_offer", linked_in_job_offer.to_storage())
  78. all_items = job_storage.read_all().items()
  79. assert len(all_items) == 1
  80. [(id, stored_job)] = all_items
  81. assert isinstance(stored_job.first_seen_date, datetime)
  82. assert id == stored_job.id
  83. # Reset the first_seen_date to None, for comparison with the non-stored version
  84. stored_job.first_seen_date = None
  85. assert stored_job == linked_in_job_offer
  86. def test_job_duplicate_addition(self, job_storage, linked_in_job_offer):
  87. job_storage.insert_record("job_offer", linked_in_job_offer.to_storage())
  88. with pytest.raises(FileExistsError) as excinfo:
  89. job_storage.insert_record("job_offer", linked_in_job_offer.to_storage())
  90. assert linked_in_job_offer.id in str(excinfo.value)