예제 #1
0
파일: tests.py 프로젝트: tbson/24ho
    def setUp(self):
        CustomerUtils.seeding(1, True)

        self.client = APIClient()
        self.client.credentials(HTTP_AUTHORIZATION='JWT ' + TestHelpers.get_customer_token())

        self.items = BolUtils.seeding(3)
예제 #2
0
파일: tests.py 프로젝트: tbson/24ho
    def setUp(self):
        customer = CustomerUtils.seeding(1, True)
        self.customer1 = CustomerUtils.seeding(2, True)

        self.items = BolUtils.seeding(3)
        self.ids = [self.items[0].pk, self.items[1].pk, self.items[2].pk]

        for item in self.items:
            item.address = None
            item.address_code = ''
            item.customer = customer
            item.save()
예제 #3
0
파일: tests.py 프로젝트: tbson/24ho
    def test_create_new_uid(self):
        # Add success
        CustomerUtils.seeding(1, True)
        self.client.credentials(HTTP_AUTHORIZATION='JWT ' +
                                TestHelpers.get_customer_token())

        item1 = AddressUtils.seeding(1, True, False)
        resp = self.client.post('/api/v1/address/', item1, format='json')
        resp = resp.json()
        self.assertEqual(resp['uid'], '1UID10')

        item2 = AddressUtils.seeding(2, True, False)
        resp = self.client.post('/api/v1/address/', item2, format='json')
        resp = resp.json()
        self.assertEqual(resp['uid'], '1UID11')
예제 #4
0
파일: tests.py 프로젝트: tbson/24ho
    def setUp(self):
        CustomerUtils.seeding(1, True)
        customer2 = CustomerUtils.seeding(2, True)
        user2 = TestHelpers.user_seeding(2, True)
        customer2.user_id = user2.pk
        customer2.save()

        self.client = APIClient()
        self.client.credentials(HTTP_AUTHORIZATION='JWT ' + TestHelpers.get_customer_token())

        self.items = BolUtils.seeding(3)
        self.items[2].address = None
        self.items[2].address_code = ''
        self.items[2].customer = customer2
        self.items[2].save()
예제 #5
0
파일: tests.py 프로젝트: tbson/24ho
    def test_customer_did_set_deposit_factor_over_90(self):
        customer = CustomerUtils.seeding(1, True)
        customer.deposit_factor = 90.1
        customer.save()

        order = OrderUtils.seeding(1, True, customer=customer)
        self.assertEqual(order.deposit_factor, settings.DEPOSIT_FACTOR)
예제 #6
0
    def seeding(index: int,
                single: bool = False,
                save: bool = True) -> models.QuerySet:
        from .serializers import ReceiptBaseSr
        from .models import Type

        customer = CustomerUtils.seeding(1, True)
        staff = StaffUtils.seeding(1, True)
        address = AddressUtils.seeding(1, True)

        if index == 0:
            raise Exception('Indext must be start with 1.')

        def get_data(i: int) -> dict:
            data = {
                'customer': customer.pk,
                'staff': staff.pk,
                'address': address.pk,
                'type': Type.ORDER,
                'vnd_sub_fee': 1000 + i,
                'vnd_total': 10000 + i
            }
            if save is False:
                return data

            instance = ReceiptBaseSr(data=data)
            instance.is_valid(raise_exception=True)
            instance = instance.save()
            return instance

        def get_list_data(index):
            return [get_data(i) for i in range(1, index + 1)]

        return get_data(index) if single is True else get_list_data(index)
예제 #7
0
파일: utils.py 프로젝트: tbson/24ho
    def seeding(index: int,
                single: bool = False,
                save: bool = True) -> models.QuerySet:
        from .serializers import CustomerBankBaseSr
        if index == 0:
            raise Exception('Indext must be start with 1.')

        customer = CustomerUtils.seeding(1, True)

        def get_data(i: int) -> dict:
            data = {
                'customer': customer.pk,
                'bank_name': "bank_name{}".format(i),
                'account_name': "name{}".format(i),
                'account_number': "123{}".format(i)
            }
            if save is False:
                return data

            instance = CustomerBankBaseSr(data=data)
            instance.is_valid(raise_exception=True)
            instance = instance.save()
            return instance

        def get_list_data(index):
            return [get_data(i) for i in range(1, index + 1)]

        return get_data(index) if single is True else get_list_data(index)
예제 #8
0
파일: tests.py 프로젝트: tbson/24ho
    def test_success(self):
        customer = CustomerUtils.seeding(1, True)
        customer.deposit_factor = 80.1
        customer.save()

        order = OrderUtils.seeding(1, True, customer=customer)
        self.assertEqual(order.deposit_factor, customer.deposit_factor)
예제 #9
0
파일: utils.py 프로젝트: tbson/24ho
    def seeding(index: int,
                single: bool = False,
                save: bool = True) -> models.QuerySet:
        from apps.address.serializers import AddressBaseSr

        if index == 0:
            raise Exception('Indext must be start with 1.')

        customer = CustomerUtils.seeding(1, True)
        area = AreaUtils.seeding(1, True)

        def get_data(i: int) -> dict:
            data = {
                'customer': customer.pk,
                'area': area.pk,
                'title': "title{}".format(i),
                'phone': "phone{}".format(i),
                'fullname': "fullname{}".format(i)
            }

            if save is False:
                return data

            instance = AddressBaseSr(data=data)
            instance.is_valid(raise_exception=True)
            instance = instance.save()
            return instance

        def get_list_data(index):
            return [get_data(i) for i in range(1, index + 1)]

        return get_data(index) if single is True else get_list_data(index)
