本文整理汇总了Python中app.users.models.User.create方法的典型用法代码示例。如果您正苦于以下问题:Python User.create方法的具体用法?Python User.create怎么用?Python User.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_password_is_rejected
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
def test_invalid_password_is_rejected(self):
User.create(name="Joe", email="[email protected]", password="12345")
with self.client:
self.client.post("/login/", data={"name": "Joe", "password": "****"})
self.assertTrue(current_user.is_anonymous())
示例2: test_users_can_logout
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
def test_users_can_logout(self):
User.create(name="Joe", email="[email protected]", password="12345")
with self.client:
self.client.post("/login/", data={"name": "Joe", "password": "12345"})
self.client.get("/logout/")
self.assertTrue(current_user.is_anonymous())
示例3: test_users_can_login
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
def test_users_can_login(self):
User.create(name="Joe", email="[email protected]", password="12345")
with self.client:
response = self.client.post("/login/", data={"name": "Joe", "password": "12345"})
self.assert_redirects(response, url_for("index"))
self.assertTrue(current_user.name == "Joe")
self.assertFalse(current_user.is_anonymous())
示例4: post
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
def post(self):
resp = request.get_json()
avatar = resp.get('avatar')
email = resp.get('email')
username = resp.get('username')
first_name = resp.get('first_name') or ''
last_name = resp.get('last_name') or ''
password = resp.get('password')
gender = resp.get('gender') or ''
user = User.create(
avatar=avatar,
email=email,
first_name=first_name,
gender=gender,
last_name=last_name,
password=password,
username=username,
created=datetime.datetime.now(),
last_login=datetime.datetime.now(),
activated=False,
)
return Response(json.dumps(user.serialize), mimetype='application/json')
示例5: test_visitors_location_is_derived_from_ip
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
def test_visitors_location_is_derived_from_ip(self):
user = User.create(name="Joe", email="[email protected]", password="12345")
site = Site.create(user_id=user.id)
mock_geodata = Mock(name="get_geodata")
mock_geodata.return_value = {
'city': 'Los Angeles',
'zipcode': '90001',
'latitude': '34.05',
'longitude': '-118.25'
}
url = url_for("tracking.register_visit", site_id=site.id)
wsgi_environment = {"REMOTE_ADDR": "1.2.3.4"}
with patch.object(app.tracking.views, "get_geodata", mock_geodata):
with self.client:
self.client.get(url, environ_overrides=wsgi_environment)
visits = Visit.query.all()
mock_geodata.assert_called_once_with("1.2.3.4")
self.assertEquals(1, len(visits))
self.assertEquals("Los Angeles, 90001", visits[0].location)
self.assertEquals("Los Angeles, 90001, 34.05, -118.25",
visits[0].location_full)
示例6: signup
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
def signup():
if current_user.is_authenticated():
flash(gettext('You are already signed in.'))
return redirect(url_for('index'))
form = SignUpForm()
if form.validate_on_submit():
try:
## Create user from the form
user = User.create()
form.populate_obj(user)
user.set_password(form.password.data)
user.last_seen = datetime.datetime.utcnow()
user.last_login = datetime.datetime.utcnow()
## Store in database
user.save()
## Login User
login_user(user)
flash(gettext('Welcome! You have signed up successfully.'))
return redirect(url_for('index'))
except:
flash(gettext('Error while saving the new user, please retry later'), 'error')
return render_template('admin/signup.html',
title = gettext('Sign Up'),
form = form)
示例7: init_db
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
def init_db(cls):
user = User.create()
user.name = u'Juan Tabares'
user.nickname = u'jctt'
user.set_password(u'admin123456')
user.role = 1
user.email = u'[email protected]'
user.last_seen = datetime.datetime.utcnow()
user.save()
DbInit.init_categories()