本文整理汇总了Python中treemap.models.User.save_with_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.save_with_user方法的具体用法?Python User.save_with_user怎么用?Python User.save_with_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.User
的用法示例。
在下文中一共展示了User.save_with_user方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EcoTest
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save_with_user [as 别名]
class EcoTest(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.instance, system_user = tm.make_instance_and_system_user()
self.user = User(username="commander")
self.user.save_with_user(system_user)
self.user.roles.add(tm.make_commander_role(self.instance))
self.species = Species(symbol='CEDR',
genus='cedrus',
species='atlantica',
max_dbh=2000,
max_height=100)
self.species.save()
p1 = Point(-8515941.0, 4953519.0)
self.plot = Plot(geom=p1,
instance=self.instance,
created_by=self.user)
self.plot.save_with_user(self.user)
self.tree = Tree(plot=self.plot,
instance=self.instance,
readonly=False,
species=self.species,
diameter=1630,
created_by=self.user)
self.tree.save_with_user(self.user)
def test_group_eco(self):
pass # TODO: Once filtering has been enabled
def test_eco_benefit_sanity(self):
req = self.factory.get('/%s/eco/benefit/tree/%s/' %
(self.instance.pk, self.tree.pk))
response = tree_benefits(req,
instance_id=self.instance.pk,
tree_id=self.tree.pk,
region='NoEastXXX')
self.assertEqual(response.status_code, 200)
rslt = json.loads(response.content)
bens = rslt['benefits']
def assertBValue(benefit, unit, value):
self.assertEqual(bens[benefit]['unit'], unit)
self.assertEqual(int(float(bens[benefit]['value'])), value)
assertBValue('energy', 'kwh', 1896)
assertBValue('airquality', 'lbs/year', 6)
assertBValue('stormwater', 'gal', 3185)
assertBValue('co2', 'lbs/year', 563)
示例2: UserExportsTestCase
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save_with_user [as 别名]
class UserExportsTestCase(OTMTestCase):
def assertUserJSON(self, data, expectations):
for key, expectation in expectations.items():
value = data[key]
self.assertEqual(
expectation, value, "failure for key '%s': expected '%s', found '%s'" % (key, expectation, value)
)
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="karhide",
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",
allow_email_contact=True,
)
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)
role = make_commander_role(self.instance)
iuser1 = InstanceUser(instance=self.instance, user=self.user1, role=role)
iuser1.save_with_user(self.user1)
iuser2 = InstanceUser(instance=self.instance, user=self.user2, role=role)
iuser2.save_with_user(self.user2)
self.plot = Plot(geom=self.instance.center, readonly=False, instance=self.instance, width=4)
self.plot.save_with_user(self.user1)
self.tree = Tree(instance=self.instance, plot=self.plot, diameter=3)
self.tree.save_with_user(self.user2)
示例3: UserExportsTestCase
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save_with_user [as 别名]
class UserExportsTestCase(OTMTestCase):
def assertUserJSON(self, data, expectations):
for key, value in expectations.items():
self.assertEqual(data[key], value)
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='karhide',
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',
allow_email_contact=True)
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)
role = make_commander_role(self.instance)
iuser1 = InstanceUser(instance=self.instance, user=self.user1,
role=role)
iuser1.save_with_user(self.user1)
iuser2 = InstanceUser(instance=self.instance, user=self.user2,
role=role)
iuser2.save_with_user(self.user2)
pt = Point(0, 0)
self.plot = Plot(geom=pt, readonly=False, instance=self.instance,
width=4)
self.plot.save_with_user(self.user1)
self.tree = Tree(instance=self.instance, plot=self.plot, diameter=3)
self.tree.save_with_user(self.user2)
示例4: UserExportsTestCase
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save_with_user [as 别名]
class UserExportsTestCase(TestCase):
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',
firstname='therem', lastname='⅀straven')
self.user1.save_with_user(self.commander)
self.user2 = User(username='genly', password='genly',
email='[email protected]',
firstname='genly', lastname='ai',
allow_email_contact=True)
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)
role = make_commander_role(self.instance)
iuser1 = InstanceUser(instance=self.instance, user=self.user1,
role=role)
iuser1.save_with_user(self.user1)
iuser2 = InstanceUser(instance=self.instance, user=self.user2,
role=role)
iuser2.save_with_user(self.user2)
pt = Point(0, 0)
self.plot = Plot(geom=pt, readonly=False, instance=self.instance,
width=4)
self.plot.save_with_user(self.user1)
self.tree = Tree(instance=self.instance, plot=self.plot, diameter=3)
self.tree.save_with_user(self.user2)
示例5: UserRolesTest
# 需要导入模块: from treemap.models import User [as 别名]
# 或者: from treemap.models.User import save_with_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)
#.........这里部分代码省略.........