|
| 1 | +""" |
| 2 | +GitLab API: https://docs.gitlab.com/ce/api/bulk_imports.html |
| 3 | +""" |
| 4 | + |
| 5 | +importpytest |
| 6 | +importresponses |
| 7 | + |
| 8 | +fromgitlab.v4.objectsimportBulkImport,BulkImportAllEntity,BulkImportEntity |
| 9 | + |
| 10 | +migration_content= { |
| 11 | +"id":1, |
| 12 | +"status":"finished", |
| 13 | +"source_type":"gitlab", |
| 14 | +"created_at":"2021-06-18T09:45:55.358Z", |
| 15 | +"updated_at":"2021-06-18T09:46:27.003Z", |
| 16 | +} |
| 17 | +entity_content= { |
| 18 | +"id":1, |
| 19 | +"bulk_import_id":1, |
| 20 | +"status":"finished", |
| 21 | +"source_full_path":"source_group", |
| 22 | +"destination_slug":"destination_slug", |
| 23 | +"destination_namespace":"destination_path", |
| 24 | +"parent_id":None, |
| 25 | +"namespace_id":1, |
| 26 | +"project_id":None, |
| 27 | +"created_at":"2021-06-18T09:47:37.390Z", |
| 28 | +"updated_at":"2021-06-18T09:47:51.867Z", |
| 29 | +"failures": [], |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +@pytest.fixture |
| 34 | +defresp_create_bulk_import(): |
| 35 | +withresponses.RequestsMock()asrsps: |
| 36 | +rsps.add( |
| 37 | +method=responses.POST, |
| 38 | +url="http://localhost/api/v4/bulk_imports", |
| 39 | +json=migration_content, |
| 40 | +content_type="application/json", |
| 41 | +status=201, |
| 42 | + ) |
| 43 | +yieldrsps |
| 44 | + |
| 45 | + |
| 46 | +@pytest.fixture |
| 47 | +defresp_list_bulk_imports(): |
| 48 | +withresponses.RequestsMock()asrsps: |
| 49 | +rsps.add( |
| 50 | +method=responses.GET, |
| 51 | +url="http://localhost/api/v4/bulk_imports", |
| 52 | +json=[migration_content], |
| 53 | +content_type="application/json", |
| 54 | +status=200, |
| 55 | + ) |
| 56 | +yieldrsps |
| 57 | + |
| 58 | + |
| 59 | +@pytest.fixture |
| 60 | +defresp_get_bulk_import(): |
| 61 | +withresponses.RequestsMock()asrsps: |
| 62 | +rsps.add( |
| 63 | +method=responses.GET, |
| 64 | +url="http://localhost/api/v4/bulk_imports/1", |
| 65 | +json=migration_content, |
| 66 | +content_type="application/json", |
| 67 | +status=200, |
| 68 | + ) |
| 69 | +yieldrsps |
| 70 | + |
| 71 | + |
| 72 | +@pytest.fixture |
| 73 | +defresp_list_all_bulk_import_entities(): |
| 74 | +withresponses.RequestsMock()asrsps: |
| 75 | +rsps.add( |
| 76 | +method=responses.GET, |
| 77 | +url="http://localhost/api/v4/bulk_imports/entities", |
| 78 | +json=[entity_content], |
| 79 | +content_type="application/json", |
| 80 | +status=200, |
| 81 | + ) |
| 82 | +yieldrsps |
| 83 | + |
| 84 | + |
| 85 | +@pytest.fixture |
| 86 | +defresp_list_bulk_import_entities(): |
| 87 | +withresponses.RequestsMock()asrsps: |
| 88 | +rsps.add( |
| 89 | +method=responses.GET, |
| 90 | +url="http://localhost/api/v4/bulk_imports/1/entities", |
| 91 | +json=[entity_content], |
| 92 | +content_type="application/json", |
| 93 | +status=200, |
| 94 | + ) |
| 95 | +yieldrsps |
| 96 | + |
| 97 | + |
| 98 | +@pytest.fixture |
| 99 | +defresp_get_bulk_import_entity(): |
| 100 | +withresponses.RequestsMock()asrsps: |
| 101 | +rsps.add( |
| 102 | +method=responses.GET, |
| 103 | +url="http://localhost/api/v4/bulk_imports/1/entities/1", |
| 104 | +json=entity_content, |
| 105 | +content_type="application/json", |
| 106 | +status=200, |
| 107 | + ) |
| 108 | +yieldrsps |
| 109 | + |
| 110 | + |
| 111 | +deftest_create_bulk_import(gl,resp_create_bulk_import): |
| 112 | +configuration= { |
| 113 | +"url":gl.url, |
| 114 | +"access_token":"test-token", |
| 115 | + } |
| 116 | +migration_entity= { |
| 117 | +"source_full_path":"source", |
| 118 | +"source_type":"group_entity", |
| 119 | +"destination_slug":"destination", |
| 120 | +"destination_namespace":"destination", |
| 121 | + } |
| 122 | +migration=gl.bulk_imports.create( |
| 123 | + { |
| 124 | +"configuration":configuration, |
| 125 | +"entities": [migration_entity], |
| 126 | + } |
| 127 | + ) |
| 128 | +assertisinstance(migration,BulkImport) |
| 129 | +assertmigration.status=="finished" |
| 130 | + |
| 131 | + |
| 132 | +deftest_list_bulk_imports(gl,resp_list_bulk_imports): |
| 133 | +migrations=gl.bulk_imports.list() |
| 134 | +assertisinstance(migrations[0],BulkImport) |
| 135 | +assertmigrations[0].status=="finished" |
| 136 | + |
| 137 | + |
| 138 | +deftest_get_bulk_import(gl,resp_get_bulk_import): |
| 139 | +migration=gl.bulk_imports.get(1) |
| 140 | +assertisinstance(migration,BulkImport) |
| 141 | +assertmigration.status=="finished" |
| 142 | + |
| 143 | + |
| 144 | +deftest_list_all_bulk_import_entities(gl,resp_list_all_bulk_import_entities): |
| 145 | +entities=gl.bulk_import_entities.list() |
| 146 | +assertisinstance(entities[0],BulkImportAllEntity) |
| 147 | +assertentities[0].bulk_import_id==1 |
| 148 | + |
| 149 | + |
| 150 | +deftest_list_bulk_import_entities(gl,migration,resp_list_bulk_import_entities): |
| 151 | +entities=migration.entities.list() |
| 152 | +assertisinstance(entities[0],BulkImportEntity) |
| 153 | +assertentities[0].bulk_import_id==1 |
| 154 | + |
| 155 | + |
| 156 | +deftest_get_bulk_import_entity(gl,migration,resp_get_bulk_import_entity): |
| 157 | +entity=migration.entities.get(1) |
| 158 | +assertisinstance(entity,BulkImportEntity) |
| 159 | +assertentity.bulk_import_id==1 |