Skip to content

Commit

Permalink
chore: run unittest2pytest on all unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nejch committed Aug 22, 2020
1 parent 402566a commit 11383e7
Show file tree
Hide file tree
Showing 12 changed files with 446 additions and 439 deletions.
8 changes: 4 additions & 4 deletions gitlab/tests/objects/test_application.py
Expand Up @@ -80,13 +80,13 @@ def resp_update_appearance(url, request):

with HTTMock(resp_get_appearance), HTTMock(resp_update_appearance):
appearance = self.gl.appearance.get()
self.assertEqual(appearance.title, self.title)
self.assertEqual(appearance.description, self.description)
assert appearance.title == self.title
assert appearance.description == self.description
appearance.title = self.new_title
appearance.description = self.new_description
appearance.save()
self.assertEqual(appearance.title, self.new_title)
self.assertEqual(appearance.description, self.new_description)
assert appearance.title == self.new_title
assert appearance.description == self.new_description

def test_update_appearance(self):
@urlmatch(
Expand Down
16 changes: 8 additions & 8 deletions gitlab/tests/objects/test_commits.py
Expand Up @@ -78,8 +78,8 @@ class TestCommit(TestProject):
@with_httmock(resp_get_commit)
def test_get_commit(self):
commit = self.project.commits.get("6b2257ea")
self.assertEqual(commit.short_id, "6b2257ea")
self.assertEqual(commit.title, "Initial commit")
assert commit.short_id == "6b2257ea"
assert commit.title == "Initial commit"

@with_httmock(resp_create_commit)
def test_create_commit(self):
Expand All @@ -89,19 +89,19 @@ def test_create_commit(self):
"actions": [{"action": "create", "file_path": "README", "content": "",}],
}
commit = self.project.commits.create(data)
self.assertEqual(commit.short_id, "ed899a2f")
self.assertEqual(commit.title, data["commit_message"])
assert commit.short_id == "ed899a2f"
assert commit.title == data["commit_message"]

@with_httmock(resp_revert_commit)
def test_revert_commit(self):
commit = self.project.commits.get("6b2257ea", lazy=True)
revert_commit = commit.revert(branch="master")
self.assertEqual(revert_commit["short_id"], "8b090c1b")
self.assertEqual(revert_commit["title"], 'Revert "Initial commit"')
assert revert_commit["short_id"] == "8b090c1b"
assert revert_commit["title"] == 'Revert "Initial commit"'

@with_httmock(resp_get_commit_gpg_signature)
def test_get_commit_gpg_signature(self):
commit = self.project.commits.get("6b2257ea", lazy=True)
signature = commit.signature()
self.assertEqual(signature["gpg_key_primary_keyid"], "8254AAB3FBD54AC9")
self.assertEqual(signature["verification_status"], "verified")
assert signature["gpg_key_primary_keyid"] == "8254AAB3FBD54AC9"
assert signature["verification_status"] == "verified"
26 changes: 13 additions & 13 deletions gitlab/tests/objects/test_groups.py
Expand Up @@ -48,18 +48,18 @@ def setUp(self):
@with_httmock(resp_get_group)
def test_get_group(self):
data = self.gl.groups.get(1)
self.assertIsInstance(data, gitlab.v4.objects.Group)
self.assertEqual(data.name, "name")
self.assertEqual(data.path, "path")
self.assertEqual(data.id, 1)
assert isinstance(data, gitlab.v4.objects.Group)
assert data.name == "name"
assert data.path == "path"
assert data.id == 1

@with_httmock(resp_create_group)
def test_create_group(self):
name, path = "name", "path"
data = self.gl.groups.create({"name": name, "path": path})
self.assertIsInstance(data, gitlab.v4.objects.Group)
self.assertEqual(data.name, name)
self.assertEqual(data.path, path)
assert isinstance(data, gitlab.v4.objects.Group)
assert data.name == name
assert data.path == path


class TestGroupExport(TestGroup):
Expand All @@ -70,32 +70,32 @@ def setUp(self):
@with_httmock(resp_create_export)
def test_create_group_export(self):
export = self.group.exports.create()
self.assertEqual(export.message, "202 Accepted")
assert export.message == "202 Accepted"

@unittest.skip("GitLab API endpoint not implemented")
@with_httmock(resp_create_export)
def test_refresh_group_export_status(self):
export = self.group.exports.create()
export.refresh()
self.assertEqual(export.export_status, "finished")
assert export.export_status == "finished"

@with_httmock(resp_create_export, resp_download_export)
def test_download_group_export(self):
export = self.group.exports.create()
download = export.download()
self.assertIsInstance(download, bytes)
self.assertEqual(download, binary_content)
assert isinstance(download, bytes)
assert download == binary_content


class TestGroupImport(TestGroup):
@with_httmock(resp_create_import)
def test_import_group(self):
group_import = self.gl.groups.import_group("file", "api-group", "API Group")
self.assertEqual(group_import["message"], "202 Accepted")
assert group_import["message"] == "202 Accepted"

@unittest.skip("GitLab API endpoint not implemented")
@with_httmock(resp_create_import)
def test_refresh_group_import_status(self):
group_import = self.group.imports.get()
group_import.refresh()
self.assertEqual(group_import.import_status, "finished")
assert group_import.import_status == "finished"
70 changes: 35 additions & 35 deletions gitlab/tests/objects/test_projects.py
Expand Up @@ -341,9 +341,9 @@ def resp_list_snippet(url, request):

