Skip to content

Commit

Permalink
Update tests and add test to check if JobOfferView returns 404 status…
Browse files Browse the repository at this point in the history
… code when user try to get JobOffer details for object with status other than active
  • Loading branch information
DEENUU1 committed Dec 31, 2023
1 parent 6c99edc commit d2bde72
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ def job_offer(user):
return JobOffer.objects.create(
title="Test Job Offer",
description="Test Job Offer Description",
status="ACTIVE"
)


@pytest.fixture
def job_offer_draft(user):
return JobOffer.objects.create(
title="Test Draft",
description="xyz",
status="DRAFT"
)

@pytest.fixture
def company(user):
return Company.objects.create(
Expand Down
1 change: 0 additions & 1 deletion tests/test_favourite/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def test_error_create_favourite_job_offer_already_saved(user, job_offer):
force_authenticate(request, user=user)
response = view(request)
assert response.status_code == 400
assert response.data['info'] == 'Job Offer is already saved to Favourite'


@pytest.mark.django_db
Expand Down
12 changes: 11 additions & 1 deletion tests/test_offer/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from offer.models import WorkType, EmploymentType, Experience, Salary
from offer.views import OfferListView, SalaryView, ExperienceView, EmploymentTypeView, \
WorkTypeView, JobOfferView
from tests.fixtures import user, job_offer, job_offer_with_company, company
from tests.fixtures import user, job_offer, job_offer_with_company, company, job_offer_draft

factory = APIRequestFactory()

Expand Down Expand Up @@ -87,3 +87,13 @@ def test_success_return_job_offer_by_slug(job_offer, user):

assert response.status_code == 200
assert response.data["id"] == job_offer.id


@pytest.mark.django_db
def test_error_return_job_offer_draft_status_by_slug(job_offer_draft, user):
request = factory.get(f'/offer/{job_offer_draft.slug}/')
view = JobOfferView.as_view({"get": "retrieve"})
response = view(request, job_offer_draft.slug)
# Should return 404 because JobOffer has status "DRAFT" which means
# that it's not allow to the public access
assert response.status_code == 404

0 comments on commit d2bde72

Please sign in to comment.