|
1 | 1 | """
|
2 | 2 | GitLab API: https://docs.gitlab.com/ee/api/container_registry.html
|
3 | 3 | """
|
| 4 | +import re |
| 5 | + |
4 | 6 | import pytest
|
5 | 7 | import responses
|
6 | 8 |
|
7 |
| -from gitlab.v4.objects import ProjectRegistryRepository |
| 9 | +from gitlab.v4.objects import ProjectRegistryRepository, RegistryRepository |
8 | 10 |
|
9 | 11 | repositories_content = [
|
10 | 12 | {
|
|
29 | 31 |
|
30 | 32 |
|
31 | 33 | @pytest.fixture
|
32 |
| -def resp_group_registry_repositories(): |
| 34 | +def resp_list_registry_repositories(): |
33 | 35 | with responses.RequestsMock() as rsps:
|
34 | 36 | rsps.add(
|
35 | 37 | method=responses.GET,
|
36 |
| - url="http://localhost/api/v4/groups/1/registry/repositories", |
| 38 | + url=re.compile( |
| 39 | + r"http://localhost/api/v4/(groups|projects)/1/registry/repositories" |
| 40 | + ), |
37 | 41 | json=repositories_content,
|
38 | 42 | content_type="application/json",
|
39 | 43 | status=200,
|
40 | 44 | )
|
41 | 45 | yield rsps
|
42 | 46 |
|
43 | 47 |
|
44 |
| -def test_list_group_registry_repositories(group, resp_group_registry_repositories): |
| 48 | +@pytest.fixture |
| 49 | +def resp_get_registry_repository(): |
| 50 | + with responses.RequestsMock() as rsps: |
| 51 | + rsps.add( |
| 52 | + method=responses.GET, |
| 53 | + url="http://localhost/api/v4/registry/repositories/1", |
| 54 | + json=repositories_content[0], |
| 55 | + content_type="application/json", |
| 56 | + status=200, |
| 57 | + ) |
| 58 | + yield rsps |
| 59 | + |
| 60 | + |
| 61 | +@pytest.fixture |
| 62 | +def resp_delete_registry_repository(no_content): |
| 63 | + with responses.RequestsMock() as rsps: |
| 64 | + rsps.add( |
| 65 | + method=responses.DELETE, |
| 66 | + url="http://localhost/api/v4/projects/1/registry/repositories/1", |
| 67 | + json=no_content, |
| 68 | + content_type="application/json", |
| 69 | + status=204, |
| 70 | + ) |
| 71 | + yield rsps |
| 72 | + |
| 73 | + |
| 74 | +def test_list_group_registry_repositories(group, resp_list_registry_repositories): |
45 | 75 | repositories = group.registry_repositories.list()
|
46 | 76 | assert isinstance(repositories[0], ProjectRegistryRepository)
|
47 | 77 | assert repositories[0].id == 1
|
| 78 | + |
| 79 | + |
| 80 | +def test_list_project_registry_repositories(project, resp_list_registry_repositories): |
| 81 | + repositories = project.repositories.list() |
| 82 | + assert isinstance(repositories[0], ProjectRegistryRepository) |
| 83 | + assert repositories[0].id == 1 |
| 84 | + |
| 85 | + |
| 86 | +def test_delete_project_registry_repository(project, resp_delete_registry_repository): |
| 87 | + project.repositories.delete(1) |
| 88 | + |
| 89 | + |
| 90 | +def test_get_registry_repository(gl, resp_get_registry_repository): |
| 91 | + repository = gl.registry_repositories.get(1) |
| 92 | + assert isinstance(repository, RegistryRepository) |
| 93 | + assert repository.id == 1 |
0 commit comments