本文整理汇总了Python中tests.create_tokens函数的典型用法代码示例。如果您正苦于以下问题:Python create_tokens函数的具体用法?Python create_tokens怎么用?Python create_tokens使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_tokens函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
""" Set up the environnment, ran before every tests. """
super(PagureFlaskApiProjectUpdateWatchTests, self).setUp()
tests.create_projects(self.session)
tests.create_projects_git(os.path.join(self.path, "tickets"))
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
# Create normal issue
repo = pagure.lib.query.get_authorized_project(self.session, "test")
msg = pagure.lib.query.new_issue(
session=self.session,
repo=repo,
title="Test issue #1",
content="We should work on this",
user="pingou",
private=False,
)
self.session.commit()
self.assertEqual(msg.title, "Test issue #1")
# Create project-less token for user foo
item = pagure.lib.model.Token(
id="project-less-foo",
user_id=1,
project_id=None,
expiration=datetime.datetime.utcnow()
+ datetime.timedelta(days=30),
)
self.session.add(item)
self.session.commit()
tests.create_tokens_acl(self.session, token_id="project-less-foo")
示例2: setUp
def setUp(self):
""" Set up the environnment, ran before every tests. """
super(PagureFlaskApiIssueCreatetests, self).setUp()
pagure.config.config["TICKETS_FOLDER"] = None
tests.create_projects(self.session)
tests.create_projects_git(os.path.join(self.path, "tickets"))
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
# Create project-less token for user foo
item = pagure.lib.model.Token(
id="project-less-foo",
user_id=2,
project_id=None,
expiration=datetime.datetime.utcnow()
+ datetime.timedelta(days=30),
)
self.session.add(item)
self.session.commit()
tests.create_tokens_acl(self.session, token_id="project-less-foo")
# Create project-specific token for user foo
item = pagure.lib.model.Token(
id="project-specific-foo",
user_id=2,
project_id=1,
expiration=datetime.datetime.utcnow()
+ datetime.timedelta(days=30),
)
self.session.add(item)
self.session.commit()
tests.create_tokens_acl(self.session, token_id="project-specific-foo")
示例3: setUp
def setUp(self):
super(PagureFlaskAppClonetests, self).setUp()
tests.create_projects(self.session)
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
self.create_project_full("clonetest", {"create_readme": "y"})
示例4: test_auth_noacl
def test_auth_noacl(self):
""" Test the authentication when the token does not have any ACL.
"""
tests.create_projects(self.session)
tests.create_tokens(self.session)
output = self.app.post("/api/0/test/new_issue")
self.assertEqual(output.status_code, 401)
data = json.loads(output.data)
self.assertDictEqual(
data,
{
"error": "Invalid or expired token. Please visit "
"https://pagure.org/ to get or renew your API token.",
"error_code": "EINVALIDTOK",
},
)
headers = {"Authorization": "token aaabbbcccddd"}
output = self.app.post("/api/0/test/new_issue", headers=headers)
self.assertEqual(output.status_code, 401)
data = json.loads(output.data)
self.assertDictEqual(
data,
{
"error": "Invalid or expired token. Please visit "
"https://pagure.org/ to get or renew your API token.",
"error_code": "EINVALIDTOK",
},
)
示例5: setUp
def setUp(self):
super(PagureLibGitAuthtests, self).setUp()
tests.create_projects(self.session)
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
self.create_project_full("hooktest")
示例6: test_auth_expired
def test_auth_expired(self):
""" Test the authentication when the token has expired.
"""
tests.create_projects(self.session)
tests.create_tokens(self.session)
output = self.app.post('/api/0/test/new_issue')
self.assertEqual(output.status_code, 401)
data = json.loads(output.data)
self.assertDictEqual(
data,
{
"error": "Invalid or expired token. Please visit " \
"https://pagure.org/ to get or renew your API token.",
"error_code": "EINVALIDTOK",
}
)
headers = {'Authorization': 'token expired_token'}
output = self.app.post('/api/0/test/new_issue', headers=headers)
self.assertEqual(output.status_code, 401)
data = json.loads(output.data)
self.assertDictEqual(
data,
{
"error": "Invalid or expired token. Please visit " \
"https://pagure.org/ to get or renew your API token.",
"error_code": "EINVALIDTOK",
}
)
示例7: test_auth
def test_auth(self):
""" Test the token based authentication.
"""
tests.create_projects(self.session)
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
output = self.app.post('/api/0/test/new_issue')
self.assertEqual(output.status_code, 401)
data = json.loads(output.data)
self.assertDictEqual(
data,
{
"error": "Invalid or expired token. Please visit " \
"https://pagure.org/ to get or renew your API token.",
"error_code": "EINVALIDTOK",
}
)
headers = {'Authorization': 'token aaabbbcccddd'}
output = self.app.post('/api/0/test/new_issue', headers=headers)
self.assertEqual(output.status_code, 400)
data = json.loads(output.data)
self.assertDictEqual(
data,
{
"error": "Invalid or incomplete input submited",
"error_code": "EINVALIDREQ",
}
)
示例8: test_http_push
def test_http_push(self):
""" Test that the HTTP push endpoint works for repoSpanner. """
tests.create_projects(self.session)
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
self.create_project_full("clonetest", {"create_readme": "y"})
# Verify the new project is indeed on repoSpanner
project = pagure.lib.query._get_project(self.session, "clonetest")
self.assertTrue(project.is_on_repospanner)
# Unfortunately, actually testing a git clone would need the app to
# run on a TCP port, which the test environment doesn't do.
output = self.app.get(
"/clonetest.git/info/refs?service=git-receive-pack",
environ_overrides={"REMOTE_USER": "pingou"},
)
self.assertEqual(output.status_code, 200)
self.assertEqual(
output.content_type, "application/x-git-receive-pack-advertisement"
)
output_text = output.get_data(as_text=True)
self.assertIn("# service=git-receive-pack", output_text)
self.assertIn("agent=repoSpanner", output_text)
self.assertIn("symref=HEAD:refs/heads/master", output_text)
self.assertIn(" refs/heads/master\x00", output_text)
示例9: setUp
def setUp(self):
super(PagureLibGitAuthPagureGitAuthtests, self).setUp()
tests.create_projects(self.session)
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
self.create_project_full("acltest")
project = pagure.lib.query._get_project(self.session, "acltest")
# Create non-push deploy key
non_push_dkey = pagure.lib.model.SSHKey(
project_id=project.id,
pushaccess=False,
public_ssh_key="\n foo bar",
ssh_short_key="\n foo bar",
ssh_search_key="\n foo bar",
creator_user_id=1, # pingou
)
self.session.add(non_push_dkey)
# Create push deploy key
push_dkey = pagure.lib.model.SSHKey(
project_id=project.id,
pushaccess=True,
public_ssh_key="\n bar foo",
ssh_short_key="\n bar foo",
ssh_search_key="\n bar foo",
creator_user_id=1, # pingou
)
self.session.add(push_dkey)
self.session.commit()
示例10: setUp
def setUp(self):
""" Set up the environnment, ran before every tests. """
super(PagureFlaskApiProjectBlockuserTests, self).setUp()
tests.create_projects(self.session)
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
item = pagure.lib.model.Token(
id="aaabbbcccdddeee",
user_id=2,
project_id=1,
expiration=datetime.datetime.utcnow()
+ datetime.timedelta(days=30),
)
self.session.add(item)
self.session.commit()
tests.create_tokens_acl(self.session, token_id="aaabbbcccdddeee")
project = pagure.lib.query.get_authorized_project(self.session, "test")
self.assertEqual(project.block_users, [])
self.blocked_users = []
project = pagure.lib.query.get_authorized_project(
self.session, "test2"
)
project.block_users = ["foo"]
self.session.add(project)
self.session.commit()
示例11: test_api_view_group_authenticated
def test_api_view_group_authenticated(self):
"""
Test the api_view_group method of the flask api with an
authenticated user. The tested group has one member.
"""
tests.create_tokens(self.session)
headers = {"Authorization": "token aaabbbcccddd"}
output = self.app.get("/api/0/group/some_group", headers=headers)
self.assertEqual(output.status_code, 200)
exp = {
"display_name": "Some Group",
"description": None,
"creator": {
"fullname": "PY C",
"default_email": "[email protected]",
"emails": ["[email protected]", "[email protected]"],
"name": "pingou",
},
"members": ["pingou"],
"date_created": "1492020239",
"group_type": "user",
"name": "some_group",
}
data = json.loads(output.get_data(as_text=True))
data["date_created"] = "1492020239"
self.assertDictEqual(data, exp)
示例12: setUp
def setUp(self):
""" Set up the environnment, ran before every tests. """
super(PagureFlaskApiGetPRFlagtests, self).setUp()
pagure.config.config["REQUESTS_FOLDER"] = None
tests.create_projects(self.session)
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
# Create a pull-request
repo = pagure.lib.query.get_authorized_project(self.session, "test")
forked_repo = pagure.lib.query.get_authorized_project(
self.session, "test"
)
req = pagure.lib.query.new_pull_request(
session=self.session,
repo_from=forked_repo,
branch_from="master",
repo_to=repo,
branch_to="master",
title="test pull-request",
user="pingou",
)
self.session.commit()
self.assertEqual(req.id, 1)
self.assertEqual(req.title, "test pull-request")
# Check flags before
self.session.commit()
request = pagure.lib.query.search_pull_requests(
self.session, project_id=1, requestid=1
)
self.assertEqual(len(request.flags), 0)
示例13: setUp
def setUp(self):
""" Set up the environnment, ran before every tests. """
super(PagureFlaskApiForkUpdatetests, self).setUp()
tests.create_projects(self.session)
tests.add_content_git_repo(
os.path.join(self.path, "repos", "test.git")
)
# Fork
project = pagure.lib.query.get_authorized_project(self.session, "test")
task = pagure.lib.query.fork_project(
session=self.session, user="pingou", repo=project
)
self.session.commit()
self.assertEqual(
task.get(),
{
"endpoint": "ui_ns.view_repo",
"repo": "test",
"namespace": None,
"username": "pingou",
},
)
tests.add_readme_git_repo(
os.path.join(self.path, "repos", "forks", "pingou", "test.git")
)
project = pagure.lib.query.get_authorized_project(self.session, "test")
fork = pagure.lib.query.get_authorized_project(
self.session, "test", user="pingou"
)
tests.create_tokens(self.session)
tests.create_tokens_acl(self.session)
req = pagure.lib.query.new_pull_request(
session=self.session,
repo_from=fork,
branch_from="master",
repo_to=project,
branch_to="master",
title="test pull-request",
user="pingou",
)
self.session.commit()
self.assertEqual(req.id, 1)
self.assertEqual(req.title, "test pull-request")
# Assert the PR is open
self.session = pagure.lib.query.create_session(self.dbpath)
project = pagure.lib.query.get_authorized_project(self.session, "test")
self.assertEqual(len(project.requests), 1)
self.assertEqual(project.requests[0].status, "Open")
# Check how the PR renders in the API and the UI
output = self.app.get("/api/0/test/pull-request/1")
self.assertEqual(output.status_code, 200)
output = self.app.get("/test/pull-request/1")
self.assertEqual(output.status_code, 200)
示例14: setUp
def setUp(self):
""" Set up the environnment, ran before every tests. """
super(ViewCommitFlagtests, self).setUp()
tests.create_projects(self.session)
tests.create_tokens(self.session)
# Add a README to the git repo - First commit
tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
self.commit = repo.revparse_single("HEAD")
示例15: test_api_whoami_auth
def test_api_whoami_auth(self):
""" Test the api_whoami function with a valid token. """
tests.create_projects(self.session)
tests.create_tokens(self.session)
headers = {"Authorization": "token aaabbbcccddd"}
output = self.app.post("/api/0/-/whoami", headers=headers)
self.assertEqual(output.status_code, 200)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(data, {"username": "pingou"})