123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- # -*- coding: utf-8 -*-
- import pytest
- import datetime
- import dingguo
- import os
- import pprint
- import pytz
- import yaml
- def get_item_a():
- return dingguo.Item(
- name = u'item',
- price_brutto = dingguo.Sum(1.0, u'EUR'),
- )
- def get_item_b():
- return dingguo.Item(
- name = u'item',
- price_brutto = dingguo.Sum(2.0, u'EUR'),
- )
- def get_discount_a():
- return dingguo.Discount(
- name = u'discount',
- amount = dingguo.Sum(1.0, u'EUR'),
- )
- def get_discount_b():
- return dingguo.Discount(
- name = u'discount',
- amount = dingguo.Sum(2.0, u'EUR'),
- )
- def get_order_a(items = True):
- order = dingguo.Order(
- platform = u'platform',
- order_id = u'id',
- order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
- customer_id = u'customer',
- )
- if items:
- order.items.append(get_item_a())
- order.items.append(get_item_b())
- order.discounts.append(get_discount_a())
- order.discounts.append(get_discount_b())
- return order
- def get_order_b():
- order = dingguo.Order(
- platform = u'platform',
- order_id = u'id',
- order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
- )
- order.items.append(get_item_a())
- order.items.append(get_item_b())
- order.discounts.append(get_discount_a())
- order.discounts.append(get_discount_b())
- return order
- def get_order_c():
- order = dingguo.Order(
- platform = u'platform',
- order_id = u'id',
- order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
- )
- order.items.append(get_item_a())
- order.items.append(get_item_b())
- order.items.append(get_item_b())
- order.discounts.append(get_discount_a())
- order.discounts.append(get_discount_b())
- return order
- def get_campaign_a():
- return dingguo.Campaign(
- name = u'campaign a',
- founder = u'company',
- end = datetime.datetime(2016, 7, 23, 9, 23, 17, tzinfo = pytz.timezone('Europe/Vienna')),
- )
- def get_campaign_b():
- return dingguo.Campaign(
- name = u'campaign b',
- founder = u'company',
- end = datetime.datetime(2016, 7, 23, 9, 23, 17, tzinfo = pytz.timezone('Europe/Vienna')),
- )
- def get_pledge_a():
- return dingguo.Pledge(
- campaign = get_campaign_a(),
- price_brutto = dingguo.Sum(10.0, u'EUR'),
- )
- def get_pledge_b():
- return dingguo.Pledge(
- campaign = get_campaign_a(),
- price_brutto = dingguo.Sum(4.0, u'EUR'),
- )
- def get_person_a():
- return dingguo.Person(
- first_name = u'Fabian Peter',
- last_name = u'Hammerle',
- )
- def get_person_b():
- return dingguo.Person(
- first_name = u'名字',
- last_name = u'贵姓',
- )
- def get_shipping():
- return dingguo.Shipping(
- price_brutto = dingguo.Sum(10.0, u'EUR'),
- destination_point = u'home',
- )
- @pytest.mark.parametrize('a,b', [
- [dingguo.Figure(1, u'mm'), dingguo.Figure(1, u'mm')],
- [get_campaign_a(), get_campaign_a()],
- [get_campaign_b(), get_campaign_b()],
- [get_discount_a(), get_discount_a()],
- [get_discount_b(), get_discount_b()],
- [get_item_a(), get_item_a()],
- [get_item_b(), get_item_b()],
- [get_order_a(), get_order_a()],
- [get_order_b(), get_order_b()],
- [get_order_c(), get_order_c()],
- [get_person_a(), get_person_a()],
- [get_person_b(), get_person_b()],
- [get_pledge_a(), get_pledge_a()],
- [get_pledge_b(), get_pledge_b()],
- [get_shipping(), get_shipping()],
- ])
- def test_eq(a, b):
- assert a == b, '\n'.join([
- 'a = %r' % a,
- 'b = %r' % b,
- 'vars(a) = %s' % pprint.pformat(vars(a)),
- 'vars(b) = %s' % pprint.pformat(vars(b)),
- ])
- assert b == a
- assert not a != b
- assert not b != a
- @pytest.mark.parametrize('a,b', [
- [dingguo.Figure(1, u'mm'), dingguo.Figure(2, u'mm')],
- [get_discount_a(), get_discount_b()],
- [get_item_a(), get_item_b()],
- [get_order_a(), get_order_a(items = False)],
- [get_order_a(), get_order_b()],
- [get_order_a(), get_order_c()],
- [get_order_b(), get_order_c()],
- [get_person_a(), get_person_b()],
- [get_pledge_a(), get_order_b()],
- [get_pledge_a(), get_pledge_b()],
- ])
- def test_neq(a, b):
- assert a != b
- assert b != a
- assert not a == b
- assert not b == a
- def test_order_ne_items_reversed():
- order = get_order_a()
- order.items = order.items[::-1]
- assert get_order_a() != order
|