Пример #1
0
def execute_from_command_line():
    from wirecloud.commons.commands.convert import ConvertCommand
    from wirecloud.commons.commands.startproject import StartprojectCommand
    utility = CommandLineUtility({
        "convert": ConvertCommand(),
        "startproject": StartprojectCommand()
    })
    try:
        utility.execute()
    except:
        sys.exit(1)
Пример #2
0
def execute_from_command_line():
    from wirecloud.commons.commands.convert import ConvertCommand
    from wirecloud.commons.commands.startproject import StartprojectCommand
    from wirecloud.fiware.commands.passintegrationtests import IntegrationTestsCommand
    utility = CommandLineUtility({
        "convert": ConvertCommand(),
        "startproject": StartprojectCommand(),
        "passintegrationtests": IntegrationTestsCommand(),
    })
    try:
        utility.execute()
    except:
        sys.exit(1)
Пример #3
0
    def setUpClass(cls):

        from wirecloud.commons.commands.convert import ConvertCommand
        from wirecloud.commons.commands.startproject import StartprojectCommand
        cls.command_utility = CommandLineUtility(
            {
                "convert": ConvertCommand(),
                "startproject": StartprojectCommand(),
            },
            prog_name='wirecloud-admin')
        cls.test_data_dir = os.path.join(os.path.dirname(__file__),
                                         'test-data')

        super(BaseAdminCommandTestCase, cls).setUpClass()
Пример #4
0
    def setUpClass(cls):

        from wirecloud.commons.commands.convert import ConvertCommand
        from wirecloud.commons.commands.startproject import StartprojectCommand
        from wirecloud.fiware.commands.passintegrationtests import IntegrationTestsCommand
        cls.command_utility = CommandLineUtility(
            {
                "convert": ConvertCommand(),
                "startproject": StartprojectCommand(),
                "passintegrationtests": IntegrationTestsCommand(),
            },
            prog_name='wirecloud-admin')
        cls.test_data_dir = os.path.join(os.path.dirname(__file__),
                                         'test-data')
Пример #5
0
    def setUp(self):

        from wirecloud.commons.commands.convert import ConvertCommand
        self.command = ConvertCommand()
Пример #6
0
class ConvertCommandTestCase(TestCase):

    tags = ('wirecloud-commands', 'wirecloud-command-convert')

    @classmethod
    def setUpClass(cls):

        cls.tmp_dir = mkdtemp()
        cls.test_data_dir = os.path.join(os.path.dirname(__file__), '../test-data')

    @classmethod
    def tearDownClass(cls):

        shutil.rmtree(cls.tmp_dir, ignore_errors=True)

    def setUp(self):

        from wirecloud.commons.commands.convert import ConvertCommand
        self.command = ConvertCommand()

    def tearDown(self):
        cleartree(self.tmp_dir)

    def test_no_args(self):

        args = []
        options = {
            "dest_format": "rdf"
        }
        self.assertRaises(CommandError, self.command.execute, *args, **options)

    def test_non_existent_file(self):

        args = ['/tmp/nonexistent_file.xml']
        options = {
            "dest_format": "rdf"
        }
        self.assertRaises(CommandError, self.command.execute, *args, **options)

    def test_invalid_dest_format(self):

        args = ['/tmp/nonexistent_file.xml']
        options = {
            "dest_format": "invalid"
        }
        self.assertRaises(CommandError, self.command.execute, *args, **options)

    def test_minimal_info_conversion_stdout(self):

        for format in ('json', 'xml', 'rdf', 'old_xml'):
            args = [os.path.join(self.test_data_dir, 'minimal_endpoint_info.json')]
            options = {"dest_format": format, "rdf_format": "n3", "stdout": io.BytesIO(), "stderr": io.BytesIO()}
            self.command.execute(*args, **options)

            options['stdout'].seek(0)
            self.assertNotEqual(options['stdout'].read(), '')
            options['stderr'].seek(0)
            self.assertEqual(options['stderr'].read(), '')

    def test_minimal_info_conversion_outputfile(self):

        dest_file = os.path.join(self.tmp_dir, 'new_file.xml')
        args = [os.path.join(self.test_data_dir, 'minimal_endpoint_info.json'), dest_file]
        options = {"dest_format": 'rdf', "rdf_format": "pretty-xml", "stdout": io.BytesIO(), "stderr": io.BytesIO()}
        self.command.execute(*args, **options)

        options['stdout'].seek(0)
        self.assertEqual(options['stdout'].read(), '')
        options['stderr'].seek(0)
        self.assertEqual(options['stderr'].read(), '')

        with open(dest_file, 'rb') as f:
            self.assertNotEqual(f.read(), '')
Пример #7
0
    def setUp(self):

        from wirecloud.commons.commands.convert import ConvertCommand
        self.command = ConvertCommand()
Пример #8
0
class ConvertCommandTestCase(WirecloudTestCase, TestCase):

    tags = ('wirecloud-commands', 'wirecloud-command-convert',
            'wirecloud-noselenium')
    fixtures = ()
    populate = False
    user_search_indexes = False

    @classmethod
    def setUpClass(cls):

        cls.tmp_dir = mkdtemp()
        cls.test_data_dir = os.path.join(os.path.dirname(__file__),
                                         'test-data')

        super(ConvertCommandTestCase, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):

        shutil.rmtree(cls.tmp_dir, ignore_errors=True)

    def setUp(self):

        from wirecloud.commons.commands.convert import ConvertCommand
        self.command = ConvertCommand()

    def tearDown(self):
        cleartree(self.tmp_dir)

    def test_no_args(self):

        args = []
        options = {"dest_format": "rdf"}
        self.assertRaises(CommandError, self.command.execute, *args, **options)

    def test_non_existent_file(self):

        args = ['/tmp/nonexistent_file.xml']
        options = {"dest_format": "rdf"}
        self.assertRaises(CommandError, self.command.execute, *args, **options)

    def test_invalid_dest_format(self):

        args = ['/tmp/nonexistent_file.xml']
        options = {"dest_format": "invalid"}
        self.assertRaises(CommandError, self.command.execute, *args, **options)

    def test_minimal_info_conversion_stdout(self):

        for format in ('json', 'xml', 'rdf'):
            args = [
                os.path.join(self.test_data_dir, 'minimal_endpoint_info.json')
            ]
            options = {
                "dest_format": format,
                "rdf_format": "n3",
                "stdout": io.StringIO(),
                "stderr": io.StringIO()
            }
            self.command.execute(*args, **options)

            options['stdout'].seek(0)
            self.assertNotEqual(options['stdout'].read(), '')
            options['stderr'].seek(0)
            self.assertEqual(options['stderr'].read(), '')

    def test_minimal_info_conversion_outputfile(self):

        dest_file = os.path.join(self.tmp_dir, 'new_file.xml')
        args = [
            os.path.join(self.test_data_dir, 'minimal_endpoint_info.json'),
            dest_file
        ]
        options = {
            "dest_format": 'rdf',
            "rdf_format": "pretty-xml",
            "stdout": io.StringIO(),
            "stderr": io.StringIO()
        }
        self.command.execute(*args, **options)

        options['stdout'].seek(0)
        self.assertEqual(options['stdout'].read(), '')
        options['stderr'].seek(0)
        self.assertEqual(options['stderr'].read(), '')

        with open(dest_file, 'rb') as f:
            self.assertNotEqual(f.read(), '')