Ejemplo n.º 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']
Ejemplo n.º 2
0
 def setUp(self):
     merchant = Merchant(name='单元测试商户', services_key=construct_merchant())
     merchant.save()
     self.merchant_id = merchant.id
     self.mobile_auto_signup_url = reverse('users:user-mobile_auto_signup')
     self.mobile_auto_signup_data = {
         "mobile": "15051251379",
         "merchant": self.merchant_id,
     }
Ejemplo n.º 3
0
 def setUp(self):
     merchant = Merchant(name='单元测试商户', services_key=construct_merchant())
     merchant.save()
     self.merchant_id = merchant.id
     self.url = reverse('users:user-email_password_signup')
     self.user_data = {
         "email": "*****@*****.**",
         "password": "******",
         "merchant": self.merchant_id,
     }
Ejemplo n.º 4
0
 def setUp(self):
     merchant = Merchant(name='单元测试商户', services_key=construct_merchant())
     merchant.save()
     self.merchant_id = merchant.id
     self.weixin_auto_signup_url = reverse('users:user-weixin_auto_signup')
     self.weixin_auto_signup_data = {
         "weixin_openid": "o4e9G412PVz-PNjxd6QgI8649-eU",
         "weixin_userinfo":
         '{"avatarUrl": "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eqnDns6HaTRr1yHYjrqmDPNz6hUjBd4ZzrOBoolXSRxrarOvJ2n8KpehBoWbib0IKxK0X7tk9qNib2Q/132", "city": "Nantong", "country": "China", "gender": 1, "language": "zh_CN", "nickName": "fsociety", "province": "Jiangsu"}',
         "merchant": self.merchant_id,
     }
Ejemplo n.º 5
0
 def signup(self):
     merchant = Merchant(name='单元测试商户', services_key=construct_merchant())
     merchant.save()
     self.merchant_id = merchant.id
     self.user_list_url = reverse('users:user-email_password_signup')
     self.signup_data = {
         "email": "*****@*****.**",
         "password": "******",
         "merchant": self.merchant_id,
     }
     response = self.client.post(self.user_list_url,
                                 self.signup_data,
                                 format='json')
     eq_(response.status_code, 201)
Ejemplo n.º 6
0
def user_create_handler(sender, instance, created, **kwargs):
    """
    post create user 后创建一对一的 profile/invite/collection
    """
    if created:
        # 创建 profile
        profile = Profile(user=instance)
        profile.save()
        # 创建 invite
        invite = Invite(user=instance)
        invite.save()
        # 创建 collection
        collection = Collection(user=instance)
        collection.save()
        # 超级管理员才能 创建 merchant
        if instance.is_superuser:
            merchant = Merchant(name=instance.username + '_商户')
            merchant.save()
            instance.merchant = merchant
            instance.save()
Ejemplo n.º 7
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))
Ejemplo n.º 8
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']