def test_PluginExistsIfFalse(self):
     """Tests the plugin exists method if none exists."""
     actual = self.helper.PluginExists(
         'temp', 'plugin_test', 'db',
         fake_sqlite_plugin_path_helper.FakeSQLitePluginPathHelper(
             self.template_path, 'test', 'db'))
     self.assertFalse(actual)
    def test_PluginExistsIfTrue(self):
        """Tests the plugin exists"""
        with tempfile.TemporaryDirectory() as tmpdir:
            file_path = os.path.join(tmpdir, 'test')
            new_file = open(file_path, 'a')
            actual = self.helper.PluginExists(
                tmpdir, new_file.name, 'db',
                fake_sqlite_plugin_path_helper.FakeSQLitePluginPathHelper(
                    self.template_path, new_file.name, 'db'))
            new_file.close()
            os.remove(file_path)

        self.assertTrue(actual)
 def testPrintCreate(self):
     """test the print for a create"""
     with tempfile.TemporaryDirectory() as tmpdir:
         fake_path_helper = (
             fake_sqlite_plugin_path_helper.FakeSQLitePluginPathHelper(
                 self.template_path, 'test', 'db'))
         path = os.path.join(tmpdir, 'testfile')
         generator = sqlite_generator.SQLiteGenerator(
             tmpdir, 'test', 'test', ['test'],
             output_handler_file.OutputHandlerFile(
                 path, file_handler.FileHandler()), self.plugin_helper,
             fake_path_helper)
         generator._PrintCreate(path)  # pylint: disable=protected-access
         expected = 'create ' + path
         actual = self._ReadFromFile(path)
     self.assertEqual(expected, actual)
    def testGenerateSQLitePluginWithExistingInit(self):
        """test the output of a generation of a sqlite plugin"""
        fake_handler = fake_file_handler.FakeFileHandler()
        mapping_helper = fake_mapping_helper.FakeMappingHelper(
            self.template_path)
        init_formatter_mapper = fake_sqliteplugin_mapping.FakeSQLitePluginMapper(
            mapping_helper)
        init_parser_mapper = fake_sqliteplugin_mapping.FakeSQLitePluginMapper(
            mapping_helper)
        parser_mapper = fake_sqliteplugin_mapping.FakeSQLitePluginMapper(
            mapping_helper)
        formatter_mapper = fake_sqliteplugin_mapping.FakeSQLitePluginMapper(
            mapping_helper)
        parser_test_mapper = fake_sqliteplugin_mapping.FakeSQLitePluginMapper(
            mapping_helper)
        formatter_test_mapper = (
            fake_sqliteplugin_mapping.FakeSQLitePluginMapper(mapping_helper))
        fake_database_information = (
            fake_sqlite_database_information.FakeSQLiteDatabaseInformation([]))

        with tempfile.TemporaryDirectory() as tmpdir:
            fake_path_helper = (
                fake_sqlite_plugin_path_helper.FakeSQLitePluginPathHelper(
                    self.template_path, 'test', 'db'))
            path = os.path.join(tmpdir, 'testfile')

            generator = sqlite_generator.SQLiteGenerator(
                tmpdir, 'test', 'test', [],
                output_handler_file.OutputHandlerFile(
                    path, file_handler.FileHandler()), self.plugin_helper,
                fake_path_helper)

            generator.init_formatter_exists = True
            generator.init_parser_exists = True

            generator.GenerateSQLitePlugin(
                tmpdir, fake_handler, init_formatter_mapper,
                init_parser_mapper, parser_mapper, formatter_mapper,
                parser_test_mapper, formatter_test_mapper, mapping_helper,
                fake_database_information)
            expected = (
                'create testcreate testcreate testcreate testcopy testedit '
                'testedit test')
            actual = self._ReadFromFile(path)
        self.assertEqual(expected, actual)
    def testPrint(self):
        """test print"""
        with tempfile.TemporaryDirectory() as tmpdir:
            fake_path_helper = \
              fake_sqlite_plugin_path_helper.FakeSQLitePluginPathHelper(
                  self.template_path, 'test', 'db')
            path = os.path.join(tmpdir, 'testfile')
            generator = sqlite_generator.SQLiteGenerator(
                tmpdir, 'test', 'test', ['test'],
                output_handler_file.OutputHandlerFile(
                    path, file_handler.FileHandler()), self.plugin_helper,
                fake_path_helper)
            arguments = 'test1', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7'
            generator._Print(*arguments)  # pylint: disable=protected-access
            actual = self._ReadFromFile(path)

        expected = 'create test1create test2create test3create test4copy ' \
                   'test5create test6create test7'
        self.assertEqual(expected, actual)