Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test(functional): replace len() calls with list membership checks#2118

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
JohnVillalovos merged 1 commit intomainfromtest/no-len-asserts
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletionstests/functional/api/test_clusters.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
def test_project_clusters(project):
project.clusters.create(
cluster =project.clusters.create(
{
"name": "cluster1",
"platform_kubernetes_attributes": {
Expand All@@ -9,21 +9,20 @@ def test_project_clusters(project):
}
)
clusters = project.clusters.list()
assertlen(clusters) == 1
assertcluster in clusters

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()
assertlen(project.clusters.list()) == 0
assertcluster not inproject.clusters.list()


def test_group_clusters(group):
group.clusters.create(
cluster =group.clusters.create(
{
"name": "cluster1",
"platform_kubernetes_attributes": {
Expand All@@ -33,14 +32,13 @@ def test_group_clusters(group):
}
)
clusters = group.clusters.list()
assertlen(clusters) == 1
assertcluster in clusters

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()
assertlen(group.clusters.list()) == 0
assertcluster not ingroup.clusters.list()
12 changes: 6 additions & 6 deletionstests/functional/api/test_current_user.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
def test_current_user_email(gl):
gl.auth()
mail = gl.user.emails.create({"email": "current@user.com"})
assertlen(gl.user.emails.list()) == 2
assertmail ingl.user.emails.list()

mail.delete()
assertlen(gl.user.emails.list()) == 1
assertmail not ingl.user.emails.list()


def test_current_user_gpg_keys(gl, GPG_KEY):
gl.auth()
gkey = gl.user.gpgkeys.create({"key": GPG_KEY})
assertlen(gl.user.gpgkeys.list()) == 1
assertgkey ingl.user.gpgkeys.list()

# Seems broken on the gitlab side
gkey = gl.user.gpgkeys.get(gkey.id)
gkey.delete()
assertlen(gl.user.gpgkeys.list()) == 0
assertgkey not ingl.user.gpgkeys.list()


def test_current_user_ssh_keys(gl, SSH_KEY):
gl.auth()
key = gl.user.keys.create({"title": "testkey", "key": SSH_KEY})
assertlen(gl.user.keys.list()) == 1
assertkey ingl.user.keys.list()

key.delete()
assertlen(gl.user.keys.list()) == 0
assertkey not ingl.user.keys.list()


def test_current_user_status(gl):
Expand Down
7 changes: 3 additions & 4 deletionstests/functional/api/test_deploy_keys.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
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
assert deploy_key in project.keys.list()

project2 = gl.projects.create({"name": "deploy-key-project"})
project2.keys.enable(deploy_key.id)
assertlen(project2.keys.list()) == 1
assertdeploy_key inproject2.keys.list()

project2.keys.delete(deploy_key.id)
assertlen(project2.keys.list()) == 0
assertdeploy_key not inproject2.keys.list()
project2.delete()
16 changes: 8 additions & 8 deletionstests/functional/api/test_deploy_tokens.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,8 +7,8 @@ def test_project_deploy_tokens(gl, project):
"scopes": ["read_registry"],
}
)
assertlen(project.deploytokens.list()) == 1
assertgl.deploytokens.list() == project.deploytokens.list()
assertdeploy_token inproject.deploytokens.list()
assertset(project.deploytokens.list()) <= set(gl.deploytokens.list())

deploy_token = project.deploytokens.get(deploy_token.id)
assert deploy_token.name == "foo"
Expand All@@ -17,8 +17,8 @@ def test_project_deploy_tokens(gl, project):
assert deploy_token.username == "bar"

deploy_token.delete()
assertlen(project.deploytokens.list()) == 0
assertlen(gl.deploytokens.list()) == 0
assertdeploy_token not inproject.deploytokens.list()
assertdeploy_token not ingl.deploytokens.list()


def test_group_deploy_tokens(gl, group):
Expand All@@ -29,13 +29,13 @@ def test_group_deploy_tokens(gl, group):
}
)

assertlen(group.deploytokens.list()) == 1
assertgl.deploytokens.list() == group.deploytokens.list()
assertdeploy_token ingroup.deploytokens.list()
assertset(group.deploytokens.list()) <= set(gl.deploytokens.list())