with HTTMock(resp_list_snippet):
snippets = self.project.snippets.list()
self.assertEqual(len(snippets), 1)
self.assertEqual(snippets[0].title, title)
self.assertEqual(snippets[0].visibility, visibility)
assert len(snippets) == 1
assert snippets[0].title == title
assert snippets[0].visibility == visibility

def test_get_project_snippets(self):
title = "Example Snippet Title"
Expand All @@ -370,8 +370,8 @@ def resp_get_snippet(url, request):

with HTTMock(resp_get_snippet):
snippet = self.project.snippets.get(1)
self.assertEqual(snippet.title, title)
self.assertEqual(snippet.visibility, visibility)
assert snippet.title == title
assert snippet.visibility == visibility

def test_create_update_project_snippets(self):
title = "Example Snippet Title"
Expand Down Expand Up @@ -424,107 +424,107 @@ def resp_create_snippet(url, request):
"visibility": visibility,
}
)
self.assertEqual(snippet.title, title)
self.assertEqual(snippet.visibility, visibility)
assert snippet.title == title
assert snippet.visibility == visibility
title = "new-title"
snippet.title = title
snippet.save()
self.assertEqual(snippet.title, title)
self.assertEqual(snippet.visibility, visibility)
assert snippet.title == title
assert snippet.visibility == visibility


class TestProjectExport(TestProject):
@with_httmock(resp_create_export)
def test_create_project_export(self):
export = self.project.exports.create()
self.assertEqual(export.message, "202 Accepted")
assert export.message == "202 Accepted"

@with_httmock(resp_create_export, resp_export_status)
def test_refresh_project_export_status(self):
export = self.project.exports.create()
export.refresh()
self.assertEqual(export.export_status, "finished")
assert export.export_status == "finished"

@with_httmock(resp_create_export, resp_download_export)
def test_download_project_export(self):
export = self.project.exports.create()
download = export.download()
self.assertIsInstance(download, bytes)
self.assertEqual(download, binary_content)
assert isinstance(download, bytes)
assert download == binary_content


class TestProjectImport(TestProject):
@with_httmock(resp_import_project)
def test_import_project(self):
project_import = self.gl.projects.import_project("file", "api-project")
self.assertEqual(project_import["import_status"], "scheduled")
assert project_import["import_status"] == "scheduled"

@with_httmock(resp_import_status)
def test_refresh_project_import_status(self):
project_import = self.project.imports.get()
project_import.refresh()
self.assertEqual(project_import.import_status, "finished")
assert project_import.import_status == "finished"

@with_httmock(resp_import_github)
def test_import_github(self):
base_path = "/root"
name = "my-repo"
ret = self.gl.projects.import_github("githubkey", 1234, base_path, name)
self.assertIsInstance(ret, dict)
self.assertEqual(ret["name"], name)
self.assertEqual(ret["full_path"], "/".join((base_path, name)))
self.assertTrue(ret["full_name"].endswith(name))
assert isinstance(ret, dict)
assert ret["name"] == name
assert ret["full_path"] == "/".join((base_path, name))
assert ret["full_name"].endswith(name)


class TestProjectRemoteMirrors(TestProject):
@with_httmock(resp_get_remote_mirrors)
def test_list_project_remote_mirrors(self):
mirrors = self.project.remote_mirrors.list()
self.assertIsInstance(mirrors, list)
self.assertIsInstance(mirrors[0], ProjectRemoteMirror)
self.assertTrue(mirrors[0].enabled)
assert isinstance(mirrors, list)
assert isinstance(mirrors[0], ProjectRemoteMirror)
assert mirrors[0].enabled

@with_httmock(resp_create_remote_mirror)
def test_create_project_remote_mirror(self):
mirror = self.project.remote_mirrors.create({"url": "https://example.com"})
self.assertIsInstance(mirror, ProjectRemoteMirror)
self.assertEqual(mirror.update_status, "none")
assert isinstance(mirror, ProjectRemoteMirror)
assert mirror.update_status == "none"

@with_httmock(resp_create_remote_mirror, resp_update_remote_mirror)
def test_update_project_remote_mirror(self):
mirror = self.project.remote_mirrors.create({"url": "https://example.com"})
mirror.only_protected_branches = True
mirror.save()
self.assertEqual(mirror.update_status, "finished")
self.assertTrue(mirror.only_protected_branches)
assert mirror.update_status == "finished"
assert mirror.only_protected_branches


class TestProjectServices(TestProject):
@with_httmock(resp_get_active_services)
def test_list_active_services(self):
services = self.project.services.list()
self.assertIsInstance(services, list)
self.assertIsInstance(services[0], ProjectService)
self.assertTrue(services[0].active)
self.assertTrue(services[0].push_events)
assert isinstance(services, list)
assert isinstance(services[0], ProjectService)
assert services[0].active
assert services[0].push_events

def test_list_available_services(self):
services = self.project.services.available()
self.assertIsInstance(services, list)
self.assertIsInstance(services[0], str)
assert isinstance(services, list)
assert isinstance(services[0], str)

@with_httmock(resp_get_service)
def test_get_service(self):
service = self.project.services.get("pipelines-email")
self.assertIsInstance(service, ProjectService)
self.assertEqual(service.push_events, True)
assert isinstance(service, ProjectService)
assert service.push_events == True

@with_httmock(resp_get_service, resp_update_service)
def test_update_service(self):
service = self.project.services.get("pipelines-email")
service.issues_events = True
service.save()
self.assertEqual(service.issues_events, True)
assert service.issues_events == True


class TestProjectPipelineSchedule(TestProject):
Expand Down

0 comments on commit 11383e7

Please sign in to comment.