Skip to content

Commit 191d5e3

Browse files
committed
tests: json format for show command
1 parent 8aa559b commit 191d5e3

File tree

12 files changed

+292
-181
lines changed

12 files changed

+292
-181
lines changed

tests/archive.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ def test_arhive_push_file_exists_overwrite(self):
427427
# @unittest.expectedFailure
428428
# @unittest.skip("skip")
429429
def test_replica_archive(self):
430-
"""make node without archiving, take stream backup and turn it into replica, set replica with archiving, make archive backup from replica"""
430+
"""
431+
make node without archiving, take stream backup and
432+
turn it into replica, set replica with archiving,
433+
make archive backup from replica
434+
"""
431435
fname = self.id().split('.')[3]
432436
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
433437
master = self.make_simple_node(
@@ -468,7 +472,9 @@ def test_replica_archive(self):
468472
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
469473
self.assertEqual(before, after)
470474

471-
# Change data on master, take FULL backup from replica, restore taken backup and check that restored data equal to original data
475+
# Change data on master, take FULL backup from replica,
476+
# restore taken backup and check that restored data equal
477+
# to original data
472478
master.psql(
473479
"postgres",
474480
"insert into t_heap as select i as id, md5(i::text) as text, "
@@ -502,7 +508,9 @@ def test_replica_archive(self):
502508
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
503509
self.assertEqual(before, after)
504510

505-
# Change data on master, make PAGE backup from replica, restore taken backup and check that restored data equal to original data
511+
# Change data on master, make PAGE backup from replica,
512+
# restore taken backup and check that restored data equal
513+
# to original data
506514
master.psql(
507515
"postgres",
508516
"insert into t_heap as select i as id, md5(i::text) as text, "

tests/backup_test.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@ def test_backup_modes_archive(self):
2929
self.set_archiving(backup_dir, 'node', node)
3030
node.start()
3131

32-
# full backup mode
33-
# with open(path.join(node.logs_dir, "backup_full.log"), "wb") as backup_log:
34-
# backup_log.write(self.backup_node(node, options=["--verbose"]))
35-
3632
backup_id = self.backup_node(backup_dir, 'node', node)
3733
show_backup = self.show_pb(backup_dir, 'node')[0]
3834

39-
self.assertEqual(show_backup['Status'], "OK")
40-
self.assertEqual(show_backup['Mode'], "FULL")
35+
self.assertEqual(show_backup['status'], "OK")
36+
self.assertEqual(show_backup['backup-mode'], "FULL")
4137

4238
# postmaster.pid and postmaster.opts shouldn't be copied
4339
excluded = True
@@ -61,29 +57,29 @@ def test_backup_modes_archive(self):
6157

6258
# print self.show_pb(node)
6359
show_backup = self.show_pb(backup_dir, 'node')[1]
64-
self.assertEqual(show_backup['Status'], "OK")
65-
self.assertEqual(show_backup['Mode'], "PAGE")
60+
self.assertEqual(show_backup['status'], "OK")
61+
self.assertEqual(show_backup['backup-mode'], "PAGE")
6662

6763
# Check parent backup
6864
self.assertEqual(
6965
backup_id,
7066
self.show_pb(
7167
backup_dir, 'node',
72-
backup_id=show_backup['ID'])["parent-backup-id"])
68+
backup_id=show_backup['id'])["parent-backup-id"])
7369

7470
# ptrack backup mode
7571
self.backup_node(backup_dir, 'node', node, backup_type="ptrack")
7672

7773
show_backup = self.show_pb(backup_dir, 'node')[2]
78-
self.assertEqual(show_backup['Status'], "OK")
79-
self.assertEqual(show_backup['Mode'], "PTRACK")
74+
self.assertEqual(show_backup['status'], "OK")
75+
self.assertEqual(show_backup['backup-mode'], "PTRACK")
8076

8177
# Check parent backup
8278
self.assertEqual(
8379
page_backup_id,
8480
self.show_pb(
8581
backup_dir, 'node',
86-
backup_id=show_backup['ID'])["parent-backup-id"])
82+
backup_id=show_backup['id'])["parent-backup-id"])
8783

8884
# Clean after yourself
8985
self.del_test_dir(module_name, fname)
@@ -106,7 +102,7 @@ def test_smooth_checkpoint(self):
106102
self.backup_node(
107103
backup_dir, 'node', node,
108104
options=["-C"])
109-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
105+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['status'], "OK")
110106
node.stop()
111107

