Skip to content

Commit

Permalink
test: create unit tests for employment_type repository (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
DEENUU1 committed Feb 26, 2024
1 parent 30bf053 commit a20e115
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_offer/test_employment_type_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pytest
from rest_framework.exceptions import NotFound
from offer.models import EmploymentType
from offer.repository.employment_type_repository import EmploymentTypeRepository

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

@pytest.mark.django_db
def test_create_employment_type(repository):
employment_type_data = {
"name": "Full-Time",
}
employment_type = repository.create(employment_type_data)
assert employment_type.id is not None
assert employment_type.name == "Full-Time"

@pytest.mark.django_db
def test_get_employment_type_by_id(repository):
employment_type_data = {
"name": "Contract",
}
created_employment_type = repository.create(employment_type_data)

retrieved_employment_type = repository.get_by_id(created_employment_type.id)
assert retrieved_employment_type is not None
assert retrieved_employment_type.name == "Contract"

@pytest.mark.django_db
def test_update_employment_type(repository):
employment_type_data = {
"name": "Temporary",
}
created_employment_type = repository.create(employment_type_data)

updated_data = {"name": "Fixed-Term"}
updated_employment_type = repository.update(created_employment_type.id, updated_data)

assert updated_employment_type is not None
assert updated_employment_type.name == "Fixed-Term"

@pytest.mark.django_db
def test_delete_employment_type(repository):
employment_type_data = {
"name": "Internship",
}
created_employment_type = repository.create(employment_type_data)

repository.delete(created_employment_type.id)

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

0 comments on commit a20e115

Please sign in to comment.