def test_generate_should_replace_name_multiple_files(self): template = Template(self.template, self.output_uri, self.tag_replacers) template2 = Template(self.template, self.output_uri2, self.tag_replacers2) generator = FileGenerator([template, template2]) generator.generate() result = FileIO.read(self.output_uri) result2 = FileIO.read(self.output_uri2) self.assert_all_placeholders_are_replaced(result, self.tag_replacers) self.assert_all_placeholders_are_replaced(result2, self.tag_replacers2)
def test_generate_should_not_override_file(self): template = Template(self.template, self.output_uri, self.tag_replacers) FileIO.write(self.output_uri, "test") generator = FileGenerator([template]) generator.generate() result = FileIO.read(self.output_uri) assert_that(result).is_equal_to("test")
def test_create_searchable(self): uri_fac = WaWiUriFactory(values.default_base_uri) fac = TemplateFactory(TemplateType.SEARCHABLE, values.default_base_uri) default_replacers = values.default_replacers("ProductElementPrice", "ERP") expected = [ Template( uri_fac.searchable_controller("ERP", "ProductElementPrice")[0], uri_fac.searchable_controller("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.i_searchable_controller("ERP", "ProductElementPrice")[0], uri_fac.i_searchable_controller("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.test_controller("ERP", "ProductElementPrice")[0], uri_fac.test_controller("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.searchable_repo("ERP", "ProductElementPrice")[0], uri_fac.searchable_repo("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.i_searchable_repo("ERP", "ProductElementPrice")[0], uri_fac.i_searchable_repo("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.test_repository("ERP", "ProductElementPrice")[0], uri_fac.test_repository("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.searchable_api_controller("ERP", "ProductElementPrice")[0], uri_fac.searchable_api_controller("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.test_api_controller("ERP", "ProductElementPrice")[0], uri_fac.test_api_controller("ERP", "ProductElementPrice")[1], default_replacers), ] result = fac.create("ERP", "ProductElementPrice") for i, j in zip(expected, result): assert_that(i).is_equal_to(j)
def test_create_crud(self): uri_fac = WaWiUriFactory(values.default_base_uri) fac = TemplateFactory(TemplateType.CRUD, values.default_base_uri) default_replacers = values.default_replacers("ProductElementPrice", "ERP") expected = [ Template( uri_fac.controller("ERP", "ProductElementPrice")[0], uri_fac.controller("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.i_controller("ERP", "ProductElementPrice")[0], uri_fac.i_controller("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.test_controller("ERP", "ProductElementPrice")[0], uri_fac.test_controller("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.repo("ERP", "ProductElementPrice")[0], uri_fac.repo("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.i_repo("ERP", "ProductElementPrice")[0], uri_fac.i_repo("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.test_repository("ERP", "ProductElementPrice")[0], uri_fac.test_repository("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.api_controller("ERP", "ProductElementPrice")[0], uri_fac.api_controller("ERP", "ProductElementPrice")[1], default_replacers), Template( uri_fac.test_api_controller("ERP", "ProductElementPrice")[0], uri_fac.test_api_controller("ERP", "ProductElementPrice")[1], default_replacers), ] assert_that(fac.create("ERP", "ProductElementPrice")).is_equal_to(expected)
def test_template_str(self): template = Template("someUri", "someOutput", {"some": "replacers"}) assert_that(template.__str__()).is_equal_to( "someUri, someOutput, {'some': 'replacers'}")
def test_template_equ(self): template = Template("someUri", "someOutput", {"some": "replacers"}) template2: object = object assert_that(template).is_not_equal_to(template2)
def test_generate_should_raise_error_if_template_not_exists(self): template = Template("wronguri", self.output_uri, self.tag_replacers) FileIO.write(self.output_uri, "test") generator = FileGenerator([template]) with self.assertRaises(FileNotFoundError): generator.generate()
def test_generate_should_replace_all_tag_replacers(self): template = Template(self.template, self.output_uri, self.tag_replacers) generator = FileGenerator([template]) generator.generate() result = FileIO.read(self.output_uri) self.assert_all_placeholders_are_replaced(result, self.tag_replacers)