112108
# Clean after yourself
@@ -162,7 +158,7 @@ def test_incremental_backup_without_full(self):
162158
repr(e.message), self.cmd))
163159

164160
self.assertEqual(
165-
self.show_pb(backup_dir, 'node')[0]['Status'],
161+
self.show_pb(backup_dir, 'node')[0]['status'],
166162
"ERROR")
167163

168164
# Clean after yourself
@@ -227,7 +223,7 @@ def test_incremental_backup_corrupt_full(self):
227223
self.assertEqual(
228224
self.show_pb(backup_dir, 'node', backup_id)['status'], "CORRUPT")
229225
self.assertEqual(
230-
self.show_pb(backup_dir, 'node')[1]['Status'], "ERROR")
226+
self.show_pb(backup_dir, 'node')[1]['status'], "ERROR")
231227

232228
# Clean after yourself
233229
self.del_test_dir(module_name, fname)
@@ -250,12 +246,12 @@ def test_ptrack_threads(self):
250246
self.backup_node(
251247
backup_dir, 'node', node,
252248
backup_type="full", options=["-j", "4"])
253-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
249+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['status'], "OK")
254250

255251
self.backup_node(
256252
backup_dir, 'node', node,
257253
backup_type="ptrack", options=["-j", "4"])
258-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
254+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['status'], "OK")
259255

260256
# Clean after yourself
261257
self.del_test_dir(module_name, fname)
@@ -282,11 +278,11 @@ def test_ptrack_threads_stream(self):
282278
backup_dir, 'node', node, backup_type="full",
283279
options=["-j", "4", "--stream"])
284280

285-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
281+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['status'], "OK")
286282
self.backup_node(
287283
backup_dir, 'node', node,
288284
backup_type="ptrack", options=["-j", "4", "--stream"])
289-
self.assertEqual(self.show_pb(backup_dir, 'node')[1]['Status'], "OK")
285+
self.assertEqual(self.show_pb(backup_dir, 'node')[1]['status'], "OK")
290286

291287
# Clean after yourself
292288
self.del_test_dir(module_name, fname)
@@ -342,7 +338,7 @@ def test_page_corruption_heal_via_ptrack_1(self):
342338
f.close
343339

344340
self.assertTrue(
345-
self.show_pb(backup_dir, 'node')[1]['Status'] == 'OK',
341+
self.show_pb(backup_dir, 'node')[1]['status'] == 'OK',
346342
"Backup Status should be OK")
347343

348344
# Clean after yourself
@@ -415,7 +411,7 @@ def test_page_corruption_heal_via_ptrack_2(self):
415411
repr(e.message), self.cmd))
416412

417413
self.assertTrue(
418-
self.show_pb(backup_dir, 'node')[1]['Status'] == 'ERROR',
414+
self.show_pb(backup_dir, 'node')[1]['status'] == 'ERROR',
419415
"Backup Status should be ERROR")
420416

421417
# Clean after yourself

tests/delete_test.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ def test_delete_full_backups(self):
4444
self.backup_node(backup_dir, 'node', node)
4545

4646
show_backups = self.show_pb(backup_dir, 'node')
47-
id_1 = show_backups[0]['ID']
48-
id_2 = show_backups[1]['ID']
49-
id_3 = show_backups[2]['ID']
47+
id_1 = show_backups[0]['id']
48+
id_2 = show_backups[1]['id']
49+
id_3 = show_backups[2]['id']
5050
self.delete_pb(backup_dir, 'node', id_2)
5151
show_backups = self.show_pb(backup_dir, 'node')
52-
self.assertEqual(show_backups[0]['ID'], id_1)
53-
self.assertEqual(show_backups[1]['ID'], id_3)
52+
self.assertEqual(show_backups[0]['id'], id_1)
53+
self.assertEqual(show_backups[1]['id'], id_3)
5454

5555
# Clean after yourself
5656
self.del_test_dir(module_name, fname)
@@ -82,15 +82,15 @@ def test_delete_increment_page(self):
8282
self.assertEqual(len(show_backups), 4)
8383

8484
# delete first page backup
85-
self.delete_pb(backup_dir, 'node', show_backups[1]['ID'])
85+
self.delete_pb(backup_dir, 'node', show_backups[1]['id'])
8686

8787
show_backups = self.show_pb(backup_dir, 'node')
8888
self.assertEqual(len(show_backups), 2)
8989

