- Notifications
You must be signed in to change notification settings - Fork673
refactor(tests): split functional tests#1205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletionstools/functional/api/test_clusters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
def test_project_clusters(project): | ||
project.clusters.create( | ||
{ | ||
"name": "cluster1", | ||
"platform_kubernetes_attributes": { | ||
"api_url": "http://url", | ||
"token": "tokenval", | ||
}, | ||
} | ||
) | ||
clusters = project.clusters.list() | ||
assert len(clusters) == 1 | ||
cluster = clusters[0] | ||
cluster.platform_kubernetes_attributes = {"api_url": "http://newurl"} | ||
cluster.save() | ||
cluster = project.clusters.list()[0] | ||
assert cluster.platform_kubernetes["api_url"] == "http://newurl" | ||
cluster.delete() | ||
assert len(project.clusters.list()) == 0 | ||
def test_group_clusters(group): | ||
group.clusters.create( | ||
{ | ||
"name": "cluster1", | ||
"platform_kubernetes_attributes": { | ||
"api_url": "http://url", | ||
"token": "tokenval", | ||
}, | ||
} | ||
) | ||
clusters = group.clusters.list() | ||
assert len(clusters) == 1 | ||
cluster = clusters[0] | ||
cluster.platform_kubernetes_attributes = {"api_url": "http://newurl"} | ||
cluster.save() | ||
cluster = group.clusters.list()[0] | ||
assert cluster.platform_kubernetes["api_url"] == "http://newurl" | ||
cluster.delete() | ||
assert len(group.clusters.list()) == 0 |
42 changes: 42 additions & 0 deletionstools/functional/api/test_current_user.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
def test_current_user_email(gl): | ||
gl.auth() | ||
mail = gl.user.emails.create({"email": "current@user.com"}) | ||
assert len(gl.user.emails.list()) == 1 | ||
mail.delete() | ||
assert len(gl.user.emails.list()) == 0 | ||
def test_current_user_gpg_keys(gl, GPG_KEY): | ||
gl.auth() | ||
gkey = gl.user.gpgkeys.create({"key": GPG_KEY}) | ||
assert len(gl.user.gpgkeys.list()) == 1 | ||
# Seems broken on the gitlab side | ||
gkey = gl.user.gpgkeys.get(gkey.id) | ||
gkey.delete() | ||
assert len(gl.user.gpgkeys.list()) == 0 | ||
def test_current_user_ssh_keys(gl, SSH_KEY): | ||
gl.auth() | ||
key = gl.user.keys.create({"title": "testkey", "key": SSH_KEY}) | ||
assert len(gl.user.keys.list()) == 1 | ||
key.delete() | ||
assert len(gl.user.keys.list()) == 0 | ||
def test_current_user_status(gl): | ||
gl.auth() | ||
message = "Test" | ||
emoji = "thumbsup" | ||
status = gl.user.status.get() | ||
status.message = message | ||
status.emoji = emoji | ||
status.save() | ||
new_status = gl.user.status.get() | ||
assert new_status.message == message | ||
assert new_status.emoji == emoji |
12 changes: 12 additions & 0 deletionstools/functional/api/test_deploy_keys.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def test_project_deploy_keys(gl, project, DEPLOY_KEY): | ||
deploy_key = project.keys.create({"title": "foo@bar", "key": DEPLOY_KEY}) | ||
project_keys = list(project.keys.list()) | ||
assert len(project_keys) == 1 | ||
project2 = gl.projects.create({"name": "deploy-key-project"}) | ||
project2.keys.enable(deploy_key.id) | ||
assert len(project2.keys.list()) == 1 | ||
project2.keys.delete(deploy_key.id) | ||
assert len(project2.keys.list()) == 0 | ||
project2.delete() |
36 changes: 36 additions & 0 deletionstools/functional/api/test_deploy_tokens.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
def test_project_deploy_tokens(gl, project): | ||
deploy_token = project.deploytokens.create( | ||
{ | ||
"name": "foo", | ||
"username": "bar", | ||
"expires_at": "2022-01-01", | ||
"scopes": ["read_registry"], | ||
} | ||
) | ||
assert len(project.deploytokens.list()) == 1 | ||
assert gl.deploytokens.list() == project.deploytokens.list() | ||
assert project.deploytokens.list()[0].name == "foo" | ||
assert project.deploytokens.list()[0].expires_at == "2022-01-01T00:00:00.000Z" | ||
assert project.deploytokens.list()[0].scopes == ["read_registry"] | ||
assert project.deploytokens.list()[0].username == "bar" | ||
deploy_token.delete() | ||
assert len(project.deploytokens.list()) == 0 | ||
assert len(gl.deploytokens.list()) == 0 | ||
def test_group_deploy_tokens(gl, group): | ||
deploy_token = group.deploytokens.create( | ||
{ | ||
"name": "foo", | ||
"scopes": ["read_registry"], | ||
} | ||
) | ||
assert len(group.deploytokens.list()) == 1 | ||
assert gl.deploytokens.list() == group.deploytokens.list() | ||
deploy_token.delete() | ||
assert len(group.deploytokens.list()) == 0 | ||
assert len(gl.deploytokens.list()) == 0 |
187 changes: 181 additions & 6 deletionstools/functional/api/test_gitlab.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,183 @@ | ||
import pytest | ||
import gitlab | ||
def test_auth_from_config(gl, temp_dir): | ||
"""Test token authentication from config file""" | ||
test_gitlab = gitlab.Gitlab.from_config( | ||
config_files=[temp_dir / "python-gitlab.cfg"] | ||
) | ||
test_gitlab.auth() | ||
assert isinstance(test_gitlab.user, gitlab.v4.objects.CurrentUser) | ||
def test_broadcast_messages(gl): | ||
msg = gl.broadcastmessages.create({"message": "this is the message"}) | ||
msg.color = "#444444" | ||
msg.save() | ||
msg_id = msg.id | ||
msg = gl.broadcastmessages.list(all=True)[0] | ||
assert msg.color == "#444444" | ||
msg = gl.broadcastmessages.get(msg_id) | ||
assert msg.color == "#444444" | ||
msg.delete() | ||
assert len(gl.broadcastmessages.list()) == 0 | ||
def test_markdown(gl): | ||
html = gl.markdown("foo") | ||
assert "foo" in html | ||
def test_lint(gl): | ||
success, errors = gl.lint("Invalid") | ||
assert success is False | ||
assert errors | ||
def test_sidekiq_queue_metrics(gl): | ||
out = gl.sidekiq.queue_metrics() | ||
assert isinstance(out, dict) | ||
assert "pages" in out["queues"] | ||
def test_sidekiq_process_metrics(gl): | ||
out = gl.sidekiq.process_metrics() | ||
assert isinstance(out, dict) | ||
assert "hostname" in out["processes"][0] | ||
def test_sidekiq_job_stats(gl): | ||
out = gl.sidekiq.job_stats() | ||
assert isinstance(out, dict) | ||
assert "processed" in out["jobs"] | ||
def test_sidekiq_compound_metrics(gl): | ||
out = gl.sidekiq.compound_metrics() | ||
assert isinstance(out, dict) | ||
assert "jobs" in out | ||
assert "processes" in out | ||
assert "queues" in out | ||
def test_gitlab_settings(gl): | ||
settings = gl.settings.get() | ||
settings.default_projects_limit = 42 | ||
settings.save() | ||
settings = gl.settings.get() | ||
assert settings.default_projects_limit == 42 | ||
def test_template_dockerfile(gl): | ||
assert gl.dockerfiles.list() | ||
dockerfile = gl.dockerfiles.get("Node") | ||
assert dockerfile.content is not None | ||
def test_template_gitignore(gl): | ||
assert gl.gitignores.list() | ||
gitignore = gl.gitignores.get("Node") | ||
assert gitignore.content is not None | ||
def test_template_gitlabciyml(gl): | ||
assert gl.gitlabciymls.list() | ||
gitlabciyml = gl.gitlabciymls.get("Nodejs") | ||
assert gitlabciyml.content is not None | ||
def test_template_license(gl): | ||
assert gl.licenses.list() | ||
license = gl.licenses.get( | ||
"bsd-2-clause", project="mytestproject", fullname="mytestfullname" | ||
) | ||
assert "mytestfullname" in license.content | ||
def test_hooks(gl): | ||
hook = gl.hooks.create({"url": "http://whatever.com"}) | ||
assert len(gl.hooks.list()) == 1 | ||
hook.delete() | ||
assert len(gl.hooks.list()) == 0 | ||
def test_namespaces(gl): | ||
namespace = gl.namespaces.list(all=True) | ||
assert namespace | ||
namespace = gl.namespaces.list(search="root", all=True)[0] | ||
assert namespace.kind == "user" | ||
def test_notification_settings(gl): | ||
settings = gl.notificationsettings.get() | ||
settings.level = gitlab.NOTIFICATION_LEVEL_WATCH | ||
settings.save() | ||
settings = gl.notificationsettings.get() | ||
assert settings.level == gitlab.NOTIFICATION_LEVEL_WATCH | ||
def test_user_activities(gl): | ||
activities = gl.user_activities.list(query_parameters={"from": "2019-01-01"}) | ||
assert isinstance(activities, list) | ||
def test_events(gl): | ||
events = gl.events.list() | ||
assert isinstance(events, list) | ||
@pytest.mark.skip | ||
def test_features(gl): | ||
feat = gl.features.set("foo", 30) | ||
assert feat.name == "foo" | ||
assert len(gl.features.list()) == 1 | ||
feat.delete() | ||
assert len(gl.features.list()) == 0 | ||
def test_pagination(gl, project): | ||
project2 = gl.projects.create({"name": "project-page-2"}) | ||
list1 = gl.projects.list(per_page=1, page=1) | ||
list2 = gl.projects.list(per_page=1, page=2) | ||
assert len(list1) == 1 | ||
assert len(list2) == 1 | ||
assert list1[0].id != list2[0].id | ||
project2.delete() | ||
def test_rate_limits(gl): | ||
settings = gl.settings.get() | ||
settings.throttle_authenticated_api_enabled = True | ||
settings.throttle_authenticated_api_requests_per_period = 1 | ||
settings.throttle_authenticated_api_period_in_seconds = 3 | ||
settings.save() | ||
projects = list() | ||
for i in range(0, 20): | ||
projects.append(gl.projects.create({"name": str(i) + "ok"})) | ||
with pytest.raises(gitlab.GitlabCreateError) as e: | ||
for i in range(20, 40): | ||
projects.append( | ||
gl.projects.create( | ||
{"name": str(i) + "shouldfail"}, obey_rate_limit=False | ||
) | ||
) | ||
assert "Retry later" in str(e.value) | ||
settings.throttle_authenticated_api_enabled = False | ||
settings.save() | ||
[project.delete() for project in projects] |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.