test_comparison.py 5.3 KB

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