Пример #1
0
 def setUp(self):
     self.parser = InfoParser()
Пример #2
0
class InfoParserTest(unittest.TestCase):
    def setUp(self):
        self.parser = InfoParser()

    def load_file(self, name):
        folder = join(join(dirname(__file__), 'infos'))
        path = join(folder, name)
        with open(path, 'r') as f:
            text = f.read()
        return text

    def test_simple(self):
        xml = self.load_file('simple_info.xml')
        result = self.parser.parse(xml)
        self.assertEqual('My Test App', result['name'])
        self.assertEqual(925, result['category'])
        self.assertEqual('simple', result['description'])
        self.assertEqual('a', result['author'])
        self.assertEqual(16, result['licence'])
        self.assertEqual('0.0.1', result['version'])
        self.assertEqual('8', result['requiremin'])
        self.assertEqual('9', result['requiremax'])

    def test_simple_require(self):
        xml = self.load_file('simple_info_require.xml')
        result = self.parser.parse(xml)
        self.assertEqual('8', result['requiremin'])

    def test_simple_require_owncloud(self):
        xml = self.load_file('simple_info_require_owncloud.xml')
        result = self.parser.parse(xml)
        self.assertEqual('8', result['requiremin'])
        self.assertEqual('9', result['requiremax'])

    def test_simple_no_author(self):
        xml = self.load_file('simple_info_no_author.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_category(self):
        xml = self.load_file('simple_info_no_category.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_description(self):
        xml = self.load_file('simple_info_no_description.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_licence(self):
        xml = self.load_file('simple_info_no_licence.xml')
        result = self.parser.parse(xml)
        self.assertEqual(6, result['licence'])

    def test_simple_no_name(self):
        xml = self.load_file('simple_info_no_name.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_requiremin(self):
        xml = self.load_file('simple_info_no_requiremin.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_version(self):
        xml = self.load_file('simple_info_no_version.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_unknown_category(self):
        xml = self.load_file('simple_info_unknown_category.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_unknown_licence(self):
        xml = self.load_file('simple_info_unknown_licence.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_all(self):
        xml = self.load_file('all_info.xml')
        result = self.parser.parse(xml)
        self.assertEqual('News', result['name'])
        self.assertEqual(920, result['category'])
        self.assertEqual('An RSS/Atom feed reader', result['description'])
        self.assertEqual('Bernhard Posselt', result['author'])
        self.assertEqual(16, result['licence'])
        self.assertEqual('4.3.2', result['version'])
        self.assertEqual('7.6', result['requiremin'])
        self.assertEqual('https://github.com/owncloud/news',
                         result['homepage'])
        self.assertEqual('https://github.com/owncloud/news/issues',
                         result['bugs'])
        self.assertEqual('https://github.com/owncloud/news.git',
                         result['repository'])
        self.assertEqual('168040', result['ocsid'])
Пример #3
0
    def run(self, arguments, directory, settings):
        url = settings.get_value("appstore", "url").rstrip("/")
        user = settings.get_value("appstore", "user")
        password = settings.get_value("appstore", "password")
        archive_dir = arguments.archive
        app_name = basename(archive_dir).split(".")[0]

        # parse the appinfo/info.xml from the archive to fill in stuff required
        # for the release
        archive = tar_open(archive_dir)

        # TODO: we need app validation like:
        # * name of the folder is the same as the id in info.xml
        # * no private api usage
        # * all needed fields for info.xml present
        # * size not bigger than allowed to upload
        info_xml = archive.extractfile(
            dict(zip(archive.getnames(), archive.getmembers()))["%s/appinfo/info.xml" % app_name]
        )

        parser = InfoParser()
        result = parser.parse(info_xml.read())

        # no ocsid present means not yet in the appstore so let's upload it
        params = {
            "name": result["name"],
            "type": result["category"],
            "depend": result["requiremin"],
            "downloadtype1": 0,
            "licensetype": result["licence"],
            "version": result["version"],
        }

        if result["homepage"] != "":
            params["homepage"] = result["homepage"]
            params["homepagetype"] = "Homepage"
        if result["repository"] != "":
            params["homepage2"] = result["repository"]
            params["homepagetype2"] = "Version Control"
        if result["bugs"] != "":
            params["homepage3"] = result["bugs"]
            params["homepagetype3"] = "Issue Tracker"
        if result["requiremax"] != "":
            params["depend2"] = result["requiremax"]

        if result["ocsid"] == "":
            create_url = "%s/content/add " % url
            response = requests.post(create_url, params=params, auth=(user, password))
            code = self.get_status_code(response)

            if code == "102":
                raise Exception("Not authorized! Check your credentials.")

            # get ocsid
            tree = ElementTree.fromstring(response.text)
            ocsid = tree.findtext(".//data/content/id")

            print(
                "Please add <ocsid>%s</ocsid> to your appinfo/info.xml to "
                + "be able to update the uploaded app" % ocsid
            )
        else:
            update_url = "%s/content/edit/%s" % (url, result["ocsid"])
            response = requests.post(update_url, params=params, auth=(user, password))
            code = self.get_status_code(response)

            if code == "102":
                raise Exception("Not authorized! Check your credentials.")

        upload_file_url = "%s/content/uploaddownload/%s" % (url, result["ocsid"])
        file = {"localfile": open(archive_dir, "rb")}
        response = requests.post(files=file)
        code = self.get_status_code(response)

        if code == "101":
            raise Exception("Could not upload file. Is the archive bigger " + "than 10Mb?")
        elif code == "103":
            raise Exception("Not authorized! Check your credentials.")
Пример #4
0
    def run(self, arguments, directory, settings):
        url = settings.get_value('appstore', 'url').rstrip('/')
        user = settings.get_value('appstore', 'user')
        password = settings.get_value('appstore', 'password')
        archive_dir = arguments.archive
        app_name = basename(archive_dir).split('.')[0]

        # parse the appinfo/info.xml from the archive to fill in stuff required
        # for the release
        archive = tar_open(archive_dir)

        # TODO: we need app validation like:
        # * name of the folder is the same as the id in info.xml
        # * no private api usage
        # * all needed fields for info.xml present
        # * size not bigger than allowed to upload
        info_xml = archive.extractfile(
            dict(zip(archive.getnames(),
                     archive.getmembers()))['%s/appinfo/info.xml' % app_name])

        parser = InfoParser()
        result = parser.parse(info_xml.read())

        # no ocsid present means not yet in the appstore so let's upload it
        params = {
            'name': result['name'],
            'type': result['category'],
            'depend': result['requiremin'],
            'downloadtype1': 0,
            'licensetype': result['licence'],
            'version': result['version']
        }

        if result['homepage'] != '':
            params['homepage'] = result['homepage']
            params['homepagetype'] = 'Homepage'
        if result['repository'] != '':
            params['homepage2'] = result['repository']
            params['homepagetype2'] = 'Version Control'
        if result['bugs'] != '':
            params['homepage3'] = result['bugs']
            params['homepagetype3'] = 'Issue Tracker'
        if result['requiremax'] != '':
            params['depend2'] = result['requiremax']

        if result['ocsid'] == '':
            create_url = '%s/content/add ' % url
            response = requests.post(create_url,
                                     params=params,
                                     auth=(user, password))
            code = self.get_status_code(response)

            if code == '102':
                raise Exception('Not authorized! Check your credentials.')

            # get ocsid
            tree = ElementTree.fromstring(response.text)
            ocsid = tree.findtext('.//data/content/id')

            print('Please add <ocsid>%s</ocsid> to your appinfo/info.xml to ' +
                  'be able to update the uploaded app' % ocsid)
        else:
            update_url = '%s/content/edit/%s' % (url, result['ocsid'])
            response = requests.post(update_url,
                                     params=params,
                                     auth=(user, password))
            code = self.get_status_code(response)

            if code == '102':
                raise Exception('Not authorized! Check your credentials.')

        upload_file_url = '%s/content/uploaddownload/%s' % (url,
                                                            result['ocsid'])
        file = {'localfile': open(archive_dir, 'rb')}
        response = requests.post(files=file)
        code = self.get_status_code(response)

        if code == '101':
            raise Exception('Could not upload file. Is the archive bigger ' +
                            'than 10Mb?')
        elif code == '103':
            raise Exception('Not authorized! Check your credentials.')
Пример #5
0
 def setUp(self):
     self.parser = InfoParser()
Пример #6
0
class InfoParserTest(unittest.TestCase):

    def setUp(self):
        self.parser = InfoParser()

    def load_file(self, name):
        folder = join(join(dirname(__file__), 'infos'))
        path = join(folder, name)
        with open(path, 'r') as f:
            text = f.read()
        return text

    def test_simple(self):
        xml = self.load_file('simple_info.xml')
        result = self.parser.parse(xml)
        self.assertEqual('My Test App', result['name'])
        self.assertEqual(925, result['category'])
        self.assertEqual('simple', result['description'])
        self.assertEqual('a', result['author'])
        self.assertEqual(16, result['licence'])
        self.assertEqual('0.0.1', result['version'])
        self.assertEqual('8', result['requiremin'])
        self.assertEqual('9', result['requiremax'])

    def test_simple_require(self):
        xml = self.load_file('simple_info_require.xml')
        result = self.parser.parse(xml)
        self.assertEqual('8', result['requiremin'])

    def test_simple_require_owncloud(self):
        xml = self.load_file('simple_info_require_owncloud.xml')
        result = self.parser.parse(xml)
        self.assertEqual('8', result['requiremin'])
        self.assertEqual('9', result['requiremax'])

    def test_simple_no_author(self):
        xml = self.load_file('simple_info_no_author.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_category(self):
        xml = self.load_file('simple_info_no_category.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_description(self):
        xml = self.load_file('simple_info_no_description.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_licence(self):
        xml = self.load_file('simple_info_no_licence.xml')
        result = self.parser.parse(xml)
        self.assertEqual(6, result['licence'])

    def test_simple_no_name(self):
        xml = self.load_file('simple_info_no_name.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_requiremin(self):
        xml = self.load_file('simple_info_no_requiremin.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_version(self):
        xml = self.load_file('simple_info_no_version.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_unknown_category(self):
        xml = self.load_file('simple_info_unknown_category.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_simple_no_unknown_licence(self):
        xml = self.load_file('simple_info_unknown_licence.xml')
        with self.assertRaises(InvalidConfigError):
            self.parser.parse(xml)

    def test_all(self):
        xml = self.load_file('all_info.xml')
        result = self.parser.parse(xml)
        self.assertEqual('News', result['name'])
        self.assertEqual(920, result['category'])
        self.assertEqual('An RSS/Atom feed reader', result['description'])
        self.assertEqual('Bernhard Posselt', result['author'])
        self.assertEqual(16, result['licence'])
        self.assertEqual('4.3.2', result['version'])
        self.assertEqual('7.6', result['requiremin'])
        self.assertEqual('https://github.com/owncloud/news', result['homepage'])
        self.assertEqual('https://github.com/owncloud/news/issues', result['bugs'])
        self.assertEqual('https://github.com/owncloud/news.git', result['repository'])
        self.assertEqual('168040', result['ocsid'])