test_storage.py 3.2 KB

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