def test_json_content_correct(self): xmlproc = XmlProcessor(test_data_path).convert_to_dict() self.replace_values(xmlproc) xmlproc.save_as_json(upd_test_data_path) with open(get_abs_path(control_upd_json_path)) as f: control_js = json.load(f) with open(get_abs_path(upd_test_data_path)) as f: test_js = json.load(f) result = diff(control_js, test_js) assert list( result ) == [], "Should be no differences between XmlProcessor output and control json"
def test_json_file_created(self): XmlProcessor(test_data_path) \ .convert_to_dict() \ .save_as_json(upd_test_data_path) js_file = Path(get_abs_path(upd_test_data_path)) assert js_file.is_file()
def test_loaded_xml_equal_expected(self): xml_as_dict = XmlProcessor(test_data_path) \ .convert_to_dict().get_as_dict() with open(get_abs_path(control_orig_json_path)) as f: orig_js = json.load(f) result = diff(xml_as_dict, orig_js) assert list( result ) == [], "Should be no differences between XmlProcessor output dict and control json"
def save_as_json(self, path): as_js = json.dumps(self.document) with open(get_abs_path(path), "w") as fd: fd.write(as_js)
def convert_to_dict(self): full_path = get_abs_path(self.filename) with open(full_path) as fd: self.document = xmltodict.parse(fd.read()) return self
def test_input_xml_exists(self): upd_test_data = Path(get_abs_path(test_data_path)) assert upd_test_data.is_file(), "Test xml file should be existing"
def setup_method(self, method): upd_test_data = Path(get_abs_path(upd_test_data_path)) if upd_test_data.is_file(): upd_test_data.unlink()