def get_single_category_put(self): login_username = '******' user_login = User(user_id=MOCK_USER_ID_LIST[0], username=login_username) category = Category(category_id=MOCK_CATEGORY_UUID_LIST[0], category_name='実写', user_id=user_login, sort_order=1) put_body = { 'category_name': '実写画像', 'category_id': MOCK_CATEGORY_UUID_LIST[0] } expected: FailureAPIResponse = { 'body': { 'category': { 'category_id': MOCK_CATEGORY_UUID_LIST[0], 'category_name': '実写画像', 'user_id': UUID(MOCK_USER_ID_LIST[0]), 'sort_order': 1 }, 'message': 'ok' } } return get_param(expected, login_username, model_items_list=[[user_login], [category]], put_body=put_body)
def get_empty_category_name_put(self): login_username = '******' user_login = User(user_id=MOCK_USER_ID_LIST[0], username=login_username) category = Category(category_id=MOCK_CATEGORY_UUID_LIST[0], category_name='実写', user_id=user_login) put_body = { 'category_name': '', 'category_id': MOCK_CATEGORY_UUID_LIST[0] } expected: FailureAPIResponse = { 'body': { 'message': '登録に失敗しました。', }, 'errors': [{ 'fieldName': 'category_name', 'message': 'カテゴリ名を入力してください。' }], } return get_param(expected, login_username, model_items_list=[[user_login], [category]], put_body=put_body)
def get_specified_user_request(self) -> ParamType: expected = User(user_id=USER_ID) request = Request(HttpRequest()) request.user = expected return self._get_param(request, expected)
def get_users(self): users = [ {'username': '******'}, {'username': '******'}, {'username': '******'}, ] model_users: List[Model] = [ User(user_id=MOCK_USER_ID_LIST[0], username=users[0]['username']), User(user_id=MOCK_USER_ID_LIST[1], username=users[1]['username']), User(user_id=MOCK_USER_ID_LIST[2], username=users[2]['username']), ] expected: SuccessAPIResponse = { 'body': { 'users': users, 'message': OK_MESSAGE } } return self._get_param(expected, model_items_list=[model_users])
def get_success_login(self): users = [ {'username': '******'}, ] model_users: List[Model] = [ User(user_id=MOCK_USER_ID_LIST[0], username=users[0]['username']), ] post_body = users[0] expected: SuccessAPIResponse = { 'body': { 'message': OK_MESSAGE } } return self._get_param(expected, model_items_list=[model_users], post_body=post_body)
def get_render_with_updated_model(self) -> SuccessUpdateParamType: model_name = 'user' model_object = User(username='******') serializer = SignupSerializer(instance=model_object) expected_response: SuccessAPIResponse = { 'body': { 'message': OK_MESSAGE, 'user': { 'username': '******' } } } expected = Response(data=expected_response, status=HTTP_200_OK) return self._get_params(expected, model_name, serializer)
def register(request): if request.session.get('is_login'): #如果是登陆状态就跳转至主页 return redirect('/index/') if request.method=='POST': #提交post类型的表单数据 register_form=forms.RegisterForm(request.POST) #把注册的form表单存储到register_form变量中 message='请检查填写的内容!' #这个是用于提示输入有误的反馈变量 if register_form.is_valid(): #如果注册的内容合法,就继续下面的内容 #获取web页面输入框输入的信息 username=register_form.cleaned_data['username'] password1=register_form.cleaned_data['password1'] password2=register_form.cleaned_data['password2'] email=register_form.cleaned_data['email'] print(email) sex=register_form.cleaned_data['sex'] #判断输入的两次密码是否一致 if password1!=password2: #如果两次输入的密码不一致 message='两次密码输入不一致' #提示输入不一致 return render(request,'login/register.html',{'message':message,'register_form':register_form}) else: user=User.objects.filter(name=username) if user: message='用户名已存在,请重新输入' return render(request,'login/register.html',{'message':message,'register_form':register_form}) get_email=User.objects.filter(email=email) if get_email: message='邮箱已被注册,请更换邮箱注册!' return render(request,'login/register.html',{'message':message,'register_form':register_form}) #没问题就进行注册 new_user=User() new_user.name=username new_user.password=password1 print(email) new_user.email=email print(new_user.email) new_user.sex=sex new_user.save() #保存到表中 return redirect('/login/') #注册完成后跳转到登陆页面 register_form=forms.RegisterForm() #保留输入的错误字段 return render(request,'login/register.html',{'register_form':register_form}) #这里用于传递输入过的错误信息到界面
def get_duplicate_category_post(self): login_username = '******' user_login = User(user_id=MOCK_USER_ID_LIST[0], username=login_username) post_body = {'category_name': '実写'} expected: FailureAPIResponse = { 'body': { 'message': '登録に失敗しました。', }, 'errors': [{ 'fieldName': 'category_name', 'message': 'カテゴリ名は既に使用されています。' }], } return get_param(expected, login_username, model_items_list=[[user_login]], post_body=post_body)
def get_user_duplicate(self) -> ParamViewRequestType: username = '******' post_body = {'username': username} duplicate_user = User(username=username) expected: FailureAPIResponse = { 'body': { 'message': messages['common']['error']['update_failure'] }, 'errors': [{ 'fieldName': 'username', 'message': 'ユーザ名はすでに使用されています。', }] } return self._get_param(expected, model_items_list=[[duplicate_user]], post_body=post_body)
def get_single_category(self): login_username = '******' user_login = User(user_id=MOCK_USER_ID_LIST[0], username=login_username) post_body = {'category_name': '実写'} expected: SuccessAPIResponse = { 'body': { 'category': { 'category_id': '', 'category_name': '実写', 'user_id': UUID(MOCK_USER_ID_LIST[0]), 'sort_order': 1 }, 'message': 'ok' } } return get_param(expected, login_username, model_items_list=[[user_login]], post_body=post_body)
def get_specified_user_request(self) -> ParamType: user = User(pk=1, username='******') view = MockView(user) return self._get_param(view, self._get_request(user))