def __init__(self, superclass=None, override=False): """Initialize the global class, e.g., by storing run-time arguments and by retrieving and preparing the module's configuration file. Args: superclass: Full name of the global class's superclass, e.g., "Mage_Rss_Block_Abstract". override: Whether this global class should override its superclass. """ Class.__init__(self) self.superclass = self._infer_super(superclass) self.override = override self.type_tag = self.type + "s" self.config = self.get_config() self._prepare_config() self.xpath = "/config/global/" + self.type_tag self.type_elem = self.config.xpath(self.xpath)[0]
def __init__(self, front_name=None, override=False, superclass=None, router=None): """Initialize the controller, e.g., by storing run-time arguments. Args: front_name: The string to use as the module's frontName. By convention this string is the module's name, lower-cased. override: Whether the module's controller(s) should override the controller(s) of the module to which its superclass belongs. superclass: Full name of the controller's superclass, e.g., "Mage_Adminhtml_Controller_Action". router: Name of the front controller router to use. Available routers are "standard", "admin", and "default". """ Class.__init__(self) self.front_name = front_name or self.module.name.lower() self.override = override self.superclass = superclass or "Mage_Core_Controller_Front_Action" self.router = router or "standard"
class ClsTest(unittest.TestCase): def setUp(self): self.cwd = os.getcwd() os.chdir(TEST_DIR) os.mkdir("Class") self.cls = Class() def tearDown(self): os.rmdir("Class") os.chdir(self.cwd) del self.cls def test__fill_template(self): self.assertEqual(self.cls._fill_template("Hello", "World"), "Foo|Bar|Hello|World") def test__create_class1(self): class_string = "" name = "Baz" target = os.path.join("Class", name + ".php") self.cls._create_class(name, "World") with open(target) as class_file: for line in class_file: class_string += line self.assertEqual(class_string, "Foo|Bar|" + name + "|World") os.remove(target) def test__create_class2(self): class_string = "" name = "Quux_Qux" target = os.path.join("Class", "Quux", "Qux.php") self.cls._create_class(name, "World") with open(target) as class_file: for line in class_file: class_string += line self.assertEqual(class_string, "Foo|Bar|Quux_Qux|World") os.remove(target) os.rmdir(target[:target.rfind(os.sep)]) def test__words_to_dirs1(self): self.assertEqual(self.cls._words_to_dirs(TEST_DIR, "Product"), TEST_DIR) def test__words_to_dirs2(self): self.assertEqual(self.cls._words_to_dirs(TEST_DIR, "Abc_Def"), os.path.join(TEST_DIR, "Abc")) def test__words_to_dirs3(self): self.assertEqual(self.cls._words_to_dirs(TEST_DIR, "Abc_Def_Ghi"), os.path.join(TEST_DIR, "Abc", "Def")) def test__create_missing_dirs1(self): self.cls._create_missing_dirs(os.path.join("abc", "def", "ghi")) os.rmdir(os.path.join("abc", "def", "ghi")) os.rmdir(os.path.join("abc", "def")) os.rmdir("abc") def test__create_missing_dirs2(self): self.cls._create_missing_dirs(os.path.join(os.path.abspath(os.getcwd()), "abc", "def", "ghi")) os.rmdir(os.path.join("abc", "def", "ghi")) os.rmdir(os.path.join("abc", "def")) os.rmdir("abc") def test__prepare_path_to(self): self.assertEqual(self.cls._prepare_path_to("Product"), os.path.join(TEST_DIR, "Class", "Product.php"))
def setUp(self): self.cwd = os.getcwd() os.chdir(TEST_DIR) os.mkdir("Class") self.cls = Class()