本文整理汇总了Python中treemap.models.User.get_instance_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_instance_user方法的具体用法?Python User.get_instance_user怎么用?Python User.get_instance_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.User
的用法示例。
在下文中一共展示了User.get_instance_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UserRolesTest
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import get_instance_user [as 别名]
class UserRolesTest(OTMTestCase):
def setUp(self):
self.instance = make_instance()
self.commander = make_commander_user(self.instance, "comm")
# Note unicode '⅀' is on purpose
self.user1 = User(username='estraven', password='estraven',
email='[email protected]',
organization='org111',
first_name='therem', last_name='⅀straven')
self.user1.save_with_user(self.commander)
self.user2 = User(username='genly', password='genly',
email='[email protected]',
first_name='genly', last_name='ai')
self.user2.save_with_user(self.commander)
self.user3 = User(username='argaven_xv', password='argaven_xv',
email='[email protected]')
self.user3.save_with_user(self.commander)
self.user4 = User(username='faxe', password='faxe',
email='[email protected]')
self.user4.save_with_user(self.commander)
self.factory = RequestFactory()
def _add_user_to_instance_view(self, email):
body = {'email': email}
return create_user_role(
make_request(method='POST',
body=json.dumps(body),
user=self.commander),
self.instance)
def test_add_user_to_instance(self):
mail.outbox = []
self.assertIsNone(self.user4.get_instance_user(self.instance))
self._add_user_to_instance_view(self.user4.email)
self.assertIsNotNone(self.user4.get_instance_user(self.instance))
msg = mail.outbox[0]
# Just make sure we have some chars and the
# correct receiver
self.assertGreater(len(msg.subject), 10)
self.assertGreater(len(msg.body), 10)
self.assertEquals(tuple(msg.to), (self.user4.email,))
def test_email_not_found_creates_invite(self):
self.assertEqual(InstanceInvitation.objects.count(), 0)
mail.outbox = []
email = '[email protected]'
body = {'email': email}
create_user_role(
make_request(method='POST',
body=json.dumps(body),
user=self.commander),
self.instance)
self.assertEqual(InstanceInvitation.objects.count(), 1)
ii = InstanceInvitation.objects.all()[0]
# Should have email and default role
self.assertEqual(ii.email, email)
self.assertEqual(ii.instance, self.instance)
self.assertEqual(ii.role, self.instance.default_role)
# Should have sent an email to the user
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
# Just make sure we have some chars and the
# correct receiver
self.assertGreater(len(msg.subject), 10)
self.assertGreater(len(msg.body), 10)
self.assertEquals(tuple(msg.to), (email,))
def test_invalid_email(self):
body = {'email': '[email protected]'}
self.assertRaises(ValidationError,
create_user_role,
make_request(method='POST',
body=json.dumps(body),
user=self.commander),
self.instance)
def test_email_already_bound(self):
iuser = InstanceUser(user=self.user1, instance=self.instance,
role=self.instance.default_role)
#.........这里部分代码省略.........