deploy_token = group.deploytokens.get(deploy_token.id)
assert deploy_token.name == "foo"
assert deploy_token.scopes == ["read_registry"]

deploy_token.delete()
assertlen(group.deploytokens.list()) == 0
assertlen(gl.deploytokens.list()) == 0
assertdeploy_token not ingroup.deploytokens.list()
assertdeploy_token not ingl.deploytokens.list()
56 changes: 23 additions & 33 deletionstests/functional/api/test_gitlab.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
import warnings

import pytest

import gitlab
Expand DownExpand Up@@ -27,7 +25,7 @@ def test_broadcast_messages(gl):
assert msg.color == "#444444"

msg.delete()
assertlen(gl.broadcastmessages.list()) == 0
assertmsg not ingl.broadcastmessages.list()


def test_markdown(gl):
Expand DownExpand Up@@ -109,10 +107,10 @@ def test_template_license(gl):

def test_hooks(gl):
hook = gl.hooks.create({"url": "http://whatever.com"})
assertlen(gl.hooks.list()) == 1
asserthook ingl.hooks.list()

hook.delete()
assertlen(gl.hooks.list()) == 0
asserthook not ingl.hooks.list()


def test_namespaces(gl):
Expand DownExpand Up@@ -151,10 +149,10 @@ def test_events(gl):
def test_features(gl):
feat = gl.features.set("foo", 30)
assert feat.name == "foo"
assertlen(gl.features.list()) == 1
assertfeat ingl.features.list()

feat.delete()
assertlen(gl.features.list()) == 0
assertfeat not ingl.features.list()


def test_pagination(gl, project):
Expand DownExpand Up@@ -198,54 +196,46 @@ def test_rate_limits(gl):
def test_list_default_warning(gl):
"""When there are more than 20 items and use default `list()` then warning is
generated"""
withwarnings.catch_warnings(record=True) ascaught_warnings:
withpytest.warns(UserWarning, match="python-gitlab.readthedocs.io") asrecord:
gl.gitlabciymls.list()
assert len(caught_warnings) == 1
warning = caught_warnings[0]
assert isinstance(warning.message, UserWarning)
message = str(warning.message)
assert "python-gitlab.readthedocs.io" in message

assert len(record) == 1
warning = record[0]
assert __file__ == warning.filename


def test_list_page_nowarning(gl):
def test_list_page_nowarning(gl, recwarn):
"""Using `page=X` will disable the warning"""
with warnings.catch_warnings(record=True) as caught_warnings:
gl.gitlabciymls.list(page=1)
assert len(caught_warnings) == 0
gl.gitlabciymls.list(page=1)
assert not recwarn


def test_list_all_false_nowarning(gl):
def test_list_all_false_nowarning(gl, recwarn):
"""Using `all=False` will disable the warning"""
with warnings.catch_warnings(record=True) as caught_warnings:
gl.gitlabciymls.list(all=False)
assert len(caught_warnings) == 0
gl.gitlabciymls.list(all=False)
assert not recwarn


def test_list_all_true_nowarning(gl):
def test_list_all_true_nowarning(gl, recwarn):
"""Using `all=True` will disable the warning"""
with warnings.catch_warnings(record=True) as caught_warnings:
items = gl.gitlabciymls.list(all=True)
assert len(caught_warnings) == 0
items = gl.gitlabciymls.list(all=True)
assert not recwarn
assert len(items) > 20


def test_list_iterator_true_nowarning(gl):
def test_list_iterator_true_nowarning(gl, recwarn):
"""Using `iterator=True` will disable the warning"""
with warnings.catch_warnings(record=True) as caught_warnings:
items = gl.gitlabciymls.list(iterator=True)
assert len(caught_warnings) == 0
items = gl.gitlabciymls.list(iterator=True)
assert not recwarn
assert len(list(items)) > 20


def test_list_as_list_false_warnings(gl):
"""Using `as_list=False` will disable the UserWarning but cause a
DeprecationWarning"""
withwarnings.catch_warnings(record=True) ascaught_warnings:
withpytest.warns(DeprecationWarning) asrecord:
items = gl.gitlabciymls.list(as_list=False)
assert len(caught_warnings) == 1
for warning in caught_warnings:
assert isinstance(warning.message, DeprecationWarning)
assert len(record) == 1
assert len(list(items)) > 20


Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp