Skip to content

Commit

Permalink
Merge pull request #444 from kids-first/str-checks
Browse files Browse the repository at this point in the history
✅ Add test for model strings
  • Loading branch information
dankolbman authored Aug 6, 2020
2 parents faf2d40 + 4caa484 commit 2b02f77
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 2b02f77

Please sign in to comment.