test_comparison.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. import datetime
  4. import dingguo
  5. import yaml
  6. import os
  7. def get_item_a():
  8. return dingguo.Item(
  9. name = u'item',
  10. price_brutto = dingguo.Sum(1.0, u'EUR'),
  11. )
  12. def get_item_b():
  13. return dingguo.Item(
  14. name = u'item',
  15. price_brutto = dingguo.Sum(2.0, u'EUR'),
  16. )
  17. def get_discount_a():
  18. return dingguo.Discount(
  19. name = u'discount',
  20. amount = dingguo.Sum(1.0, u'EUR'),
  21. )
  22. def get_discount_b():
  23. return dingguo.Discount(
  24. name = u'discount',
  25. amount = dingguo.Sum(2.0, u'EUR'),
  26. )
  27. def get_order_a(items = True):
  28. order = dingguo.Order(
  29. platform = u'platform',
  30. order_id = u'id',
  31. order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
  32. customer_id = u'customer',
  33. )
  34. if items:
  35. order.items.append(get_item_a())
  36. order.items.append(get_item_b())
  37. order.discounts.append(get_discount_a())
  38. order.discounts.append(get_discount_b())
  39. return order
  40. def get_order_b():
  41. order = dingguo.Order(
  42. platform = u'platform',
  43. order_id = u'id',
  44. order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
  45. )
  46. order.items.append(get_item_a())
  47. order.items.append(get_item_b())
  48. order.discounts.append(get_discount_a())
  49. order.discounts.append(get_discount_b())
  50. return order
  51. def get_order_c():
  52. order = dingguo.Order(
  53. platform = u'platform',
  54. order_id = u'id',
  55. order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
  56. )
  57. order.items.append(get_item_a())
  58. order.items.append(get_item_b())
  59. order.items.append(get_item_b())
  60. order.discounts.append(get_discount_a())
  61. order.discounts.append(get_discount_b())
  62. return order
  63. def test_figure_eq():
  64. assert dingguo.Figure(1, u'mm') == dingguo.Figure(1, u'mm')
  65. def test_figure_eq_inverted():
  66. assert not dingguo.Figure(1, u'mm') == dingguo.Figure(2, u'mm')
  67. def test_figure_ne():
  68. assert dingguo.Figure(1, u'mm') != dingguo.Figure(2, u'mm')
  69. def test_figure_ne_inverted():
  70. assert not dingguo.Figure(1, u'mm') != dingguo.Figure(1, u'mm')
  71. def test_item_eq():
  72. assert get_item_a() == get_item_a()
  73. assert get_item_b() == get_item_b()
  74. def test_item_eq_inverted():
  75. assert not get_item_a() == get_item_b()
  76. def test_item_ne():
  77. assert get_item_a() != get_item_b()
  78. def test_item_ne_inverted():
  79. assert not get_item_a() != get_item_a()
  80. assert not get_item_b() != get_item_b()
  81. def test_discount_eq():
  82. assert get_discount_a() == get_discount_a()
  83. assert get_discount_b() == get_discount_b()
  84. def test_discount_eq_inverted():
  85. assert not get_discount_a() == get_discount_b()
  86. def test_discount_ne():
  87. assert get_discount_a() != get_discount_b()
  88. def test_discount_ne_inverted():
  89. assert not get_discount_a() != get_discount_a()
  90. assert not get_discount_b() != get_discount_b()
  91. def test_order_eq():
  92. assert get_order_a() == get_order_a()
  93. assert get_order_b() == get_order_b()
  94. assert get_order_c() == get_order_c()
  95. def test_order_eq_inverted():
  96. assert not get_order_a() == get_order_c()
  97. assert not get_order_b() == get_order_a()
  98. assert not get_order_c() == get_order_b()
  99. def test_order_ne():
  100. assert get_order_a() != get_order_c()
  101. assert get_order_b() != get_order_a()
  102. assert get_order_c() != get_order_b()
  103. def test_order_ne_inverted():
  104. assert not get_order_a() != get_order_a()
  105. assert not get_order_b() != get_order_b()
  106. assert not get_order_c() != get_order_c()
  107. def test_order_ne_items():
  108. assert get_order_a() != get_order_a(items = False)
  109. def test_order_ne_items_reversed():
  110. order = get_order_a()
  111. order.items = order.items[::-1]
  112. assert get_order_a() != order