|
@@ -0,0 +1,122 @@
|
|
|
+from CloneXls import ChangeLog
|
|
|
+import CloneXls
|
|
|
+import os
|
|
|
+from pathlib import Path
|
|
|
+from openpyxl import load_workbook
|
|
|
+import string
|
|
|
+import random
|
|
|
+import sys
|
|
|
+
|
|
|
+myPath = os.path.dirname(os.path.abspath(__file__))
|
|
|
+sys.path.insert(0, myPath + '/../')
|
|
|
+
|
|
|
+input_directory = "tests/TestInput/"
|
|
|
+original_file = "CompleteBaangtWebdemo.xlsx"
|
|
|
+input_file = "CompleteBaangtWebdemo1.xlsx"
|
|
|
+output_file = "CompleteBaangtWebdemo1_baangt.xlsx"
|
|
|
+new_prefix = "_test"
|
|
|
+output_file_2 = "CompleteBaangtWebdemo1_test.xlsx"
|
|
|
+sheet = "data"
|
|
|
+ignore_headers = ["password", "Country"]
|
|
|
+ignore_sheets = ["TestStepExecution"]
|
|
|
+
|
|
|
+with open(Path(input_directory).joinpath(original_file), "rb") as file:
|
|
|
+ data = file.read()
|
|
|
+
|
|
|
+with open(Path(input_directory).joinpath(input_file), "wb") as file:
|
|
|
+ file.write(data)
|
|
|
+
|
|
|
+
|
|
|
+def update_source(path):
|
|
|
+ wb = load_workbook(path)
|
|
|
+ sht = wb.get_sheet_by_name(sheet)
|
|
|
+ for row in range(1, sht.max_row+1):
|
|
|
+ sht.cell(row, 9).value = None
|
|
|
+ sht.cell(1, 9).value = ''.join(random.choices(string.ascii_uppercase + string.digits, k=5))
|
|
|
+ sht.cell(2, 9).value = ''.join(random.choices(string.ascii_uppercase + string.digits, k=5))
|
|
|
+ sht.cell(5, 9).value = ''.join(random.choices(string.ascii_uppercase + string.digits, k=5))
|
|
|
+ sht.cell(8, 3).value = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
|
|
|
+ wb.save(path)
|
|
|
+
|
|
|
+
|
|
|
+def check_source(path, ignore=False):
|
|
|
+ wb = load_workbook(path)
|
|
|
+ sht = wb.get_sheet_by_name("Change Logs")
|
|
|
+ if not ignore:
|
|
|
+ assert int(sht.cell(2, 4).value) == 1
|
|
|
+ assert int(sht.cell(3, 4).value) == 1
|
|
|
+ assert int(sht.cell(4, 4).value) == 8
|
|
|
+ assert sht.max_row == 4
|
|
|
+ else:
|
|
|
+ assert int(sht.cell(2, 4).value) == 1
|
|
|
+ assert int(sht.cell(3, 4).value) == 8
|
|
|
+ assert sht.max_row == 3
|
|
|
+
|
|
|
+
|
|
|
+def test_check_source_file():
|
|
|
+ try:
|
|
|
+ CloneXls.CloneXls("tests/TestInput/CompleteBaangtWebdemo1.xlsx")
|
|
|
+ assert 1 == 0
|
|
|
+ except BaseException:
|
|
|
+ assert 1 == 1
|
|
|
+
|
|
|
+
|
|
|
+def test_update_or_make_clone():
|
|
|
+ output = str(Path(input_directory).joinpath(output_file))
|
|
|
+ input_ = str(Path(input_directory).joinpath(input_file))
|
|
|
+ if os.path.exists(output):
|
|
|
+ os.remove(output)
|
|
|
+ cloneXls = CloneXls.CloneXls(input_)
|
|
|
+ cloneXls.update_or_make_clone()
|
|
|
+ assert os.path.exists(output)
|
|
|
+
|
|
|
+
|
|
|
+def test_update_or_make_clone_prefix():
|
|
|
+ output = str(Path(input_directory).joinpath(output_file_2))
|
|
|
+ input = str(Path(input_directory).joinpath(input_file))
|
|
|
+ if os.path.exists(output):
|
|
|
+ os.remove(output)
|
|
|
+ cloneXls = CloneXls.CloneXls(input, new_prefix)
|
|
|
+ cloneXls.update_or_make_clone()
|
|
|
+ assert os.path.exists(output) and new_prefix in output
|
|
|
+ os.remove(output)
|
|
|
+
|
|
|
+
|
|
|
+def test_ChangeLog_class():
|
|
|
+ output = str(Path(input_directory).joinpath(output_file))
|
|
|
+ input_ = str(Path(input_directory).joinpath(input_file))
|
|
|
+ changeLog = ChangeLog(input_, output)
|
|
|
+ assert changeLog.ignore_sheets == ['change logs'] and changeLog.ignore_headers ==[]
|
|
|
+
|
|
|
+
|
|
|
+def test_ChangeLog_not_case_sensitive():
|
|
|
+ output = str(Path(input_directory).joinpath(output_file))
|
|
|
+ input_ = str(Path(input_directory).joinpath(input_file))
|
|
|
+ changeLog = ChangeLog(
|
|
|
+ input_, output, ignore_headers=ignore_headers, ignore_sheets=ignore_sheets
|
|
|
+ )
|
|
|
+ assert changeLog.ignore_headers[0].islower() and changeLog.ignore_headers[1].islower() and \
|
|
|
+ changeLog.ignore_sheets[0].islower()
|
|
|
+ update_source(input_)
|
|
|
+ changeLog.xlsxChangeLog()
|
|
|
+ check_source(output, ignore=True)
|
|
|
+
|
|
|
+
|
|
|
+def test_ChangeLog_case_sensitive():
|
|
|
+ output = str(Path(input_directory).joinpath(output_file))
|
|
|
+ input_ = str(Path(input_directory).joinpath(input_file))
|
|
|
+ os.remove(output)
|
|
|
+ cloneXls = CloneXls.CloneXls(input_)
|
|
|
+ cloneXls.update_or_make_clone()
|
|
|
+ changeLog = ChangeLog(
|
|
|
+ input_, output, ignore_headers=ignore_headers, ignore_sheets=ignore_sheets, case_sensitive_ignore=True
|
|
|
+ )
|
|
|
+ assert changeLog.ignore_headers[0].islower() and not changeLog.ignore_headers[1].islower() and \
|
|
|
+ not changeLog.ignore_sheets[0].islower()
|
|
|
+ update_source(input_)
|
|
|
+ changeLog.xlsxChangeLog()
|
|
|
+ changeLog.xlsxChangeLog()
|
|
|
+ check_source(output)
|
|
|
+ os.remove(input_)
|
|
|
+ os.remove(output)
|
|
|
+
|