예제 #1
0
    def signup(self):
        merchant = Merchant(name='单元测试商户')
        merchant.save()
        self.merchant_id = merchant.id
        # 注册 superuser 获取 token
        self.user_data = model_to_dict(UserFactory.build())
        user = User.objects.create_user(
            username=self.user_data.get('username'),
            mobile=self.user_data.get('mobile'),
            password=self.user_data.get('password'),
            is_superuser=True)
        user.save()
        self.user = User.objects.get(pk=user.id)
        token_auth_url = reverse('users:user-username_password_signin')
        data = {
            'username': self.user.username,
            'password': self.user_data.get('password')
        }
        response = self.client.post(token_auth_url, data, format='json')
        self.token = response.data['token']
        self.client.credentials(HTTP_AUTHORIZATION='JWT {}'.format(self.token))

        # 创建 category
        category_response = create_category(self.client, self.merchant_id)
        self.category_id = category_response.json()['id']

        # 创建 product
        product_response = create_product(self.client, self.category_id,
                                          self.merchant_id)
        self.product_uuid = product_response.json()['id']
예제 #2
0
 def signupanotheruser(self):
     # 注册另一个用户用来作为 to_user
     self.to_user_data = model_to_dict(UserFactory.build())
     to_user = User.objects.create_user(
         username=self.to_user_data.get('username'),
         mobile=self.to_user_data.get('mobile'),
         password=self.to_user_data.get('password'))
     to_user.save()
     self.to_user = User.objects.get(pk=to_user.id)
예제 #3
0
 def signup(self):
     # 注册 superuser 获取 token
     self.user_data = model_to_dict(UserFactory.build())
     user = User.objects.create_user(
         username=self.user_data.get('username'),
         mobile=self.user_data.get('mobile'),
         password=self.user_data.get('password'),
         is_superuser=True)
     user.save()
     self.user = User.objects.get(pk=user.id)
     token_auth_url = reverse('users:user-username_password_signin')
     data = {
         'username': self.user.username,
         'password': self.user_data.get('password')
     }
     response = self.client.post(token_auth_url, data, format='json')
     self.token = response.data['token']
     self.client.credentials(HTTP_AUTHORIZATION='JWT {}'.format(self.token))
예제 #4
0
 def signup(self):
     # 注册普通用户获得 token
     merchant = Merchant(name='单元测试商户', services_key=construct_merchant())
     merchant.save()
     self.merchant_id = merchant.id
     self.user_data = model_to_dict(UserFactory.build())
     user = User.objects.create_user(
         username=self.user_data.get('username'),
         mobile=self.user_data.get('mobile'),
         password=self.user_data.get('password'))
     user.merchant = merchant
     user.save()
     self.user = User.objects.get(pk=user.id)
     token_auth_url = reverse('users:user-username_password_signin')
     data = {
         'username': self.user.username,
         'password': self.user_data.get('password')
     }
     response = self.client.post(token_auth_url, data, format='json')
     self.token = response.data['token']
     self.client.credentials(HTTP_AUTHORIZATION='JWT {}'.format(self.token))
예제 #5
0
    def signup(self):
        # 注册 superuser 获取 token
        merchant = Merchant(name='单元测试商户')
        merchant.save()
        self.merchant_id = merchant.id
        self.user_data = model_to_dict(UserFactory.build())
        user = User.objects.create_user(
            username=self.user_data.get('username'),
            mobile=self.user_data.get('mobile'),
            password=self.user_data.get('password'),
            is_superuser=True,
            merchant=merchant)
        user.merchant = merchant
        user.save()
        self.user = User.objects.get(pk=user.id)
        token_auth_url = reverse('users:user-username_password_signin')
        data = {
            'username': self.user.username,
            'password': self.user_data.get('password')
        }
        response = self.client.post(token_auth_url, data, format='json')
        self.token = response.data['token']
        self.client.credentials(HTTP_AUTHORIZATION='JWT {}'.format(self.token))

        # 创建 category
        category_response = create_category(self.client, self.merchant_id)
        self.category_id = category_response.json()['id']

        # 创建 product
        product_response = create_product(self.client, self.category_id,
                                          self.merchant_id)
        self.product_uuid = product_response.json()['id']

        # 创建 product_spec
        product_spec_response = create_product_spec(self.client,
                                                    self.category_id,
                                                    self.product_uuid)
        self.product_spec_id = product_spec_response.json()['id']

        promotion_product_url = reverse('promotions:productpromotion-list')

        # 创建砍价商品 promotion_product
        self.bargain_promotion_product_data = {
            "product_spec": self.product_spec_id,
            "bargain_start_price": 100.00,
            "bargain_end_price": 10.00,
            "bargain_percent_range": '20-30',
            "promotion_type": '1',
            "promotion_stock": 10
        }

        bargain_promotion_product_response = self.client.post(
            promotion_product_url,
            self.bargain_promotion_product_data,
            format='json')
        self.bargain_promotion_product_id = bargain_promotion_product_response.json(
        )['id']

        # 创建团购商品 promotion_product
        self.groupon_promotion_product_data = {
            "product_spec": self.product_spec_id,
            "groupon_limit": 2,
            "promotion_type": '2',
            "promotion_stock": 10
        }

        groupon_promotion_product_response = self.client.post(
            promotion_product_url,
            self.groupon_promotion_product_data,
            format='json')
        self.groupon_promotion_product_id = groupon_promotion_product_response.json(
        )['id']
예제 #6
0
 def setUp(self):
     self.user_data = model_to_dict(UserFactory.build())