Skip to content
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
6 changes: 3 additions & 3 deletions octue/resources/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from octue.utils.encoders import OctueJSONEncoder


TAG_PATTERN = re.compile(r"^$|^[a-z0-9][a-z0-9:\-]*(?<![:-])$")
TAG_PATTERN = re.compile(r"^$|^[A-Za-z0-9][A-Za-z0-9:\-/]*(?<![/:-])$")


class Tag(Filterable):
"""A tag starts and ends with a character in [a-z] or [0-9]. It can contain the colon discriminator or hyphens.
Empty strings are also valid. More valid examples:
"""A tag starts and ends with a character in [A-Za-z0-9]. It can contain the colon discriminator, forward slashes
or hyphens. Empty strings are also valid. More valid examples:
system:32
angry-marmaduke
mega-man:torso:component:12
Expand Down
11 changes: 0 additions & 11 deletions tests/mixins/test_taggable.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ def test_instantiates_with_tags(self):
taggable = MyTaggable(tags="a b c")
self.assertEqual(set(taggable.tags), {Tag("a"), Tag("b"), Tag("c")})

with self.assertRaises(exceptions.InvalidTagException):
MyTaggable(tags=":a b c")

def test_instantiates_with_tag_set(self):
"""Ensures datafile inherits correctly from the Taggable class and passes arguments through"""
taggable_1 = MyTaggable(tags="")
Expand Down Expand Up @@ -76,14 +73,6 @@ def test_valid_tags(self):
},
)

def test_invalid_tags(self):
"""Ensures invalid tags raise an error"""
taggable = MyTaggable()

for tag in "-bah", "humbug:", "SHOUTY", r"back\slashy", {"not-a": "string"}:
with self.assertRaises(exceptions.InvalidTagException):
taggable.add_tags(tag)

def test_mixture_valid_invalid(self):
"""Ensures that adding a variety of tags, some of which are invalid, doesn't partially add them to the object"""
taggable = MyTaggable()
Expand Down
12 changes: 12 additions & 0 deletions tests/resources/test_tag.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
from octue import exceptions
from octue.resources.filter_containers import FilterList, FilterSet
from octue.resources.tag import Tag, TagSet
from tests.base import BaseTestCase


class TestTag(BaseTestCase):
def test_invalid_tags_cause_error(self):
"""Test that invalid tags cause an error to be raised."""
for tag in ":a", "@", "a_b", "-bah", "humbug:", r"back\slashy", {"not-a": "string"}, "/a", "a/":
with self.assertRaises(exceptions.InvalidTagException):
Tag(tag)

def test_valid_tags(self):
"""Test that valid tags instantiate as expected."""
for tag in "hello", "hello:world", "hello-world:goodbye", "HELLO-WORLD", "Asia/Pacific":
Tag(tag)

def test_subtags(self):
""" Test that subtags are correctly parsed from tags. """
self.assertEqual(Tag("a:b:c").subtags, FilterList([Tag("a"), Tag("b"), Tag("c")]))
Expand Down