Skip to content

Commit

Permalink
test: create unit tests for work_type_repository (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
DEENUU1 committed Feb 26, 2024
1 parent 4604fe5 commit 2482190
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/test_offer/test_work_type_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest
from rest_framework.exceptions import NotFound

from offer.models import WorkType
from offer.repository.work_type_repository import WorkTypeRepository


@pytest.fixture
def repository():
return WorkTypeRepository()


@pytest.mark.django_db
def test_create(repository):
work_type_data = {"name": "Full-time"}

created_work_type = repository.create(work_type_data)

assert isinstance(created_work_type, WorkType)
assert created_work_type.name == "Full-time"


@pytest.mark.django_db
def test_get_by_id(repository):
work_type_data = {"name": "Full-time"}

created_work_type = repository.create(work_type_data)
retrieved_work_type = repository.get_by_id(created_work_type.id)

assert retrieved_work_type == created_work_type


@pytest.mark.django_db
def test_get_by_id_not_found(repository):
with pytest.raises(NotFound):
repository.get_by_id(999)


@pytest.mark.django_db
def test_update(repository):
work_type_data = {"name": "Full-time"}
updated_data = {"name": "Remote"}

created_work_type = repository.create(work_type_data)
updated_work_type = repository.update(created_work_type.id, updated_data)

assert updated_work_type.name == "Remote"


@pytest.mark.django_db
def test_update_not_found(repository):
with pytest.raises(NotFound):
repository.update(999, {"name": "Remote"})


@pytest.mark.django_db
def test_delete(repository):
work_type_data = {"name": "Full-time"}

created_work_type = repository.create(work_type_data)
repository.delete(created_work_type.id)

with pytest.raises(NotFound):
repository.get_by_id(created_work_type.id)


@pytest.mark.django_db
def test_delete_not_found(repository):
with pytest.raises(NotFound):
repository.delete(999)

0 comments on commit 2482190

Please sign in to comment.