本文整理汇总了Python中account.models.UserProfile.new方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.new方法的具体用法?Python UserProfile.new怎么用?Python UserProfile.new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类account.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.new方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bar_payment_user_uses_only_accepted_tabs
# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import new [as 别名]
def test_bar_payment_user_uses_only_accepted_tabs(
self, mock_bar_models_charge_source, mock_bar_models_authorize_source
):
"""
Ensure that a payment only use tabs that have been accepted
For this test you need:
- A bar
- A user
- Another user
- A tab created by each user
"""
self.user.customer.default_source = "123"
self.user.customer.save()
mock_bar_models_authorize_source.return_value = {"id": "jnsdflkgj34r"}
mock_bar_models_charge_source.return_value = {"id": "jnsdflkgj34r"}
# Create another user
user = UserProfile.new("[email protected]", "password", "Ryan", "Frahm", datetime.datetime.now())
user.groups.add(Group.objects.filter(name="Drinkers")[0])
# Create a 2 tabs
# This one should not be accepted
tab2 = Tab.new(20.00, self.user.email, "ijbwflgkbsdf", user)
# This one should be automatically accepted
tab1 = Tab.new(20.00, self.user.email, "ijbwflgkbsdf", self.user)
url = reverse("api:bar-pay", args=(1,))
amount = 10
d = {"amount": amount}
response = self.client.post(url, d, format="json")
self.assertEqual(len(response.data.get("transactions")), 1)
self.assertIsNotNone(response.data.get("sale"))
# The user's tab should now be $10
self.assertEqual(response.data.get("tab"), 10)
transactions = response.data.get("transactions")
self.assertEqual(transactions[0]["status"], "authorized")
self.assertEqual(transactions[0]["amount"], 10.00)
self.assertEqual(transactions[0]["tab_id"], tab1.pk)
示例2: setUp
# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import new [as 别名]
def setUp(self, mock_bar_models_authorize_source, mock_bar_models_charge_source, mock_account_models_stripe):
# mock_account_models_customer.default_source = '123'
mock_account_models_stripe.Customer.create.return_value = {"id": "13542lknlknlkn"}
mock_bar_models_authorize_source.return_value = {"id": "jnsdflkgj34r"}
# Create groups
group = Group(name="Bar Owners")
group.save()
g = Group(name="Drinkers")
g.save()
# Create a user
email = "[email protected]"
password = "password"
self.firstname = "Bob"
self.lastname = "Dyllan"
self.dob = datetime.datetime.now()
self.user = UserProfile.new(email, password, self.firstname, self.lastname, self.dob)
self.user.groups.add(group)
self.client = APIClient(enforce_csrf_checks=True)
self.client.force_authenticate(user=self.user)
d = {
"street": "123 Street",
"city": "Des Moines",
"province": "IA",
"postal": "50305",
"country": "US",
"lat": 41.0,
"lng": -91.0,
}
bar = Bar.new("Test Bar 1", d, self.user)
bar.save()
self.bar = bar
m = StripeMerchant(user=self.user, account_id="123", pub_key="123", refresh_token="123", access_token="123")
m.save()
示例3: test_role_create
# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import new [as 别名]
def test_role_create(self):
"""
Ensure that we can create a role
"""
url = reverse("api:bar-roles", args=(1,))
# Create another user
user = UserProfile.new("[email protected]", "password", "Ryan", "Frahm", datetime.datetime.now())
user.groups.add(Group.objects.filter(name="Drinkers")[0])
role = "admin,bartender,manager"
d = {"uid": user.pk, "role": role}
response = self.client.post(url, d, format="json")
self.assertEqual(response.data.get("role"), role)
self.assertTrue(Role.objects.filter().exists())
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
示例4: test_tab_create_for_another_user
# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import new [as 别名]
def test_tab_create_for_another_user(self, mock_bar_models_authorize_source):
"""
Ensure we can create a tab for another registered user
"""
# Create another user
user = UserProfile.new("[email protected]", "password", "Ryan", "Frahm", datetime.datetime.now())
user.groups.add(Group.objects.filter(name="Drinkers")[0])
url = reverse("api:tabs")
d = {"amount": 20, "source": "123", "users": [{"id": user.pk}], "note": "Testy test notes!"}
mock_bar_models_authorize_source.return_value = {"id": "jnsdflkgj34r"}
response = self.client.post(url, d, format="json")
tabs = response.data.get("tabs")
self.assertEqual(len(tabs), 1)
self.assertEqual(tabs[0]["receiver"], user.pk)
self.assertEqual(response.data.get("amount"), d["amount"])
示例5: test_user_get_tab_list
# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import new [as 别名]
def test_user_get_tab_list(self):
"""
Ensure we only return active tabs
"""
# Create another user
user = UserProfile.new("[email protected]", "password", "Ryan", "Frahm", datetime.datetime.now())
user.groups.add(Group.objects.filter(name="Drinkers")[0])
tab = Tab(amount=20, total=20, sender=user, receiver=self.user, source="23423542", charge="13425", active=False)
tab.save()
tab = Tab(amount=20, total=20, sender=user, receiver=self.user, source="23423542", charge="13425")
tab.save()
url = reverse("api:tabs")
response = self.client.get(url, format="json")
tabs = response.data
self.assertEqual(len(tabs), 1)
示例6: test_role_create_when_not_owner_or_admin
# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import new [as 别名]
def test_role_create_when_not_owner_or_admin(self):
"""
Ensure that only owners/admins can create roles.
It should return a status 400
"""
url = reverse("api:bar-roles", args=(1,))
# Create another user
user = UserProfile.new("[email protected]", "password", "Ryan", "Frahm", datetime.datetime.now())
user.groups.add(Group.objects.filter(name="Drinkers")[0])
# Switch owners really quick on this bar
bar = Bar.objects.get(pk=1)
bar.owner = user
bar.save()
role = "admin,bartender,manager"
d = {"uid": user.pk, "role": role}
response = self.client.post(url, d, format="json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
示例7: create_user
# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import new [as 别名]
def create_user():
return UserProfile.new(email, password, 'Bill', 'Black', '2015-10-26')