예제 #10
0
파일: tests.py 프로젝트: tbson/24ho
    def setUp(self):
        self.customer = CustomerUtils.seeding(1, True)
        self.staff = StaffUtils.seeding(1, True)

        self.bol = BolUtils.seeding(1, True)
        self.bol.mass = 5
        self.bol.insurance = True
        self.bol.cny_insurance_value = 500
        self.bol.cny_sub_fee = 6.2
        self.bol.cny_shockproof_fee = 0
        self.bol.cny_wooden_box_fee = 1
        self.bol.save()
예제 #11
0
파일: tests.py 프로젝트: tbson/24ho
    def test_success(self):
        customer = CustomerUtils.seeding(1, True)
        customer.deposit_factor = 50
        customer.save()

        order = OrderUtils.seeding(1, True, customer=customer)
        OrderItemUtils.seeding(1, True, order=order)

        deposit_amount = OrderUtils.get_deposit_amount(order)
        vnd_total = OrderUtils.get_vnd_total(OrderBaseSr(order).data)
        self.assertEqual(OrderUtils.get_remain_after_deposit_amount(order),
                         int(vnd_total) - deposit_amount)
예제 #12
0
파일: tests.py 프로젝트: tbson/24ho
    def setUp(self):
        self.customer = CustomerUtils.seeding(1, True)
        self.staff = StaffUtils.seeding(1, True)

        self.order = OrderUtils.seeding(1, True, customer=self.customer)
        self.order.status = Status.NEW

        OrderItemUtils.seeding(1, True, order=self.order)

        self.bol = BolUtils.seeding(1, True, order=self.order)
        self.bol.mass = 5
        self.bol.save()

        OrderUtils.force_cal(self.order)
예제 #13
0
파일: tests.py 프로젝트: tbson/24ho
    def test_only_set_in_customer(self):
        customer = CustomerUtils.seeding(1, True)
        customer.delivery_fee_volume_unit_price = 30000
        customer.save()

        item = BolUtils.seeding(1, True)
        item.customer = customer
        item.save()

        output = BolUtils.cal_delivery_fee_volume_unit_price(item)
        eput = {
            'RANGE': 2.5,
            'FIXED': 30000
        }
        self.assertEqual(output, eput)
예제 #14
0
파일: tests.py 프로젝트: tbson/24ho
    def test_set_in_customer_and_bol(self):
        customer = CustomerUtils.seeding(1, True)
        customer.delivery_fee_mass_unit_price = 30000
        customer.save()

        item = BolUtils.seeding(1, True)
        item.customer = customer
        item.mass_unit_price = 40000
        item.save()

        output = BolUtils.cal_delivery_fee_mass_unit_price(item)
        eput = {
            'RANGE': 1.5,
            'FIXED': 40000
        }
        self.assertEqual(output, eput)
예제 #15
0
파일: tests.py 프로젝트: tbson/24ho
    def test_fall_back_to_default_value(self):
        customer = CustomerUtils.seeding(1, True)
        customer.delivery_fee_volume_unit_price = 0
        customer.save()

        item = BolUtils.seeding(1, True)
        item.customer = customer
        item.input_volume = 20
        item.volume_unit_price = 0
        item.save()

        output = BolUtils.cal_delivery_fee_volume_unit_price(item)
        eput = {
            'RANGE': 2.5,
            'FIXED': 0
        }
        self.assertEqual(output, eput)
예제 #16
0
파일: tests.py 프로젝트: tbson/24ho
    def test_success_case(self):
        self.assertEqual(Transaction.objects.count(), 0)

        # Recharge
        recharge_amount = 50000
        money_type = MoneyType.CASH
        customer = CustomerUtils.seeding(1, True)
        TransactionUtils.recharge(recharge_amount, money_type, customer,
                                  self.staff)
        self.assertEqual(Transaction.objects.count(), 1)

        # Approve
        success, _ = OrderUtils.approve(self.order, self.staff, self.staff)
        self.assertEqual(success, True)
        self.assertEqual(Transaction.objects.count(), 2)

        deposit_transaction = Transaction.objects.get(order=self.order,
                                                      type=Type.DEPOSIT)
        self.assertEqual(deposit_transaction.amount,
                         OrderUtils.get_deposit_amount(self.order))
예제 #17
0
파일: tests.py 프로젝트: tbson/24ho
    def test_normal_case(self):
        address = AddressUtils.seeding(1, True)
        customer = CustomerUtils.seeding(2, True)
        data = {
            'uid': str(uuid.uuid4()),
            'address': address.id,
            'shop_link': 'link1',
            'site': 'TAOBAO',
            'real_rate': 3300,
            'rate': 3400,
            'cny_amount': 100,
            'cny_order_fee': 5,
            'cny_inland_delivery_fee': 5.5,
            'cny_count_check_fee': 3,
            'cny_shockproof_fee': 3,
            'cny_wooden_box_fee': 3,
            'vnd_delivery_fee': 100000,
            'vnd_sub_fee': 20000,
            'cny_sub_fee': 12,
        }
        order = OrderBaseSr(data=data)
        order.is_valid(raise_exception=True)
        order_obj = order.save()

        self.assertEqual(order.data['vnd_total'], 567100)
        self.assertEqual(order.data['customer'], address.customer.pk)

        # Update address -> update customer
        address.customer = customer
        address.save()
        order = OrderBaseSr(order_obj,
                            data={'address': address.pk},
                            partial=True)
        order.is_valid(raise_exception=True)
        order.save()
        self.assertEqual(order.data['customer'], customer.pk)
예제 #18
0
파일: tests.py 프로젝트: tbson/24ho
 def test_customer_did_not_set_deposit_factor(self):
     customer = CustomerUtils.seeding(1, True)
     order = OrderUtils.seeding(1, True, customer=customer)
     self.assertEqual(order.deposit_factor, settings.DEPOSIT_FACTOR)