本文整理汇总了Python中core.models.User.username方法的典型用法代码示例。如果您正苦于以下问题:Python User.username方法的具体用法?Python User.username怎么用?Python User.username使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.User
的用法示例。
在下文中一共展示了User.username方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import username [as 别名]
def authenticate(self, saml_authentication=None):
if not saml_authentication: # Using another authentication method
return None
if saml_authentication.is_authenticated():
attributes = saml_authentication.get_attributes()
user_changed = False
try:
user = User.objects.get(username=saml_authentication.get_attributes()['uid'][0])
except User.DoesNotExist:
user = User(username=saml_authentication.get_attributes()['uid'][0])
user.set_unusable_password()
user.username = attributes['uid'][0]
map_fields = {
'realname': 'cn',
'email': 'mail'
}
# ensure realname for users from webid don't contain unverified note
if 'cn' in attributes:
attributes['cn'][0] = attributes['cn'][0].replace(' (unverified)', '')
for field, samlfield in map_fields.items():
if getattr(user, field) != attributes[samlfield][0]:
setattr(user, field, attributes[samlfield][0])
user_changed = True
if user_changed:
user.save()
return user
return None
示例2: test_call_register_channel
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import username [as 别名]
def test_call_register_channel(self):
'''
Test registration to a channel
'''
u = User()
u.username = "sample_post"
u.first_name = "sample_post"
u.email = "[email protected]"
u.set_password("123")
u.save()
ch1 = Channel()
ch1.owner = u
ch1.name = "PostSub"
ch1.image = 'http://www.google.com'
ch1.description = "A channel description"
ch1.kind = PUBLIC
ch1.hidden = False
ch1.subscriptions = 0
ch1.save()
sub1 = Subscriber()
sub1.sub_type = 'type2'
sub1.token = 'token2'
sub1.device_id = 'devid5'
sub1.save()
resp = ask_subscribe_channel(ch1, sub1.device_id)
self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
self.client.login(username='test_user', password='password')
data = {
'channel' : ch1.name,
'token' : sub1.token,
'browser' : 'chrome',
'device_id' : sub1.device_id
}
response = self.client.post(reverse('browser-registration'), json.dumps(data), sub1.token)
self.assertTrue(response.status_code, 200)
示例3: test_call_delete
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import username [as 别名]
def test_call_delete(self):
'''
Test deleting of a registration of a device from a channel
'''
u = User()
u.username = "sample_del"
u.first_name = "sample_del"
u.email = "[email protected]"
u.set_password("123")
u.save()
ch1 = Channel()
ch1.owner = u
ch1.name = "DelSub"
ch1.image = 'http://www.google.com'
ch1.description = "A channel description"
ch1.kind = PUBLIC
ch1.hidden = False
ch1.subscriptions = 0
ch1.save()
sub1 = Subscriber()
sub1.sub_type = 'type2'
sub1.token = 'token2'
sub1.device_id = 'devid6'
sub1.save()
resp = ask_subscribe_channel(ch1, sub1.device_id)
self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
self.client.login(username='test_user', password='password')
response = self.client.delete(reverse('browser-get-registration', kwargs={'device_id': sub1.device_id,
'channel_name' : ch1.name}))
self.assertEqual(response.status_code, 200)
channels = SubscriberManager().get_device_subscriptions(sub1.device_id)
sub_channel = next((x for x in channels if x == ch1.name.lower()), None)
self.assertIsNone(sub_channel)
示例4: test_call_get
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import username [as 别名]
def test_call_get(self):
'''
Test check if a device is registered to a channel
'''
u = User()
u.username = "sample_un"
u.first_name = "Sample_un"
u.email = "[email protected]"
u.set_password("123")
u.save()
ch1 = Channel()
ch1.owner = u
ch1.name = "GetSub"
ch1.image = 'http://www.google.com'
ch1.description = "A channel description"
ch1.kind = PUBLIC
ch1.hidden = False
ch1.subscriptions = 0
ch1.save()
sub1 = Subscriber()
sub1.sub_type = 'type2'
sub1.token = 'token2'
sub1.device_id = 'devid4'
sub1.save()
resp = ask_subscribe_channel(ch1, 'devid4')
self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
self.client.login(username='test_user', password='password')
response = self.client.get(reverse('browser-get-registration', kwargs={'device_id': 'devid4', 'channel_name' : 'GetSub'}) )
self.assertTrue(response.status_code, 200)