Skip to content

Commit

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

from offer.models import Salary
from offer.repository.salary_repository import SalaryRepository


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


@pytest.mark.django_db
def test_create(repository):
salary_data = {"salary_from": 50000, "salary_to": 70000, "currency": "USD", "schedule": "Full-time"}

created_salary = repository.create(salary_data)

assert isinstance(created_salary, Salary)
assert created_salary.salary_from == 50000
assert created_salary.schedule == "Full-time"


@pytest.mark.django_db
def test_get_by_id(repository):
salary_data = {"salary_from": 50000, "salary_to": 70000, "currency": "USD", "schedule": "Full-time"}

created_salary = repository.create(salary_data)
retrieved_salary = repository.get_by_id(created_salary.id)

assert retrieved_salary == created_salary


@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):
salary_data = {"salary_from": 50000, "salary_to": 70000, "currency": "USD", "schedule": "Full-time"}
updated_data = {"salary_from": 60000, "currency": "EUR"}

created_salary = repository.create(salary_data)
updated_salary = repository.update(created_salary.id, updated_data)

assert updated_salary.salary_from == 60000
assert updated_salary.currency == "EUR"


@pytest.mark.django_db
def test_update_not_found(repository):
with pytest.raises(NotFound):
repository.update(999, {"salary_from": 60000, "currency": "EUR"})


@pytest.mark.django_db
def test_delete(repository):
salary_data = {"salary_from": 50000, "salary_to": 70000, "currency": "USD", "schedule": "Full-time"}

created_salary = repository.create(salary_data)
repository.delete(created_salary.id)

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


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

0 comments on commit 4604fe5

Please sign in to comment.