|
1 | 1 | import pytest |
2 | 2 | from time import sleep |
3 | 3 |
|
| 4 | +from django.urls import resolve |
| 5 | + |
4 | 6 | from testapp.models import Book |
5 | 7 |
|
6 | 8 |
|
@@ -219,3 +221,33 @@ def test_move_next_page(adminpage, slug, p, o, direction): |
219 | 221 | assert book.my_order == 25 + index |
220 | 222 | else: |
221 | 223 | assert book.my_order == Book.objects.count() - 24 - index |
| 224 | + |
| 225 | + |
| 226 | +@pytest.mark.parametrize('slug, p, o', slugs) |
| 227 | +def test_drag_then_delete(adminpage, slug, p, o, direction, update_url): |
| 228 | + if o == 2: |
| 229 | + return |
| 230 | + table_locator = adminpage.locator('table#result_list') |
| 231 | + drag_handle = table_locator.locator('tbody tr:nth-child(9) div.drag.handle') |
| 232 | + with adminpage.expect_response(update_url) as response_info: |
| 233 | + drag_handle.drag_to(table_locator.locator('tbody tr:nth-child(3)')) |
| 234 | + while not (response := response_info.value): |
| 235 | + sleep(0.1) |
| 236 | + assert response.ok |
| 237 | + table_row = table_locator.locator('tbody tr:nth-child(2)') |
| 238 | + action_checkbox = table_row.locator('td.action-checkbox input[type="checkbox"]') |
| 239 | + detail_anchor = table_row.locator('th.field-title a[href]') |
| 240 | + change_url = detail_anchor.get_attribute('href') |
| 241 | + if '?' in change_url: |
| 242 | + change_url = change_url[:change_url.index('?')] |
| 243 | + book = Book.objects.get(id=resolve(change_url).kwargs['object_id']) |
| 244 | + action_checkbox.click() |
| 245 | + action_select = adminpage.locator('#changelist-form select[name="action"]') |
| 246 | + action_select.select_option('delete_selected') |
| 247 | + with adminpage.expect_response(adminpage.url) as response_info: |
| 248 | + adminpage.locator('#changelist-form button[name="index"]').click() |
| 249 | + assert response_info.value.ok |
| 250 | + html_response = response_info.value.text() |
| 251 | + assert f'<a href="{change_url}">{book.title}</a>' in html_response |
| 252 | + for chapter in book.chapter_set.all(): |
| 253 | + assert f'<li>Chapter: {chapter}</li>' in html_response |
0 commit comments