Browse Source

yaml support for transportation

Fabian Peter Hammerle 8 years ago
parent
commit
de50b9d7eb
2 changed files with 33 additions and 2 deletions
  1. 2 0
      dingguo/__init__.py
  2. 31 2
      tests/test_yaml.py

+ 2 - 0
dingguo/__init__.py

@@ -318,6 +318,8 @@ yaml.SafeDumper.add_representer(Article, lambda dumper, article: dumper.represen
 
 class Transportation(Item):
 
+    yaml_tag = u'!transportation'
+
     def __init__(
             self,
             departure_point = None,

+ 31 - 2
tests/test_yaml.py

@@ -43,6 +43,15 @@ def get_article():
             state = u'goood',
             )
 
+def get_transportation():
+    return dingguo.Transportation(
+            name = u'ticket',
+            price_brutto = get_sum_a(),
+            departure_point = u'home',
+            destination_point = u'city',
+            distance = dingguo.Distance(3.21, u'km'),
+            )
+
 def get_discount_a():
     return dingguo.Discount(
             name = u'discount a',
@@ -225,7 +234,7 @@ def test_distance_to_yaml():
 def test_distance_from_yaml():
     assert dingguo.Distance(1.34, u'km') == yaml.load(u"!distance '1.34 km'\n")
 
-def test_article_to_yaml_a():
+def test_article_to_yaml():
     assert to_yaml(get_article()) == u"""!article
 authors:
 - a
@@ -239,7 +248,7 @@ shipper: shipper
 state: goood
 """
 
-def test_article_to_yaml_a():
+def test_article_to_yaml():
     assert get_article() == yaml.load(u"""!article
 authors:
 - a
@@ -252,3 +261,23 @@ reseller: seller
 shipper: shipper
 state: goood
 """)
+
+def test_transportation_to_yaml():
+    assert to_yaml(get_transportation()) == u"""!transportation
+departure_point: home
+destination_point: city
+distance: !distance '3.21 km'
+name: ticket
+price_brutto: !sum '1.23 EUR'
+route_map: null
+"""
+
+def test_transportation_from_yaml():
+    assert get_transportation() == yaml.load(u"""!transportation
+departure_point: home
+destination_point: city
+distance: !distance '3.21 km'
+name: ticket
+price_brutto: !sum '1.23 EUR'
+route_map: null
+""")