Skip to content

Commit e46ae71

Browse files
committed
add test to downloads
1 parent 40a35e0 commit e46ae71

File tree

5 files changed

+88
-16
lines changed

5 files changed

+88
-16
lines changed

.vscode/launch.json

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
{
2-
"configurations": [
3-
{
4-
"type": "java",
5-
"name": "Spring Boot-App<postgres-azure-backup>",
6-
"request": "launch",
7-
"cwd": "${workspaceFolder}/server",
8-
"mainClass": "io.github.mucsi96.postgresbackuptool.App",
9-
"projectName": "postgres-azure-backup",
10-
"args": "",
11-
"envFile": "${workspaceFolder}/.env"
12-
}
13-
]
2+
"configurations": [
3+
{
4+
"type": "java",
5+
"name": "Spring Boot-App<postgres-azure-backup>",
6+
"request": "launch",
7+
"cwd": "${workspaceFolder}/server",
8+
"mainClass": "io.github.mucsi96.postgresbackuptool.App",
9+
"projectName": "postgres-azure-backup",
10+
"args": "",
11+
"envFile": "${workspaceFolder}/.env"
12+
},
13+
{
14+
"name": "Python: Unittest",
15+
"type": "debugpy",
16+
"request": "launch",
17+
"console": "integratedTerminal",
18+
"justMyCode": true
19+
}
20+
]
1421
}

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
- migrate to angular 19 and resource
22
- drop @mucsi96/ui-elements in favor of angular/material
3-
- add possibility to additionaly create plain dumps
4-
- show dump format on UI
53
- deploy backup job with help

client/src/app/backups/backups.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ <h2 bt>
4343
mat-icon-button
4444
(click)="downloadBackup({ type: 'archive' })"
4545
class="download"
46+
aria-label="Download archive"
4647
>
4748
<mat-icon>folder_zip</mat-icon>
4849
</button>
@@ -51,6 +52,7 @@ <h2 bt>
5152
mat-icon-button
5253
(click)="downloadBackup({ type: 'plain' })"
5354
class="download"
55+
aria-label="Download plain dump"
5456
>
5557
<mat-icon>description</mat-icon>
5658
</button>

test/test_backups.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from datetime import timedelta
2+
import re
23
from playwright.sync_api import Page, expect
34
from typing import Any, Dict, List
45
from utils import (
56
cleanup_backups,
67
create_backup,
78
extract_table_data,
9+
mock_window_open,
810
)
911

1012

@@ -61,7 +63,8 @@ def test_creates_backup(page: Page):
6163
cleanup_backups()
6264
page.goto("http://localhost:8080")
6365
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()
6568
page.get_by_text("db1").click()
6669
table_data = list_without_keys(
6770
extract_table_data(page.locator(":text('Backups') + table")),
@@ -83,7 +86,8 @@ def test_creates_backup_with_retention(page: Page):
8386
retention_period_input = page.get_by_label("Retention period")
8487
retention_period_input.fill("7")
8588
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()
8791
page.get_by_text("db1").click()
8892
table_data = list_without_keys(
8993
extract_table_data(page.locator(":text('Backups') + table")),
@@ -155,3 +159,51 @@ def test_cleans_up_outdated_backups(page: Page):
155159
"Retention": "31 days",
156160
},
157161
]
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+

test/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,16 @@ def get_db1_tables():
176176
tables = [table[0] for table in cur1.fetchall()]
177177
cur1.close()
178178
return tables
179+
180+
181+
def mock_window_open(page):
182+
page.evaluate(
183+
"""
184+
window.open = (url) => {
185+
if (url && url.startsWith("https://blobstorage:10000")) {
186+
url = url.replace("https://blobstorage:10000", "https://localhost:8081");
187+
window.location.href = url;
188+
}
189+
};
190+
"""
191+
)

0 commit comments

Comments
 (0)