Exemple #1
0
    def test_add_read(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_psql", self.path_dir)
        inst.set_database(
            "postgresql:name=" + self.data['dbname'] + ",user=puser,password=123456,host=localhost")
        inst.add()
        self.assertEqual(["inst_psql"], self.luct_glo.listing())

        inst = LucteriosInstance("inst_psql", self.path_dir)
        inst.read()
        self.assertEqual("postgresql", inst.database[0])
        self.assertEqual("localhost", inst.database[1]['host'])
        self.assertEqual(self._testMethodName, inst.database[1]['name'])
        self.assertEqual("123456", inst.database[1]['password'])
        self.assertEqual("puser", inst.database[1]['user'])
        self.assertEqual("lucterios.standard", inst.appli_name)
        self.assertEqual((), inst.modules)

        table_list = list(self.run_psql_cmd(
            "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'"))
        table_list = table_list[2:-2]
        table_list.sort()
        self.assertEqual(self.waiting_table, table_list)

        inst = LucteriosInstance("inst_psql", self.path_dir)
        inst.clear()
        table_list = list(self.run_psql_cmd(
            "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'"))
        table_list = table_list[2:-2]
        self.assertEqual([], table_list)

        inst = LucteriosInstance("inst_psql", self.path_dir)
        inst.delete()
        self.assertEqual([], self.luct_glo.listing())
Exemple #2
0
    def test_archive(self):
        self.assertEqual([], self.luct_glo.listing())
        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.add()
        path_usr = join(self.path_dir, 'inst_e', 'usr', 'foo')
        makedirs(path_usr)
        with open(join(path_usr, 'myfile'), mode='w+') as myfile:
            myfile.write('boooo!!')

        inst.filename = join(self.path_dir, "inst_e.arc")
        self.assertEqual(True, inst.archive())

        import tarfile
        list_file = []
        with tarfile.open(inst.filename, "r:gz") as tar:
            for tarinfo in tar:
                list_file.append(tarinfo.name)
        list_file.sort()
        self.assertEqual(
            ['dump.json', 'target', 'usr', 'usr/foo', 'usr/foo/myfile'], list_file)

        inst = LucteriosInstance("inst_f", self.path_dir)
        inst.add()
        inst.filename = join(self.path_dir, "inst_e.arc")
        self.assertEqual(True, inst.restore())
        self.assertEqual(True, isdir(join(self.path_dir, 'inst_f', 'usr')))
        self.assertEqual(
            True, isdir(join(self.path_dir, 'inst_f', 'usr', 'foo')))
        self.assertEqual(
            True, isfile(join(self.path_dir, 'inst_f', 'usr', 'foo', 'myfile')))
Exemple #3
0
    def test_add_read(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_mysql", self.path_dir)
        inst.set_database(
            "mysql:name=testv2,user=myuser,password=123456,host=localhost")
        inst.add()
        self.assertEqual(["inst_mysql"], self.luct_glo.listing())

        inst = LucteriosInstance("inst_mysql", self.path_dir)
        inst.read()
        self.assertEqual("mysql", inst.database[0])
        self.assertEqual("localhost", inst.database[1]['host'])
        self.assertEqual("testv2", inst.database[1]['name'])
        self.assertEqual("123456", inst.database[1]['password'])
        self.assertEqual("myuser", inst.database[1]['user'])
        self.assertEqual("lucterios.standard", inst.appli_name)
        self.assertEqual((), inst.modules)

        table_list = list(self.run_mysql_cmd("use testv2;show tables;"))
        if "Tables_in_testv2" in table_list:
            table_list.remove("Tables_in_testv2")
        table_list.sort()
        self.assertEqual(self.waiting_table, table_list)

        inst = LucteriosInstance("inst_mysql", self.path_dir)
        inst.clear()
        table_list = list(self.run_mysql_cmd("use testv2;show tables;"))
        self.assertEqual([], table_list)

        inst = LucteriosInstance("inst_mysql", self.path_dir)
        inst.delete()
        self.assertEqual([], self.luct_glo.listing())
Exemple #4
0
    def test_add_read(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_a", self.path_dir)
        inst.add()
        self.assertEqual(["inst_a"], self.luct_glo.listing())

        inst = LucteriosInstance("inst_a", self.path_dir)
        inst.read()
        self.assertEqual(("sqlite", {}), inst.database)
        self.assertEqual("lucterios.standard", inst.appli_name)
        self.assertEqual((), inst.modules)

        table_list = list(self.run_sqlite_cmd(
            "inst_a", "SELECT name FROM sqlite_master WHERE type='table';"))
        if "sqlite_sequence" in table_list:
            table_list.remove("sqlite_sequence")
        table_list.sort()
        self.assertEqual(self.waiting_table, table_list)

        inst = LucteriosInstance("inst_a", self.path_dir)
        inst.clear()

        table_list = list(self.run_sqlite_cmd(
            "inst_a", "SELECT name FROM sqlite_master WHERE type='table';"))
        if "sqlite_sequence" in table_list:
            table_list.remove("sqlite_sequence")
        table_list.sort()
        self.assertEqual([], table_list)

        self.assertEqual(["inst_a"], self.luct_glo.listing())
Exemple #5
0
    def test_extra(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.set_extra(
            "DEBUG=True,ALLOWED_HOSTS=[localhost;127.0.0.1],DEFAULT_PAGE=cms/,NBMAX=5,PIVALUE=3.1415"
        )
        inst.add()
        self.assertEqual(["inst_e"], self.luct_glo.listing())

        # print(open(self.path_dir + '/inst_a/settings.py', 'r').readlines())

        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.read()
        self.assertEqual(
            {
                'DEBUG': True,
                '': {
                    'mode': (0, 'Connexion toujours nécessaire')
                },
                'ALLOWED_HOSTS': ['localhost', '127.0.0.1'],
                'DEFAULT_PAGE': 'cms/',
                "NBMAX": 5,
                'PIVALUE': 3.1415
            }, inst.extra)
        inst.modif()

        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.read()
Exemple #6
0
    def test_security(self):
        from django.contrib.auth import authenticate
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.add()
        self.assertEqual(["inst_g"], self.luct_glo.listing())

        self.assertEqual(
            ["0"],
            list(
                self.run_sqlite_cmd(
                    "inst_g",
                    "SELECT value FROM CORE_parameter WHERE name='CORE-connectmode';"
                )))
        self.assertEqual(
            authenticate(username='******', password='******').username, 'admin')

        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.set_extra("PASSWORD=abc123,MODE=2")
        inst.security()

        self.assertEqual([
            "Admin password change in 'inst_g'.",
            "Security mode change in 'inst_g'."
        ], inst.msg_list)
        self.assertEqual(
            ["2"],
            list(
                self.run_sqlite_cmd(
                    "inst_g",
                    "SELECT value FROM CORE_parameter WHERE name='CORE-connectmode';"
                )))
        self.assertEqual(authenticate(username='******', password='******'),
                         None)
        self.assertEqual(
            authenticate(username='******', password='******').username,
            'admin')

        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.set_extra("MODE=1,PASSWORD=abc,123;ABC=789,3333")
        inst.security()
        self.assertEqual(authenticate(username='******', password='******'),
                         None)
        self.assertEqual(authenticate(username='******', password='******'),
                         None)
        self.assertEqual(
            authenticate(username='******',
                         password='******').username, 'admin')

        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.set_extra("PASSWORD=ppooi=jjhg,fdd,MODE=0")
        inst.security()
        self.assertEqual(
            authenticate(username='******', password='******').username,
            'admin')
Exemple #7
0
    def test_migration(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_h", self.path_dir)
        inst.add()
        self.assertEqual(["inst_h"], self.luct_glo.listing())
        mirg = MigrateFromV1("inst_h", self.path_dir, "")
        mirg.filename = join(
            dirname(self.path_dir), 'data', 'archive_demo.bkf')
        mirg.restore()
Exemple #8
0
    def test_migration(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_psql", self.path_dir)
        inst.set_database(
            "postgresql:name=" + self.data['dbname'] + ",user=puser,password=123456,host=localhost")
        inst.add()
        self.assertEqual(["inst_psql"], self.luct_glo.listing())
        mirg = MigrateFromV1("inst_psql", self.path_dir, "")
        mirg.filename = join(
            dirname(self.path_dir), 'data', 'archive_demo.bkf')
        mirg.restore()
Exemple #9
0
    def test_archive(self):
        self.assertEqual([], self.luct_glo.listing())
        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.add()
        inst.filename = join(self.path_dir, "inst_g.arc")
        self.assertEqual(True, inst.archive())

        inst = LucteriosInstance("inst_mysql", self.path_dir)
        inst.set_database(
            "mysql:name=testv2,user=myuser,password=123456,host=localhost")
        inst.add()
        inst.filename = join(self.path_dir, "inst_g.arc")
        self.assertEqual(True, inst.restore())
Exemple #10
0
    def test_archive(self):
        self.assertEqual([], self.luct_glo.listing())
        inst = LucteriosInstance("inst_h", self.path_dir)
        inst.add()
        inst.filename = join(self.path_dir, "inst_h.arc")
        self.assertEqual(True, inst.archive())

        inst = LucteriosInstance("inst_psql", self.path_dir)
        inst.set_database(
            "postgresql:name=" + self.data['dbname'] + ",user=puser,password=123456,host=localhost")
        inst.add()
        inst.filename = join(self.path_dir, "inst_h.arc")
        self.assertEqual(True, inst.restore())
Exemple #11
0
 def add_modif_inst_result(self, result, to_create):
     inst = LucteriosInstance(result[0])
     inst.set_extra("LANGUAGE_CODE=%s" % result[5])
     inst.set_appli(result[1])
     inst.set_module(result[2])
     inst.set_database(result[4])
     if to_create:
         inst.add()
     else:
         inst.modif()
     inst = LucteriosInstance(result[0])
     inst.set_extra(result[3])
     inst.security()
     self.refresh(result[0])
Exemple #12
0
    def test_extra(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.set_extra("DEBUG=True,ALLOWED_HOSTS=[localhost]")
        inst.add()
        self.assertEqual(["inst_e"], self.luct_glo.listing())

        # print(open(self.path_dir + '/inst_a/settings.py', 'r').readlines())

        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.read()
        self.assertEqual({'DEBUG': True, '': {'mode': (
            0, 'Connexion toujours nécessaire')}, 'ALLOWED_HOSTS': ['localhost']}, inst.extra)
Exemple #13
0
 def add_modif_inst_result(self, result, to_create):
     inst = LucteriosInstance(result[0])
     inst.set_extra("LANGUAGE_CODE='%s'" % result[5])
     inst.set_appli(result[1])
     inst.set_module(result[2])
     inst.set_database(result[4])
     if to_create:
         inst.add()
     else:
         inst.modif()
     inst = LucteriosInstance(result[0])
     inst.set_extra(result[3])
     inst.security()
     self.refresh(result[0])
Exemple #14
0
    def test_extra(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.set_extra("DEBUG=True,ALLOWED_HOSTS=[localhost;127.0.0.1],DEFAULT_PAGE=cms/,NBMAX=5,PIVALUE=3.1415")
        inst.add()
        self.assertEqual(["inst_e"], self.luct_glo.listing())

        # print(open(self.path_dir + '/inst_a/settings.py', 'r').readlines())

        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.read()
        self.assertEqual({'DEBUG': True, '': {'mode': (0, 'Connexion toujours nécessaire')},
                          'ALLOWED_HOSTS': ['localhost', '127.0.0.1'], 'DEFAULT_PAGE': 'cms/',
                          "NBMAX": 5, 'PIVALUE': 3.1415}, inst.extra)
        inst.modif()

        inst = LucteriosInstance("inst_e", self.path_dir)
        inst.read()
Exemple #15
0
    def test_add_del(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_c", self.path_dir)
        inst.add()
        self.assertEqual(["inst_c"], self.luct_glo.listing())

        inst = LucteriosInstance("inst_d", self.path_dir)
        inst.add()
        list_res = self.luct_glo.listing()
        list_res.sort()
        self.assertEqual(["inst_c", "inst_d"], list_res)

        inst = LucteriosInstance("inst_c", self.path_dir)
        inst.delete()
        self.assertEqual(["inst_d"], self.luct_glo.listing())

        inst = LucteriosInstance("inst_d", self.path_dir)
        inst.delete()
        self.assertEqual([], self.luct_glo.listing())
Exemple #16
0
    def test_security(self):
        from django.contrib.auth import authenticate
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.add()
        self.assertEqual(["inst_g"], self.luct_glo.listing())

        self.assertEqual(["0"], list(self.run_sqlite_cmd(
            "inst_g", "SELECT value FROM CORE_parameter WHERE name='CORE-connectmode';")))
        self.assertEqual(
            authenticate(username='******', password='******').username, 'admin')

        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.set_extra("PASSWORD=abc123,MODE=2")
        inst.security()

        self.assertEqual(["Admin password change in 'inst_g'.",
                          "Security mode change in 'inst_g'."], inst.msg_list)
        self.assertEqual(["2"], list(self.run_sqlite_cmd(
            "inst_g", "SELECT value FROM CORE_parameter WHERE name='CORE-connectmode';")))
        self.assertEqual(
            authenticate(username='******', password='******'), None)
        self.assertEqual(
            authenticate(username='******', password='******').username, 'admin')

        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.set_extra("MODE=1,PASSWORD=abc,123;ABC=789,3333")
        inst.security()
        self.assertEqual(
            authenticate(username='******', password='******'), None)
        self.assertEqual(
            authenticate(username='******', password='******'), None)
        self.assertEqual(authenticate(
            username='******', password='******').username, 'admin')

        inst = LucteriosInstance("inst_g", self.path_dir)
        inst.set_extra("PASSWORD=ppooi=jjhg,fdd,MODE=0")
        inst.security()
        self.assertEqual(
            authenticate(username='******', password='******').username, 'admin')
Exemple #17
0
    def test_add_modif(self):
        self.assertEqual([], self.luct_glo.listing())

        inst = LucteriosInstance("inst_b", self.path_dir)
        inst.add()
        self.assertEqual(["inst_b"], self.luct_glo.listing())

        inst = LucteriosInstance("inst_b", self.path_dir)
        inst.set_database("sqlite")
        inst.appli_name = "lucterios.standard"
        inst.modules = ('lucterios.dummy',)
        inst.modif()

        inst = LucteriosInstance("inst_b", self.path_dir)
        inst.read()
        self.assertEqual(("sqlite", {}), inst.database)
        self.assertEqual("lucterios.standard", inst.appli_name)
        self.assertEqual(('lucterios.dummy',), inst.modules)

        inst = LucteriosInstance("inst_b", self.path_dir)
        inst.refresh()