Example #1
0
File: tests.py Project: tbson/24ho
    def test_not_blank_names(self):
        address = AddressUtils.seeding(1, True)
        sale = StaffUtils.seeding(2, True)
        cust_care = StaffUtils.seeding(3, True)
        approver = StaffUtils.seeding(4, True)

        data = {
            'uid': str(uuid.uuid4()),
            'address': address.id,
            'sale': sale.id,
            'cust_care': cust_care.id,
            'approver': approver.id,
            'shop_link': 'link1',
            'site': 'TAOBAO',
            'rate': 3400,
            'real_rate': 3300,
        }
        order = OrderBaseSr(data=data)
        order.is_valid(raise_exception=True)
        order.save()

        self.assertEqual(order.data['customer_name'], 'last1 first1')
        self.assertEqual(order.data['sale_name'], 'last2 first2')
        self.assertEqual(order.data['cust_care_name'], 'last3 first3')
        self.assertEqual(order.data['approver_name'], 'last4 first4')
Example #2
0
    def seeding(index: int,
                single: bool = False,
                save: bool = True) -> models.QuerySet:
        from .serializers import BagBaseSr

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

        area = AreaUtils.seeding(1, True)
        staff = StaffUtils.seeding(1, True)

        def get_data(i: int) -> dict:

            data = {
                'area': area.pk,
                'staff': staff.pk,
            }
            if save is False:
                return data

            instance = BagBaseSr(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)
Example #3
0
File: utils.py Project: tbson/24ho
    def seeding(index: int,
                single: bool = False,
                save: bool = True) -> models.QuerySet:
        from apps.staff.utils import StaffUtils
        from .serializers import TransactionBaseSr
        from .models import Type, MoneyType
        if index == 0:
            raise Exception('Indext must be start with 1.')
        staff = StaffUtils.seeding(1, True)

        def get_data(i: int) -> dict:
            data = {
                'amount': 1000 + i,
                'staff': staff.pk,
                'type': Type.RECHARGE,
                'money_type': MoneyType.CASH
            }
            if save is False:
                return data

            instance = TransactionBaseSr(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)
Example #4
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)
Example #5
0
File: tests.py Project: tbson/24ho
    def test_normal_case(self):
        order = OrderUtils.seeding(1, True)
        staff = StaffUtils.seeding(1, True)

        TransactionUtils.deposit(order, staff)
        self.assertEqual(Transaction.objects.count(), 1)

        TransactionUtils.undeposit(order)
        self.assertEqual(Transaction.objects.count(), 0)
Example #6
0
File: tests.py Project: tbson/24ho
    def setUp(self):
        self.order = OrderUtils.seeding(1, True)
        self.order.status = Status.NEW

        self.staff = StaffUtils.seeding(1, True)

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

        OrderUtils.force_cal(self.order)
Example #7
0
File: tests.py Project: 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()
Example #8
0
File: tests.py Project: 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)
Example #9
0
File: tests.py Project: tbson/24ho
    def test_normal_case(self):
        order = OrderUtils.seeding(1, True)
        OrderItemUtils.seeding(2, order=order)

        staff = StaffUtils.seeding(1, True)
        TransactionUtils.recharge(100000000, MoneyType.CASH, order.customer, staff)
        self.assertEqual(Transaction.objects.count(), 1)

        TransactionUtils.deposit(order, staff)
        transaction = Transaction.objects.first()

        self.assertEqual(Transaction.objects.count(), 2)
        self.assertEqual(transaction.order, order)
        self.assertEqual(transaction.staff, staff)
        self.assertEqual(transaction.customer, order.customer)
        self.assertEqual(transaction.amount, OrderUtils.get_deposit_amount(order))
        self.assertEqual(transaction.type, Type.DEPOSIT)
Example #10
0
File: tests.py Project: tbson/24ho
    def test_cust_care(self):
        cust_care = StaffUtils.seeding(1, True)

        # Update not exist
        response = self.client.put(
            "/api/v1/order/{}/change-cust-care/".format(0), {}, format='json')
        self.assertEqual(response.status_code, 404)

        # Update exist staff
        response = self.client.put("/api/v1/order/{}/change-cust-care/".format(
            self.item.pk), {"value": cust_care.pk},
                                   format='json')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['cust_care'], cust_care.pk)

        # Update not exist staff -> do not change original value
        response = self.client.put("/api/v1/order/{}/change-cust-care/".format(
            self.item.pk), {"value": 9999},
                                   format='json')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['cust_care'], cust_care.pk)
Example #11
0
 def get_cust_care_name(self, obj):
     return StaffUtils.getName(obj.cust_care)
Example #12
0
 def get_sale_name(self, obj):
     return StaffUtils.getName(obj.sale)
Example #13
0
File: tests.py Project: tbson/24ho
 def setUp(self):
     self.staff = StaffUtils.seeding(1, True)
     self.order = OrderUtils.seeding(1, True)
     self.order.status = Status.NEW
     self.order.save()