-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathtest_bulk_imports.py
More file actions
153 lines (126 loc) · 4.28 KB
/
test_bulk_imports.py
File metadata and controls
153 lines (126 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
GitLab API: https://docs.gitlab.com/ce/api/bulk_imports.html
"""
import pytest
import responses
from gitlab.v4.objects import BulkImport, BulkImportAllEntity, BulkImportEntity
migration_content = {
"id": 1,
"status": "finished",
"source_type": "gitlab",
"created_at": "2021-06-18T09:45:55.358Z",
"updated_at": "2021-06-18T09:46:27.003Z",
}
entity_content = {
"id": 1,
"bulk_import_id": 1,
"status": "finished",
"source_full_path": "source_group",
"destination_slug": "destination_slug",
"destination_namespace": "destination_path",
"parent_id": None,
"namespace_id": 1,
"project_id": None,
"created_at": "2021-06-18T09:47:37.390Z",
"updated_at": "2021-06-18T09:47:51.867Z",
"failures": [],
}
@pytest.fixture
def resp_create_bulk_import():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.POST,
url="http://localhost/api/v4/bulk_imports",
json=migration_content,
content_type="application/json",
status=201,
)
yield rsps
@pytest.fixture
def resp_list_bulk_imports():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/bulk_imports",
json=[migration_content],
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_get_bulk_import():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/bulk_imports/1",
json=migration_content,
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_list_all_bulk_import_entities():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/bulk_imports/entities",
json=[entity_content],
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_list_bulk_import_entities():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/bulk_imports/1/entities",
json=[entity_content],
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_get_bulk_import_entity():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/bulk_imports/1/entities/1",
json=entity_content,
content_type="application/json",
status=200,
)
yield rsps
def test_create_bulk_import(gl, resp_create_bulk_import):
configuration = {"url": gl.url, "access_token": "test-token"}
migration_entity = {
"source_full_path": "source",
"source_type": "group_entity",
"destination_slug": "destination",
"destination_namespace": "destination",
}
migration = gl.bulk_imports.create(
{"configuration": configuration, "entities": [migration_entity]}
)
assert isinstance(migration, BulkImport)
assert migration.status == "finished"
def test_list_bulk_imports(gl, resp_list_bulk_imports):
migrations = gl.bulk_imports.list()
assert isinstance(migrations[0], BulkImport)
assert migrations[0].status == "finished"
def test_get_bulk_import(gl, resp_get_bulk_import):
migration = gl.bulk_imports.get(1)
assert isinstance(migration, BulkImport)
assert migration.status == "finished"
def test_list_all_bulk_import_entities(gl, resp_list_all_bulk_import_entities):
entities = gl.bulk_import_entities.list()
assert isinstance(entities[0], BulkImportAllEntity)
assert entities[0].bulk_import_id == 1
def test_list_bulk_import_entities(gl, migration, resp_list_bulk_import_entities):
entities = migration.entities.list()
assert isinstance(entities[0], BulkImportEntity)
assert entities[0].bulk_import_id == 1
def test_get_bulk_import_entity(gl, migration, resp_get_bulk_import_entity):
entity = migration.entities.get(1)
assert isinstance(entity, BulkImportEntity)
assert entity.bulk_import_id == 1