def post(self, request): try: form = forms.SignupForm(request.POST) if form.is_valid(): token = make_password(get_random_string(length=16)) password = make_password(form.cleaned_data['password']) r = utils.insert_user(form.cleaned_data['email'], password, token, 'U') if r == 201: return render( request, self.template_name, { 'form': forms.SignupForm(), 'success': '1', 'msg': 'Account created Successfully' }) else: return render( request, self.template_name, { 'form': forms.SignupForm(), 'error': '1', 'msg': 'Network error. Try later.' }) else: return render(request, self.template_name, { 'form': form, 'error': '1', 'form_err': '1' }) except Exception as e: return render( request, self.template_name, { 'form': forms.SignupForm(), 'error': '1', 'msg': 'Incorrect Submission' })
def register_user(): if not request.is_json: return make_response('Could not execute!', 401) request_body = request.get_json() res = insert_user(request_body['username'], request_body['password']) if not res: return make_response('Could not execute!', 401) return make_response('', 204)
def prepare(request): request.addfinalizer(finalize) mongo.db.drop_collection('users') insert_user('123', '123456789')
def test_that_you_cannot_insert_123_user_with_password_123(): assert insert_user('123', '123') is False
def test_that_you_cannot_insert_123_user_after_123_is_inserted(): assert insert_user('123', '123456789') is False
def test_that_query_user_is_123_after_inserting_123_user(): insert_user('123', '123456789') user = get_user('123') assert user['user'] == '123'
def test_that_query_user_is_not_none_after_inserting_a_given_user(): insert_user('123', '123456789') user = get_user('123') assert user != None