test_comparison.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. import datetime
  4. import dingguo
  5. import os
  6. import pprint
  7. import pytz
  8. import yaml
  9. def get_item_a():
  10. return dingguo.Item(
  11. name = u'item',
  12. price_brutto = dingguo.Sum(1.0, u'EUR'),
  13. )
  14. def get_item_b():
  15. return dingguo.Item(
  16. name = u'item',
  17. price_brutto = dingguo.Sum(2.0, u'EUR'),
  18. )
  19. def get_discount_a():
  20. return dingguo.Discount(
  21. name = u'discount',
  22. amount = dingguo.Sum(1.0, u'EUR'),
  23. )
  24. def get_discount_b():
  25. return dingguo.Discount(
  26. name = u'discount',
  27. amount = dingguo.Sum(2.0, u'EUR'),
  28. )
  29. def get_order_a(items = True):
  30. order = dingguo.Order(
  31. platform = u'platform',
  32. order_id = u'id',
  33. order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
  34. customer_id = u'customer',
  35. )
  36. if items:
  37. order.items.append(get_item_a())
  38. order.items.append(get_item_b())
  39. order.discounts.append(get_discount_a())
  40. order.discounts.append(get_discount_b())
  41. return order
  42. def get_order_b():
  43. order = dingguo.Order(
  44. platform = u'platform',
  45. order_id = u'id',
  46. order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
  47. )
  48. order.items.append(get_item_a())
  49. order.items.append(get_item_b())
  50. order.discounts.append(get_discount_a())
  51. order.discounts.append(get_discount_b())
  52. return order
  53. def get_order_c():
  54. order = dingguo.Order(
  55. platform = u'platform',
  56. order_id = u'id',
  57. order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
  58. )
  59. order.items.append(get_item_a())
  60. order.items.append(get_item_b())
  61. order.items.append(get_item_b())
  62. order.discounts.append(get_discount_a())
  63. order.discounts.append(get_discount_b())
  64. return order
  65. def get_campaign_a():
  66. return dingguo.Campaign(
  67. name = u'campaign a',
  68. founder = u'company',
  69. end = datetime.datetime(2016, 7, 23, 9, 23, 17, tzinfo = pytz.timezone('Europe/Vienna')),
  70. )
  71. def get_campaign_b():
  72. return dingguo.Campaign(
  73. name = u'campaign b',
  74. founder = u'company',
  75. end = datetime.datetime(2016, 7, 23, 9, 23, 17, tzinfo = pytz.timezone('Europe/Vienna')),
  76. )
  77. def get_pledge_a():
  78. return dingguo.Pledge(
  79. campaign = get_campaign_a(),
  80. price_brutto = dingguo.Sum(10.0, u'EUR'),
  81. )
  82. def get_pledge_b():
  83. return dingguo.Pledge(
  84. campaign = get_campaign_a(),
  85. price_brutto = dingguo.Sum(4.0, u'EUR'),
  86. )
  87. def get_person_a():
  88. return dingguo.Person(
  89. first_name = u'Fabian Peter',
  90. last_name = u'Hammerle',
  91. )
  92. def get_person_b():
  93. return dingguo.Person(
  94. first_name = u'名字',
  95. last_name = u'贵姓',
  96. )
  97. def get_shipping():
  98. return dingguo.Shipping(
  99. price_brutto = dingguo.Sum(10.0, u'EUR'),
  100. destination_point = u'home',
  101. )
  102. @pytest.mark.parametrize('a,b', [
  103. [dingguo.Figure(1, u'mm'), dingguo.Figure(1, u'mm')],
  104. [get_campaign_a(), get_campaign_a()],
  105. [get_campaign_b(), get_campaign_b()],
  106. [get_discount_a(), get_discount_a()],
  107. [get_discount_b(), get_discount_b()],
  108. [get_item_a(), get_item_a()],
  109. [get_item_b(), get_item_b()],
  110. [get_order_a(), get_order_a()],
  111. [get_order_b(), get_order_b()],
  112. [get_order_c(), get_order_c()],
  113. [get_person_a(), get_person_a()],
  114. [get_person_b(), get_person_b()],
  115. [get_pledge_a(), get_pledge_a()],
  116. [get_pledge_b(), get_pledge_b()],
  117. [get_shipping(), get_shipping()],
  118. ])
  119. def test_eq(a, b):
  120. assert a == b, '\n'.join([
  121. 'a = %r' % a,
  122. 'b = %r' % b,
  123. 'vars(a) = %s' % pprint.pformat(vars(a)),
  124. 'vars(b) = %s' % pprint.pformat(vars(b)),
  125. ])
  126. assert b == a
  127. assert not a != b
  128. assert not b != a
  129. @pytest.mark.parametrize('a,b', [
  130. [dingguo.Figure(1, u'mm'), dingguo.Figure(2, u'mm')],
  131. [get_discount_a(), get_discount_b()],
  132. [get_item_a(), get_item_b()],
  133. [get_order_a(), get_order_a(items = False)],
  134. [get_order_a(), get_order_b()],
  135. [get_order_a(), get_order_c()],
  136. [get_order_b(), get_order_c()],
  137. [get_person_a(), get_person_b()],
  138. [get_pledge_a(), get_order_b()],
  139. [get_pledge_a(), get_pledge_b()],
  140. ])
  141. def test_neq(a, b):
  142. assert a != b
  143. assert b != a
  144. assert not a == b
  145. assert not b == a
  146. def test_order_ne_items_reversed():
  147. order = get_order_a()
  148. order.items = order.items[::-1]
  149. assert get_order_a() != order