| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 04c6063 commit 97e0eb9
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | def test_project_clusters(project): | |
| 2 | - project.clusters.create( | ||
| 2 | + cluster = project.clusters.create( | ||
| 3 | 3 | { | |
| 4 | 4 | "name": "cluster1", | |
| 5 | 5 | "platform_kubernetes_attributes": { | |
@@ -9,21 +9,20 @@ def test_project_clusters(project): | |||
| 9 | 9 | } | |
| 10 | 10 | ) | |
| 11 | 11 | clusters = project.clusters.list() | |
| 12 | - assert len(clusters) == 1 | ||
| 12 | + assert cluster in clusters | ||
| 13 | 13 | ||
| 14 | - cluster = clusters[0] | ||
| 15 | 14 | cluster.platform_kubernetes_attributes = {"api_url": "http://newurl"} | |
| 16 | 15 | cluster.save() | |
| 17 | 16 | ||
| 18 | 17 | cluster = project.clusters.list()[0] | |
| 19 | 18 | assert cluster.platform_kubernetes["api_url"] == "http://newurl" | |
| 20 | 19 | ||
| 21 | 20 | cluster.delete() | |
| 22 | - assert len(project.clusters.list()) == 0 | ||
| 21 | + assert cluster not in project.clusters.list() | ||
| 23 | 22 | ||
| 24 | 23 | ||
| 25 | 24 | def test_group_clusters(group): | |
| 26 | - group.clusters.create( | ||
| 25 | + cluster = group.clusters.create( | ||
| 27 | 26 | { | |
| 28 | 27 | "name": "cluster1", | |
| 29 | 28 | "platform_kubernetes_attributes": { | |
@@ -33,14 +32,13 @@ def test_group_clusters(group): | |||
| 33 | 32 | } | |
| 34 | 33 | ) | |
| 35 | 34 | clusters = group.clusters.list() | |
| 36 | - assert len(clusters) == 1 | ||
| 35 | + assert cluster in clusters | ||
| 37 | 36 | ||
| 38 | - cluster = clusters[0] | ||
| 39 | 37 | cluster.platform_kubernetes_attributes = {"api_url": "http://newurl"} | |
| 40 | 38 | cluster.save() | |
| 41 | 39 | ||
| 42 | 40 | cluster = group.clusters.list()[0] | |
| 43 | 41 | assert cluster.platform_kubernetes["api_url"] == "http://newurl" | |
| 44 | 42 | ||
| 45 | 43 | cluster.delete() | |
| 46 | - assert len(group.clusters.list()) == 0 | ||
| 44 | + assert cluster not in group.clusters.list() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,30 +1,30 @@ | |||
| 1 | 1 | def test_current_user_email(gl): | |
| 2 | 2 | gl.auth() | |
| 3 | 3 | mail = gl.user.emails.create({"email": "current@user.com"}) | |
| 4 | - assert len(gl.user.emails.list()) == 2 | ||
| 4 | + assert mail in gl.user.emails.list() | ||
| 5 | 5 | ||
| 6 | 6 | mail.delete() | |
| 7 | - assert len(gl.user.emails.list()) == 1 | ||
| 7 | + assert mail not in gl.user.emails.list() | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | def test_current_user_gpg_keys(gl, GPG_KEY): | |
| 11 | 11 | gl.auth() | |
| 12 | 12 | gkey = gl.user.gpgkeys.create({"key": GPG_KEY}) | |
| 13 | - assert len(gl.user.gpgkeys.list()) == 1 | ||
| 13 | + assert gkey in gl.user.gpgkeys.list() | ||
| 14 | 14 | ||
| 15 | 15 | # Seems broken on the gitlab side | |
| 16 | 16 | gkey = gl.user.gpgkeys.get(gkey.id) | |
| 17 | 17 | gkey.delete() | |
| 18 | - assert len(gl.user.gpgkeys.list()) == 0 | ||
| 18 | + assert gkey not in gl.user.gpgkeys.list() | ||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | def test_current_user_ssh_keys(gl, SSH_KEY): | |
| 22 | 22 | gl.auth() | |
| 23 | 23 | key = gl.user.keys.create({"title": "testkey", "key": SSH_KEY}) | |
| 24 | - assert len(gl.user.keys.list()) == 1 | ||
| 24 | + assert key in gl.user.keys.list() | ||
| 25 | 25 | ||
| 26 | 26 | key.delete() | |
| 27 | - assert len(gl.user.keys.list()) == 0 | ||
| 27 | + assert key not in gl.user.keys.list() | ||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | 30 | def test_current_user_status(gl): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,11 @@ | |||
| 1 | 1 | def test_project_deploy_keys(gl, project, DEPLOY_KEY): | |
| 2 | 2 | deploy_key = project.keys.create({"title": "foo@bar", "key": DEPLOY_KEY}) | |
| 3 | - project_keys = list(project.keys.list()) | ||
| 4 | - assert len(project_keys) == 1 | ||
| 3 | + assert deploy_key in project.keys.list() | ||
| 5 | 4 | ||
| 6 | 5 | project2 = gl.projects.create({"name": "deploy-key-project"}) | |
| 7 | 6 | project2.keys.enable(deploy_key.id) | |
| 8 | - assert len(project2.keys.list()) == 1 | ||
| 7 | + assert deploy_key in project2.keys.list() | ||
| 9 | 8 | ||
| 10 | 9 | project2.keys.delete(deploy_key.id) | |
| 11 | - assert len(project2.keys.list()) == 0 | ||
| 10 | + assert deploy_key not in project2.keys.list() | ||
| 12 | 11 | project2.delete() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,8 +7,8 @@ def test_project_deploy_tokens(gl, project): | |||
| 7 | 7 | "scopes": ["read_registry"], | |
| 8 | 8 | } | |
| 9 | 9 | ) | |
| 10 | - assert len(project.deploytokens.list()) == 1 | ||
| 11 | - assert gl.deploytokens.list() == project.deploytokens.list() | ||
| 10 | + assert deploy_token in project.deploytokens.list() | ||
| 11 | + assert set(project.deploytokens.list()) <= set(gl.deploytokens.list()) | ||
| 12 | 12 | ||
| 13 | 13 | deploy_token = project.deploytokens.get(deploy_token.id) | |
| 14 | 14 | assert deploy_token.name == "foo" | |
@@ -17,8 +17,8 @@ def test_project_deploy_tokens(gl, project): | |||
| 17 | 17 | assert deploy_token.username == "bar" | |
| 18 | 18 | ||
| 19 | 19 | deploy_token.delete() | |
| 20 | - assert len(project.deploytokens.list()) == 0 | ||
| 21 | - assert len(gl.deploytokens.list()) == 0 | ||
| 20 | + assert deploy_token not in project.deploytokens.list() | ||
| 21 | + assert deploy_token not in gl.deploytokens.list() | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | def test_group_deploy_tokens(gl, group): | |
@@ -29,13 +29,13 @@ def test_group_deploy_tokens(gl, group): | |||
| 29 | 29 | } | |
| 30 | 30 | ) | |
| 31 | 31 | ||
| 32 | - assert len(group.deploytokens.list()) == 1 | ||
| 33 | - assert gl.deploytokens.list() == group.deploytokens.list() | ||
| 32 | + assert deploy_token in group.deploytokens.list() | ||
| 33 | + assert set(group.deploytokens.list()) <= set(gl.deploytokens.list()) | ||
| 34 | 34 | ||
| 35 | 35 | deploy_token = group.deploytokens.get(deploy_token.id) | |
| 36 | 36 | assert deploy_token.name == "foo" | |
| 37 | 37 | assert deploy_token.scopes == ["read_registry"] | |
| 38 | 38 | ||
| 39 | 39 | deploy_token.delete() | |
| 40 | - assert len(group.deploytokens.list()) == 0 | ||
| 41 | - assert len(gl.deploytokens.list()) == 0 | ||
| 40 | + assert deploy_token not in group.deploytokens.list() | ||
| 41 | + assert deploy_token not in gl.deploytokens.list() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,3 @@ | |||
| 1 | - import warnings | ||
| 2 | - | ||
| 3 | 1 | import pytest | |
| 4 | 2 | ||
| 5 | 3 | import gitlab | |
@@ -27,7 +25,7 @@ def test_broadcast_messages(gl): | |||
| 27 | 25 | assert msg.color == "#444444" | |
| 28 | 26 | ||
| 29 | 27 | msg.delete() | |
| 30 | - assert len(gl.broadcastmessages.list()) == 0 | ||
| 28 | + assert msg not in gl.broadcastmessages.list() | ||
| 31 | 29 | ||
| 32 | 30 | ||
| 33 | 31 | def test_markdown(gl): | |
@@ -109,10 +107,10 @@ def test_template_license(gl): | |||
| 109 | 107 | ||
| 110 | 108 | def test_hooks(gl): | |
| 111 | 109 | hook = gl.hooks.create({"url": "http://whatever.com"}) | |
| 112 | - assert len(gl.hooks.list()) == 1 | ||
| 110 | + assert hook in gl.hooks.list() | ||
| 113 | 111 | ||
| 114 | 112 | hook.delete() | |
| 115 | - assert len(gl.hooks.list()) == 0 | ||
| 113 | + assert hook not in gl.hooks.list() | ||
| 116 | 114 | ||
| 117 | 115 | ||
| 118 | 116 | def test_namespaces(gl): | |
@@ -151,10 +149,10 @@ def test_events(gl): | |||
| 151 | 149 | def test_features(gl): | |
| 152 | 150 | feat = gl.features.set("foo", 30) | |
| 153 | 151 | assert feat.name == "foo" | |
| 154 | - assert len(gl.features.list()) == 1 | ||
| 152 | + assert feat in gl.features.list() | ||
| 155 | 153 | ||
| 156 | 154 | feat.delete() | |
| 157 | - assert len(gl.features.list()) == 0 | ||
| 155 | + assert feat not in gl.features.list() | ||
| 158 | 156 | ||
| 159 | 157 | ||
| 160 | 158 | def test_pagination(gl, project): | |
@@ -198,54 +196,46 @@ def test_rate_limits(gl): | |||
| 198 | 196 | def test_list_default_warning(gl): | |
| 199 | 197 | """When there are more than 20 items and use default `list()` then warning is | |
| 200 | 198 | generated""" | |
| 201 | - with warnings.catch_warnings(record=True) as caught_warnings: | ||
| 199 | + with pytest.warns(UserWarning, match="python-gitlab.readthedocs.io") as record: | ||
| 202 | 200 | gl.gitlabciymls.list() | |
| 203 | - assert len(caught_warnings) == 1 | ||
| 204 | - warning = caught_warnings[0] | ||
| 205 | - assert isinstance(warning.message, UserWarning) | ||
| 206 | - message = str(warning.message) | ||
| 207 | - assert "python-gitlab.readthedocs.io" in message | ||
| 201 | + | ||
| 202 | + assert len(record) == 1 | ||
| 203 | + warning = record[0] | ||
| 208 | 204 | assert __file__ == warning.filename | |
| 209 | 205 | ||
| 210 | 206 | ||
| 211 | - def test_list_page_nowarning(gl): | ||
| 207 | + def test_list_page_nowarning(gl, recwarn): | ||
| 212 | 208 | """Using `page=X` will disable the warning""" | |
| 213 | - with warnings.catch_warnings(record=True) as caught_warnings: | ||
| 214 | - gl.gitlabciymls.list(page=1) | ||
| 215 | - assert len(caught_warnings) == 0 | ||
| 209 | + gl.gitlabciymls.list(page=1) | ||
| 210 | + assert not recwarn | ||
| 216 | 211 | ||
| 217 | 212 | ||
| 218 | - def test_list_all_false_nowarning(gl): | ||
| 213 | + def test_list_all_false_nowarning(gl, recwarn): | ||
| 219 | 214 | """Using `all=False` will disable the warning""" | |
| 220 | - with warnings.catch_warnings(record=True) as caught_warnings: | ||
| 221 | - gl.gitlabciymls.list(all=False) | ||
| 222 | - assert len(caught_warnings) == 0 | ||
| 215 | + gl.gitlabciymls.list(all=False) | ||
| 216 | + assert not recwarn | ||
| 223 | 217 | ||
| 224 | 218 | ||
| 225 | - def test_list_all_true_nowarning(gl): | ||
| 219 | + def test_list_all_true_nowarning(gl, recwarn): | ||
| 226 | 220 | """Using `all=True` will disable the warning""" | |
| 227 | - with warnings.catch_warnings(record=True) as caught_warnings: | ||
| 228 | - items = gl.gitlabciymls.list(all=True) | ||
| 229 | - assert len(caught_warnings) == 0 | ||
| 221 | + items = gl.gitlabciymls.list(all=True) | ||
| 222 | + assert not recwarn | ||
| 230 | 223 | assert len(items) > 20 | |
| 231 | 224 | ||
| 232 | 225 | ||
| 233 | - def test_list_iterator_true_nowarning(gl): | ||
| 226 | + def test_list_iterator_true_nowarning(gl, recwarn): | ||
| 234 | 227 | """Using `iterator=True` will disable the warning""" | |
| 235 | - with warnings.catch_warnings(record=True) as caught_warnings: | ||
| 236 | - items = gl.gitlabciymls.list(iterator=True) | ||
| 237 | - assert len(caught_warnings) == 0 | ||
| 228 | + items = gl.gitlabciymls.list(iterator=True) | ||
| 229 | + assert not recwarn | ||
| 238 | 230 | assert len(list(items)) > 20 | |
| 239 | 231 | ||
| 240 | 232 | ||
| 241 | 233 | def test_list_as_list_false_warnings(gl): | |
| 242 | 234 | """Using `as_list=False` will disable the UserWarning but cause a | |
| 243 | 235 | DeprecationWarning""" | |
| 244 | - with warnings.catch_warnings(record=True) as caught_warnings: | ||
| 236 | + with pytest.warns(DeprecationWarning) as record: | ||
| 245 | 237 | items = gl.gitlabciymls.list(as_list=False) | |
| 246 | - assert len(caught_warnings) == 1 | ||
| 247 | - for warning in caught_warnings: | ||
| 248 | - assert isinstance(warning.message, DeprecationWarning) | ||
| 238 | + assert len(record) == 1 | ||
| 249 | 239 | assert len(list(items)) > 20 | |
| 250 | 240 | ||
| 251 | 241 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments