本文整理汇总了Python中mkt.api.models.generate函数的典型用法代码示例。如果您正苦于以下问题:Python generate函数的具体用法?Python generate怎么用?Python generate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: api
def api(request):
try:
access = Access.objects.get(user=request.user)
except Access.DoesNotExist:
access = None
roles = request.amo_user.groups.all()
if roles:
messages.error(request, _('Users with roles cannot use the API.'))
elif not request.amo_user.read_dev_agreement:
messages.error(request, _('You must accept the terms of service.'))
elif request.method == 'POST':
if 'delete' in request.POST:
if access:
access.delete()
messages.success(request, _('API key deleted.'))
else:
if not access:
key = 'mkt:%s:%s' % (request.amo_user.pk,
request.amo_user.email)
access = Access.objects.create(key=key, user=request.user,
secret=generate())
else:
access.update(secret=generate())
messages.success(request, _('New API key generated.'))
return redirect(reverse('mkt.developers.apps.api'))
return jingo.render(request, 'developers/api.html',
{'consumer': access, 'profile': profile,
'roles': roles})
开发者ID:bearstech,项目名称:zamboni,代码行数:34,代码来源:views.py
示例2: test_bad_access_token
def test_bad_access_token(self):
url = absolutify(reverse('app-list'))
Token.generate_new(ACCESS_TOKEN, creds=self.access, user=self.user2)
url, auth_header = self._oauth_request_info(
url, client_key=self.access.key,
client_secret=self.access.secret, resource_owner_key=generate(),
resource_owner_secret=generate())
auth = authentication.RestOAuthAuthentication()
req = RequestFactory().get(
url, HTTP_HOST='testserver',
HTTP_AUTHORIZATION=auth_header)
assert not auth.is_authenticated(req)
开发者ID:aricha,项目名称:zamboni,代码行数:12,代码来源:test_oauth.py
示例3: test_bad_access_request
def test_bad_access_request(self):
t = Token.generate_new(REQUEST_TOKEN, self.access)
url = urlparse.urljoin(settings.SITE_URL,
reverse('mkt.developers.oauth_access_request'))
url, auth_header = self._oauth_request_info(
url, client_key=t.key, client_secret=t.secret,
resource_owner_key=generate(), resource_owner_secret=generate(),
verifier=generate(), callback_uri=self.access.redirect_uri)
res = self.client.get(url, HTTP_HOST='testserver',
HTTP_AUTHORIZATION=auth_header)
eq_(res.status_code, 401)
assert not Token.objects.filter(token_type=ACCESS_TOKEN).exists()
开发者ID:Dreadchild,项目名称:zamboni,代码行数:12,代码来源:test_oauth.py
示例4: test_bad_access_token
def test_bad_access_token(self):
url = absolutify(reverse('app-list'))
Token.generate_new(ACCESS_TOKEN, creds=self.access, user=self.user2)
url, auth_header = self._oauth_request_info(
url, client_key=self.access.key,
client_secret=self.access.secret, resource_owner_key=generate(),
resource_owner_secret=generate())
auth = authentication.RestOAuthAuthentication()
req = RequestFactory().get(
url, HTTP_HOST='testserver',
HTTP_AUTHORIZATION=auth_header)
req.API = True
req.user = AnonymousUser()
RestOAuthMiddleware().process_request(req)
ok_(not auth.authenticate(Request(req)))
ok_(not req.user.is_authenticated())
开发者ID:j-barron,项目名称:zamboni,代码行数:16,代码来源:test_oauth.py
示例5: login_user
def login_user(self):
self.profile.update(read_dev_agreement=datetime.now())
self.access = Access.objects.create(key='oauthClientKeyForTests',
secret=generate(),
user=self.user)
self.client = RestOAuthClient(self.access)
self.anon = RestOAuthClient(None)
开发者ID:j-barron,项目名称:zamboni,代码行数:7,代码来源:test_oauth.py
示例6: api
def api(request):
roles = request.amo_user.groups.filter(name="Admins").exists()
f = APIConsumerForm()
if roles:
messages.error(request, _("Users with the admin role cannot use the API."))
elif request.method == "POST":
if "delete" in request.POST:
try:
consumer = Access.objects.get(pk=request.POST.get("consumer"))
consumer.delete()
except Access.DoesNotExist:
messages.error(request, _("No such API key."))
else:
key = "mkt:%s:%s:%s" % (
request.amo_user.pk,
request.amo_user.email,
Access.objects.filter(user=request.user).count(),
)
access = Access.objects.create(key=key, user=request.user, secret=generate())
f = APIConsumerForm(request.POST, instance=access)
if f.is_valid():
f.save()
messages.success(request, _("New API key generated."))
else:
access.delete()
consumers = list(Access.objects.filter(user=request.user))
return jingo.render(
request, "developers/api.html", {"consumers": consumers, "profile": profile, "roles": roles, "form": f}
)
开发者ID:rskumar,项目名称:zamboni,代码行数:30,代码来源:views.py
示例7: setUp
def setUp(self):
self.api_name = 'foo'
self.auth = authentication.OAuthAuthentication()
self.profile = UserProfile.objects.get(pk=2519)
self.profile.update(read_dev_agreement=datetime.today())
self.access = Access.objects.create(key='foo', secret=generate(),
user=self.profile.user)
开发者ID:flyun,项目名称:zamboni,代码行数:7,代码来源:test_authentication.py
示例8: api
def api(request):
roles = request.amo_user.groups.filter(name='Admins').exists()
f = APIConsumerForm()
if roles:
messages.error(request,
_('Users with the admin role cannot use the API.'))
elif request.method == 'POST':
if 'delete' in request.POST:
try:
consumer = Access.objects.get(pk=request.POST.get('consumer'))
consumer.delete()
except Access.DoesNotExist:
messages.error(request, _('No such API key.'))
else:
key = 'mkt:%s:%s:%s' % (
request.amo_user.pk,
request.amo_user.email,
Access.objects.filter(user=request.user).count())
access = Access.objects.create(key=key,
user=request.user,
secret=generate())
f = APIConsumerForm(request.POST, instance=access)
if f.is_valid():
f.save()
messages.success(request, _('New API key generated.'))
else:
access.delete()
consumers = list(Access.objects.filter(user=request.user))
return jingo.render(request, 'developers/api.html',
{'consumers': consumers, 'roles': roles, 'form': f})
开发者ID:sylvesterwillis,项目名称:zamboni,代码行数:31,代码来源:views.py
示例9: test_owner_still_non_reviewer_access
def test_owner_still_non_reviewer_access(self):
user = Webapp.objects.get(pk=337141).authors.all()[0]
access = Access.objects.create(
key='test_oauth_key_owner', secret=generate(), user=user)
client = RestOAuthClient(access)
res = client.get(self.url)
eq_(res.status_code, 403)
开发者ID:Dreadchild,项目名称:zamboni,代码行数:7,代码来源:test_views_api.py
示例10: setUp
def setUp(self):
self.user = User.objects.get(pk=2519)
self.profile = self.user.get_profile()
self.profile.update(read_dev_agreement=datetime.now())
self.access = Access.objects.create(key="oauthClientKeyForTests", secret=generate(), user=self.user)
self.client = RestOAuthClient(self.access)
self.anon = RestOAuthClient(None)
开发者ID:rhelmer,项目名称:zamboni,代码行数:7,代码来源:test_oauth.py
示例11: setUp
def setUp(self, api_name="apps"):
self.user = User.objects.get(pk=2519)
self.profile = self.user.get_profile()
self.profile.update(read_dev_agreement=datetime.now())
self.access = Access.objects.create(key="foo", secret=generate(), user=self.user)
self.client = OAuthClient(self.access, api_name=api_name)
开发者ID:almet,项目名称:zamboni,代码行数:7,代码来源:test_oauth.py
示例12: setUp
def setUp(self, api_name='apps'):
self.profile = self.user = UserProfile.objects.get(pk=2519)
self.profile.update(read_dev_agreement=datetime.now())
self.access = Access.objects.create(key='oauthClientKeyForTests',
secret=generate(),
user=self.user)
self.client = OAuthClient(self.access, api_name=api_name)
self.anon = OAuthClient(None, api_name=api_name)
开发者ID:Dreadchild,项目名称:zamboni,代码行数:8,代码来源:test_oauth.py
示例13: setUp
def setUp(self):
self.api_name = "foo"
self.profile = UserProfile.objects.get(pk=2519)
self.profile.update(read_dev_agreement=datetime.today())
self.access = Access.objects.create(key="test_oauth_key", secret=generate(), user=self.profile.user)
self.auth = authentication.RestOAuthAuthentication()
self.middlewares = [RedirectPrefixedURIMiddleware, RestOAuthMiddleware]
unpin_this_thread()
开发者ID:robhudson,项目名称:zamboni,代码行数:8,代码来源:test_authentication.py
示例14: test_admin_get
def test_admin_get(self):
self.create_app()
admin = UserProfile.objects.get(email="[email protected]")
g = Group.objects.create(rules="*:*")
GroupUser.objects.create(group=g, user=admin)
ac = Access.objects.create(key="adminOauthKey", secret=generate(), user=admin.user)
client = RestOAuthClient(ac)
r = client.get(self.get_url)
eq_(r.status_code, 200)
开发者ID:hardikj,项目名称:zamboni,代码行数:9,代码来源:test_handlers.py
示例15: test_reviewer_get
def test_reviewer_get(self):
self.create_app()
editor = UserProfile.objects.get(email="[email protected]")
g = Group.objects.create(rules="Apps:Review,Reviews:Edit")
GroupUser.objects.create(group=g, user=editor)
ac = Access.objects.create(key="adminOauthKey", secret=generate(), user=editor.user)
client = RestOAuthClient(ac)
r = client.get(self.get_url)
eq_(r.status_code, 200)
开发者ID:hardikj,项目名称:zamboni,代码行数:9,代码来源:test_handlers.py
示例16: test_bad_token_request
def test_bad_token_request(self):
url = settings.SITE_URL + reverse("mkt.developers.oauth_token_request")
url, auth_header = self._oauth_request_info(
url, client_key=self.access.key, client_secret=generate(), callback_uri=self.access.redirect_uri
)
res = self.client.get(url, HTTP_HOST="testserver", HTTP_AUTHORIZATION=auth_header)
eq_(res.status_code, 401)
assert not Token.objects.filter(token_type=REQUEST_TOKEN).exists()
开发者ID:rhelmer,项目名称:zamboni,代码行数:9,代码来源:test_oauth.py
示例17: test_admin_get
def test_admin_get(self):
self.create_app()
admin = UserProfile.objects.get(email='[email protected]')
g = Group.objects.create(rules='*:*')
GroupUser.objects.create(group=g, user=admin)
ac = Access.objects.create(key='adminOauthKey', secret=generate(),
user=admin.user)
client = OAuthClient(ac, api_name='apps')
r = client.get(self.get_url)
eq_(r.status_code, 200)
开发者ID:at13,项目名称:zamboni,代码行数:10,代码来源:test_handlers.py
示例18: setUp
def setUp(self):
self.api_name = 'foo'
self.profile = UserProfile.objects.get(pk=2519)
self.profile.update(read_dev_agreement=datetime.today())
self.access = Access.objects.create(key='test_oauth_key',
secret=generate(),
user=self.profile)
self.auth = authentication.RestOAuthAuthentication()
self.middlewares = [APIBaseMiddleware, RestOAuthMiddleware]
unpin_this_thread()
开发者ID:JaredKerim-Mozilla,项目名称:zamboni,代码行数:10,代码来源:test_authentication.py
示例19: setUp
def setUp(self, api_name='apps'):
self.profile = self.user = UserProfile.objects.get(pk=2519)
self.profile.update(read_dev_agreement=datetime.now())
self.app_name = 'Mkt Test App'
self.redirect_uri = 'https://example.com/redirect_target'
self.access = Access.objects.create(key='oauthClientKeyForTests',
secret=generate(),
user=self.user,
redirect_uri=self.redirect_uri,
app_name=self.app_name)
开发者ID:j-barron,项目名称:zamboni,代码行数:10,代码来源:test_oauth.py
示例20: setUp
def setUp(self):
super(TestApiReviewer, self).setUp()
self.user = User.objects.get(pk=2519)
self.profile = self.user.get_profile()
self.profile.update(read_dev_agreement=datetime.now())
self.grant_permission(self.profile, "Apps:Review")
self.access = Access.objects.create(key="test_oauth_key", secret=generate(), user=self.user)
self.url = reverse("reviewers-search-api")
self.webapp = Webapp.objects.get(pk=337141)
self.category = Category.objects.create(name="test", type=amo.ADDON_WEBAPP)
self.webapp.update(status=amo.STATUS_PENDING)
self.refresh("webapp")
开发者ID:robhudson,项目名称:zamboni,代码行数:15,代码来源:test_api.py
注:本文中的mkt.api.models.generate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论