90-
self.assertEqual(show_backups[0]['Mode'], "FULL")
91-
self.assertEqual(show_backups[0]['Status'], "OK")
92-
self.assertEqual(show_backups[1]['Mode'], "FULL")
93-
self.assertEqual(show_backups[1]['Status'], "OK")
90+
self.assertEqual(show_backups[0]['backup-mode'], "FULL")
91+
self.assertEqual(show_backups[0]['status'], "OK")
92+
self.assertEqual(show_backups[1]['backup-mode'], "FULL")
93+
self.assertEqual(show_backups[1]['status'], "OK")
9494

9595
# Clean after yourself
9696
self.del_test_dir(module_name, fname)
@@ -122,15 +122,15 @@ def test_delete_increment_ptrack(self):
122122
self.assertEqual(len(show_backups), 4)
123123

124124
# delete first page backup
125-
self.delete_pb(backup_dir, 'node', show_backups[1]['ID'])
125+
self.delete_pb(backup_dir, 'node', show_backups[1]['id'])
126126

127127
show_backups = self.show_pb(backup_dir, 'node')
128128
self.assertEqual(len(show_backups), 2)
129129

130-
self.assertEqual(show_backups[0]['Mode'], "FULL")
131-
self.assertEqual(show_backups[0]['Status'], "OK")
132-
self.assertEqual(show_backups[1]['Mode'], "FULL")
133-
self.assertEqual(show_backups[1]['Status'], "OK")
130+
self.assertEqual(show_backups[0]['backup-mode'], "FULL")
131+
self.assertEqual(show_backups[0]['status'], "OK")
132+
self.assertEqual(show_backups[1]['backup-mode'], "FULL")
133+
self.assertEqual(show_backups[1]['status'], "OK")
134134

135135
# Clean after yourself
136136
self.del_test_dir(module_name, fname)

tests/delta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ def test_page_corruption_heal_via_ptrack_1(self):
11911191
f.close
11921192

11931193
self.assertTrue(
1194-
self.show_pb(backup_dir, 'node')[1]['Status'] == 'OK',
1194+
self.show_pb(backup_dir, 'node')[1]['status'] == 'OK',
11951195
"Backup Status should be OK")
11961196

11971197
# Clean after yourself
@@ -1264,7 +1264,7 @@ def test_page_corruption_heal_via_ptrack_2(self):
12641264
repr(e.message), self.cmd))
12651265

12661266
self.assertTrue(
1267-
self.show_pb(backup_dir, 'node')[1]['Status'] == 'ERROR',
1267+
self.show_pb(backup_dir, 'node')[1]['status'] == 'ERROR',
12681268
"Backup Status should be ERROR")
12691269

12701270
# Clean after yourself

tests/exclude.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,33 @@ def test_exclude_temp_tables(self):
3434
temp_schema_name = conn.execute("SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema()")[0][0]
3535
conn.commit()
3636

37-
temp_toast_schema_name = "pg_toast_" + temp_schema_name.replace("pg_", "")
37+
temp_toast_schema_name = "pg_toast_" + temp_schema_name.replace(
38+
"pg_", "")
3839
conn.commit()
3940

4041
conn.execute("create index test_idx on test (generate_series)")
4142
conn.commit()
4243

43-
heap_path = conn.execute("select pg_relation_filepath('test')")[0][0]
44+
heap_path = conn.execute(
45+
"select pg_relation_filepath('test')")[0][0]
4446
conn.commit()
4547

46-
index_path = conn.execute("select pg_relation_filepath('test_idx')")[0][0]
48+
index_path = conn.execute(
49+
"select pg_relation_filepath('test_idx')")[0][0]
4750
conn.commit()
4851

4952
heap_oid = conn.execute("select 'test'::regclass::oid")[0][0]
5053
conn.commit()
5154

52-
toast_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format(temp_toast_schema_name, "pg_toast_" + str(heap_oid)))[0][0]
55+
toast_path = conn.execute(
56+
"select pg_relation_filepath('{0}.{1}')".format(
57+
temp_toast_schema_name, "pg_toast_" + str(heap_oid)))[0][0]
5358
conn.commit()
5459

55-
toast_idx_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format(temp_toast_schema_name, "pg_toast_" + str(heap_oid) + "_index"))[0][0]
60+
toast_idx_path = conn.execute(
61+
"select pg_relation_filepath('{0}.{1}')".format(
62+
temp_toast_schema_name,
63+
"pg_toast_" + str(heap_oid) + "_index"))[0][0]
5664
conn.commit()
5765

5866
temp_table_filename = os.path.basename(heap_path)

0 commit comments

Comments
 (0)