|
1 | 1 | import json |
| 2 | +import uuid |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from django.urls import reverse |
@@ -123,6 +124,58 @@ def test_nodes_move(self): |
123 | 124 | assert response.status_code == 200, response.data |
124 | 125 |
|
125 | 126 |
|
| 127 | +@pytest.mark.django_db(transaction=True) |
| 128 | +def test_create_document_with_custom_id(auth_api_client: AuthTestClient): |
| 129 | + """ |
| 130 | + Allow custom ID attribute: if ID attribute is set, then node will set it |
| 131 | + as its ID. |
| 132 | + """ |
| 133 | + assert Document.objects.count() == 0 |
| 134 | + |
| 135 | + user = auth_api_client.user |
| 136 | + |
| 137 | + custom_id = uuid.uuid4() |
| 138 | + |
| 139 | + payload = dict( |
| 140 | + id=str(custom_id), |
| 141 | + ctype='document', |
| 142 | + # "lang" attribute is not set |
| 143 | + title='doc1.pdf', |
| 144 | + parent_id=str(user.home_folder.pk) |
| 145 | + ) |
| 146 | + |
| 147 | + response = auth_api_client.post('/nodes', json=payload) |
| 148 | + |
| 149 | + assert response.status_code == 201, response.content |
| 150 | + assert Document.objects.count() == 1 |
| 151 | + doc = Document.objects.first() |
| 152 | + assert doc.id == custom_id |
| 153 | + |
| 154 | + |
| 155 | +@pytest.mark.django_db(transaction=True) |
| 156 | +def test_create_folder_with_custom_id(auth_api_client: AuthTestClient): |
| 157 | + """ |
| 158 | + Allow custom ID attribute: if ID attribute is set, then node will set it |
| 159 | + as its ID. |
| 160 | + """ |
| 161 | + user = auth_api_client.user |
| 162 | + |
| 163 | + custom_id = uuid.uuid4() |
| 164 | + |
| 165 | + payload = dict( |
| 166 | + id=str(custom_id), |
| 167 | + ctype='folder', |
| 168 | + title='My Documents', |
| 169 | + parent_id=str(user.home_folder.pk) |
| 170 | + ) |
| 171 | + |
| 172 | + response = auth_api_client.post('/nodes', json=payload) |
| 173 | + folder = Folder.objects.get(title='My Documents') |
| 174 | + |
| 175 | + assert response.status_code == 201, response.content |
| 176 | + assert folder.id == custom_id |
| 177 | + |
| 178 | + |
126 | 179 | @pytest.mark.django_db(transaction=True) |
127 | 180 | def test_create_document(auth_api_client: AuthTestClient): |
128 | 181 | """ |
|
0 commit comments