1
1
from datetime import timedelta
2
+ import re
2
3
from playwright .sync_api import Page , expect
3
4
from typing import Any , Dict , List
4
5
from utils import (
5
6
cleanup_backups ,
6
7
create_backup ,
7
8
extract_table_data ,
9
+ mock_window_open ,
8
10
)
9
11
10
12
@@ -61,7 +63,8 @@ def test_creates_backup(page: Page):
61
63
cleanup_backups ()
62
64
page .goto ("http://localhost:8080" )
63
65
page .get_by_role ("button" , name = "Backup" ).click ()
64
- expect (page .get_by_role ("status" ).filter (has_text = "Backup created" )).to_be_visible ()
66
+ expect (page .get_by_role ("status" ).filter (
67
+ has_text = "Backup created" )).to_be_visible ()
65
68
page .get_by_text ("db1" ).click ()
66
69
table_data = list_without_keys (
67
70
extract_table_data (page .locator (":text('Backups') + table" )),
@@ -83,7 +86,8 @@ def test_creates_backup_with_retention(page: Page):
83
86
retention_period_input = page .get_by_label ("Retention period" )
84
87
retention_period_input .fill ("7" )
85
88
page .get_by_role ("button" , name = "Backup" ).click ()
86
- expect (page .get_by_role ("status" ).filter (has_text = "Backup created" )).to_be_visible ()
89
+ expect (page .get_by_role ("status" ).filter (
90
+ has_text = "Backup created" )).to_be_visible ()
87
91
page .get_by_text ("db1" ).click ()
88
92
table_data = list_without_keys (
89
93
extract_table_data (page .locator (":text('Backups') + table" )),
@@ -155,3 +159,51 @@ def test_cleans_up_outdated_backups(page: Page):
155
159
"Retention" : "31 days" ,
156
160
},
157
161
]
162
+
163
+
164
+ def test_downloads_backup_archive (page : Page ):
165
+ cleanup_backups ()
166
+ page .goto ("http://localhost:8080" )
167
+ page .get_by_role ("button" , name = "Backup" ).click ()
168
+ expect (page .get_by_role ("status" ).filter (
169
+ has_text = "Backup created" )).to_be_visible ()
170
+ page .get_by_text ("db1" ).click ()
171
+ page .locator (":text('Backups') + table" ).get_by_text ("1 day" ).click ()
172
+
173
+ mock_window_open (page )
174
+
175
+ with page .expect_download () as download_info :
176
+ page .get_by_role ("button" , name = "Download archive" ).click ()
177
+
178
+ assert re .match (
179
+ r"https://localhost:8081/devstoreaccount1/backups/db1%2F.*-.*.9.1.pgdump" , download_info .value .url
180
+ )
181
+
182
+ def test_downloads_backup_plain (page : Page ):
183
+ cleanup_backups ()
184
+ page .goto ("http://localhost:8080" )
185
+ page .get_by_role ("button" , name = "Backup" ).click ()
186
+ expect (page .get_by_role ("status" ).filter (
187
+ has_text = "Backup created" )).to_be_visible ()
188
+ page .get_by_text ("db1" ).click ()
189
+ page .locator (":text('Backups') + table" ).get_by_text ("1 day" ).click ()
190
+
191
+ mock_window_open (page )
192
+
193
+ with page .expect_download () as download_info :
194
+ page .get_by_role ("button" , name = "Download plain dump" ).click ()
195
+
196
+ assert re .match (
197
+ r"https://localhost:8081/devstoreaccount1/backups/db1%2F.*-.*.9.1.sql" , download_info .value .url
198
+ )
199
+
200
+ response = page .request .get (download_info .value .url )
201
+ assert response .status == 200
202
+ assert "CREATE SCHEMA test1" in response .text ()
203
+ assert "COPY test1.fruites (name) FROM stdin" in response .text ()
204
+ assert "Apple" in response .text ()
205
+ assert "Orange" in response .text ()
206
+ assert "Banana" in response .text ()
207
+ assert "Rasberry" in response .text ()
208
+
209
+
0 commit comments