Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Add test for model strings #444

Merged
merged 2 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from django.db import models
from django.contrib.auth import get_user_model
from creator.fields import KFIDField
from creator.fields import KFIDField, kf_id_generator
from creator.studies.models import Study
from creator.files.models import File

Expand All @@ -22,6 +22,14 @@ def test_kf_id_prefix_value(db):
assert File.objects.get(kf_id=kf_id) == f


def test_wrong_len():
""" Test that kf_ids must use a two character prefix """
with pytest.raises(ValueError) as err:
kf_id = kf_id_generator("ABC")

assert "of length 2" in err


def test_user_display_name(db):
user = User(username="user", first_name="Test", last_name=None)
assert user.display_name == "Test"
Expand Down
21 changes: 21 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
import uuid

from creator.studies.models import Study
from creator.files.models import File, Version, DownloadToken
from creator.projects.models import Project


@pytest.mark.parametrize(
"model,expected",
[
(Study, "SD_00000001"),
(File, "SF_00000001"),
(Version, "FV_00000001"),
(Project, "test/test"),
],
)
def test_str(model, expected):
""" Test string conversion functions """
obj = model(pk=expected)
assert str(obj) == expected