Skip to content

Commit

Permalink
Unittest for OfferListView and OfferListView
Browse files Browse the repository at this point in the history
  • Loading branch information
DEENUU1 committed Dec 9, 2023
1 parent 9f0fdad commit fe10f15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion offer/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class JobOfferSerializer(ModelSerializer):
work_type = WorkTypeSerializer(many=True)
employment_type = EmploymentTypeSerializer(many=True)
company = CompanySerializer()
adresses = AddressSerializer(many=True)
addresses = AddressSerializer(many=True)
is_new = serializers.ReadOnlyField()
is_expired = serializers.ReadOnlyField()
days_until_expiration_str = serializers.ReadOnlyField()
Expand Down
22 changes: 21 additions & 1 deletion tests/test_offer/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from tests.fixtures import user, job_offer, job_offer_with_company, user_second, company
from rest_framework.test import force_authenticate, APIRequestFactory
from offer.views import CompanyOfferListView, OfferListView, SalaryView, ExperienceView, EmploymentTypeView, \
WorkTypeView
WorkTypeView, JobOfferView
import json
from offer.models import JobOffer, WorkType, EmploymentType, Experience, Salary

Expand Down Expand Up @@ -67,3 +67,23 @@ def test_success_return_min_max_salary_empty():

assert response.status_code == 204
assert response.data is None


@pytest.mark.django_db
def test_success_return_list_of_job_offers(user, job_offer, job_offer_with_company, company):
request = factory.get('/offer/')
view = OfferListView.as_view()
response = view(request)

assert response.status_code == 200
assert len(response.data) == 4


@pytest.mark.django_db
def test_success_return_job_offer_by_id(job_offer, user):
request = factory.get(f'/offer/{job_offer.id}/')
view = JobOfferView.as_view({"get": "retrieve"})
response = view(request, job_offer.id)

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

0 comments on commit fe10f15

Please sign in to comment.