-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: create unit tests for experience repository (#11)
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pytest | ||
from rest_framework.exceptions import NotFound | ||
from offer.models import Experience | ||
from offer.repository.experience_repository import ExperienceRepository | ||
|
||
@pytest.fixture | ||
def repository(): | ||
return ExperienceRepository() | ||
|
||
@pytest.mark.django_db | ||
def test_create_experience(repository): | ||
experience_data = { | ||
"name": "Entry Level", | ||
} | ||
experience = repository.create(experience_data) | ||
assert experience.id is not None | ||
assert experience.name == "Entry Level" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_get_experience_by_id(repository): | ||
experience_data = { | ||
"name": "Senior", | ||
} | ||
created_experience = repository.create(experience_data) | ||
|
||
retrieved_experience = repository.get_by_id(created_experience.id) | ||
assert retrieved_experience is not None | ||
assert retrieved_experience.name == "Senior" | ||
|
||
@pytest.mark.django_db | ||
def test_update_experience(repository): | ||
experience_data = { | ||
"name": "Junior", | ||
} | ||
created_experience = repository.create(experience_data) | ||
|
||
updated_data = {"name": "Associate"} | ||
updated_experience = repository.update(created_experience.id, updated_data) | ||
|
||
assert updated_experience is not None | ||
assert updated_experience.name == "Associate" | ||
|
||
@pytest.mark.django_db | ||
def test_delete_experience(repository): | ||
experience_data = { | ||
"name": "Intern", | ||
} | ||
created_experience = repository.create(experience_data) | ||
|
||
repository.delete(created_experience.id) | ||
|
||
with pytest.raises(NotFound): | ||
repository.get_by_id(created_experience.id) |