From c79edbfc84a06df9216e3c4a7ea0272affaa7937 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Tue, 9 Jun 2020 10:46:36 +0200 Subject: [PATCH] tests: backup: Even more! Now with deletion of tested tmp! Now we also test for everything in backup.py! EVERYTHING! We even delete the old file that we ourselfs created to test the export/backup function. --- private/test/test_backup.py | 33 +++++++++++++++++++-------------- private/test/testcfg.py | 4 ++++ 2 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 private/test/testcfg.py diff --git a/private/test/test_backup.py b/private/test/test_backup.py index 757e1d4..fa45141 100644 --- a/private/test/test_backup.py +++ b/private/test/test_backup.py @@ -1,32 +1,33 @@ -import sys - -sys.path.append('..') - +import os import unittest -from ListUsers import ListUsers +import sys +import csv import backup - +sys.path.append('..') +from lib.ListUsers import ListUsers +import test.testcfg as testcfg class TestBackup(unittest.TestCase): - test_csv: str = "test/testbackup.csv" - test_db: str = "./test/applications.sqlite" def setUp(self): try: - self.fetch = ListUsers(self.test_db, unapproved=False, approved=False).get_fetch() - self.Backup = backup.Backup(self.test_csv) + self.fetch = ListUsers(testcfg.test_db, unapproved=False, approved=False).get_fetch() + self.Backup = backup.Backup(testcfg.test_backup_csv) except Exception as general_setup: self.fail(f"Failed setup already! {general_setup}") def test_set_dialect(self): - pass + self.Backup.set_dialect("excel") + self.assertEqual(self.Backup.dialect, "excel") def test_set_quoting(self): - pass + self.Backup.set_quoting(csv.QUOTE_NONNUMERIC) + self.assertEqual(self.Backup.quoting, csv.QUOTE_NONNUMERIC) def test_set_filename(self): - self.Backup.set_filename(self.test_csv) - self.assertEqual(self.Backup.filename, self.test_csv) + self.Backup.set_filename(testcfg.test_backup_csv) + self.assertEqual(self.Backup.filename, testcfg.test_backup_csv) + self.Backup.set_field_names(self.fetch[0].keys()) def test_set_field_names(self): # @TODO: Dynamic! Having a test scheme from which we setup our test is beneficial here, also values @@ -36,7 +37,11 @@ class TestBackup(unittest.TestCase): def test_backup_to_file(self): try: + self.Backup.set_field_names(self.fetch[0].keys()) self.Backup.backup_to_file(self.fetch) + self.assertTrue(os.path.exists(testcfg.test_backup_csv), + "Assert True that file exists and was written") + os.unlink(os.path.realpath(testcfg.test_backup_csv)) except IOError as io_error: self.fail(io_error) diff --git a/private/test/testcfg.py b/private/test/testcfg.py new file mode 100644 index 0000000..1fc8f5b --- /dev/null +++ b/private/test/testcfg.py @@ -0,0 +1,4 @@ +test_backup_csv: str = "test/testbackup.csv" +test_db: str = "./test/applications.sqlite" +ListUsers_fetch_size_min: int = 3 +ListUsers_output_newlines: int = 1 \ No newline at end of file