model tests
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/python
|
||||||
|
|
||||||
|
from src.models import Category
|
||||||
|
|
||||||
|
|
||||||
|
def test_single_level_category():
|
||||||
|
c = Category.from_str("single")
|
||||||
|
assert c
|
||||||
|
assert c.name == "single"
|
||||||
|
assert c.parent is None
|
||||||
|
|
||||||
|
def test_two_level_category():
|
||||||
|
c = Category.from_str("first:second")
|
||||||
|
assert c
|
||||||
|
assert c.name == "second"
|
||||||
|
assert isinstance(c.parent, Category)
|
||||||
|
assert c.parent.name == "first"
|
||||||
|
assert c.parent.parent is None
|
||||||
|
|
||||||
|
def test_three_level_category():
|
||||||
|
c = Category.from_str("first:second:third")
|
||||||
|
assert c
|
||||||
|
assert c.name == "third"
|
||||||
|
assert isinstance(c.parent, Category)
|
||||||
|
assert c.parent.name == "second"
|
||||||
|
assert isinstance(c.parent.parent, Category)
|
||||||
|
assert c.parent.parent.name == "first"
|
||||||
|
assert c.parent.parent.parent is None
|
||||||
|
|
||||||
|
def test_single_level_category_to_string():
|
||||||
|
c = Category.from_str("single")
|
||||||
|
assert c
|
||||||
|
assert str(c) == "single"
|
||||||
|
|
||||||
|
def test_two_level_category_to_string():
|
||||||
|
c = Category(name = "second", parent=Category(name = "first"))
|
||||||
|
assert c.to_str() == "first:second"
|
||||||
|
|
||||||
|
def test_three_level_category_to_string():
|
||||||
|
c = Category(name = "third", parent=Category(name = "second", parent=Category(name="first")))
|
||||||
|
assert c.to_str() == "first:second:third"
|
||||||
|
|
||||||
|
def test_category_str():
|
||||||
|
c = Category.from_str("first:second:third")
|
||||||
|
assert str(c) == "first:second:third"
|
||||||
|
|
||||||
|
def test_category_repr():
|
||||||
|
c = Category.from_str("first:second:third")
|
||||||
|
assert repr(c) == "Category.from_str(\"first:second:third\")"
|
||||||
|
|
||||||
Reference in New Issue
Block a user