test_storage.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. ),
  48. JobOffer(
  49. url="https://www.linkedin.com/jobs/view/3755217595",
  50. title="Job title",
  51. company="Company",
  52. origin=JobOfferOrigin.LINKED_IN,
  53. application_process=ApplicationProcess.REGULAR,
  54. location="location",
  55. company_domain="domain",
  56. company_url="https://www.linkedin.com/company/the-company/life",
  57. comment="""
  58. multi
  59. line
  60. comment
  61. """,
  62. publication_date=date.today(),
  63. ),
  64. ]
  65. )
  66. def linked_in_job_offer(request):
  67. return request.param
  68. class TestJobStorage:
  69. def test_job_storage_empty_on_startup(self, job_storage):
  70. assert job_storage.read_all() == {}
  71. def test_job_addition(self, job_storage, linked_in_job_offer):
  72. job_storage.add_job(linked_in_job_offer)
  73. all_items = job_storage.read_all().items()
  74. assert len(all_items) == 1
  75. [(id, stored_job)] = all_items
  76. assert isinstance(stored_job.first_seen_date, datetime)
  77. assert id == stored_job.id
  78. # Reset the first_seen_date to None, for comparison with the non-stored version
  79. stored_job.first_seen_date = None
  80. assert stored_job == linked_in_job_offer
  81. def test_job_duplicate_addition(self, job_storage, linked_in_job_offer):
  82. job_storage.add_job(linked_in_job_offer)
  83. with pytest.raises(FileExistsError) as excinfo:
  84. job_storage.add_job(linked_in_job_offer)
  85. assert linked_in_job_offer.id in str(excinfo.value)