Esempio n. 1
0
    def test_license_agreement_choice(self):
        """We have right callbacks called in license choices"""
        callback_yes = Mock()
        callback_no = Mock()
        inter = LicenseAgreement("License content", callback_yes, callback_no)

        self.assertEquals(inter.choose(choice_id=0), callback_yes.return_value)
        self.assertEquals(inter.choose(choice_id=1), callback_no.return_value)
        self.assertEquals(inter.choose(answer='a'), callback_yes.return_value)
        self.assertEquals(inter.choose(answer='N'), callback_no.return_value)
        self.assertEquals(inter.choose(), callback_no.return_value)
Esempio n. 2
0
    def test_license_agreement_choice(self):
        """We have right callbacks called in license choices"""
        callback_yes = Mock()
        callback_no = Mock()
        inter = LicenseAgreement("License content", callback_yes, callback_no)

        self.assertEquals(inter.choose(choice_id=0), callback_yes.return_value)
        self.assertEquals(inter.choose(choice_id=1), callback_no.return_value)
        self.assertEquals(inter.choose(answer='a'), callback_yes.return_value)
        self.assertEquals(inter.choose(answer='N'), callback_no.return_value)
        self.assertEquals(inter.choose(), callback_no.return_value)
Esempio n. 3
0
    def get_metadata_and_check_license(self, result):
        """Download files to download + license and check it"""
        logger.debug("Parse download metadata")

        error_msg = result[self.download_page].error
        if error_msg:
            logger.error("An error occurred while downloading {}: {}".format(
                self.download_page, error_msg))
            UI.return_main_screen()

        url, checksum = (None, None)
        with StringIO() as license_txt:
            in_license = False
            in_download = False
            for line in result[self.download_page].buffer:
                line_content = line.decode()

                if self.expect_license:
                    in_license = self.parse_license(line_content, license_txt,
                                                    in_license)

                (download, in_download) = self.parse_download_link(
                    line_content, in_download)
                if download is not None:
                    (newurl, new_checksum) = download
                    url = newurl if newurl is not None else url
                    checksum = new_checksum if new_checksum is not None else checksum
                    if url is not None:
                        if self.checksum_type and checksum:
                            logger.debug(
                                "Found download link for {}, checksum: {}".
                                format(url, checksum))
                            break
                        elif not self.checksum_type:
                            logger.debug(
                                "Found download link for {}".format(url))
                            break

            if url is None or (self.checksum_type and checksum is None):
                logger.error(
                    "Download page changed its syntax or is not parsable")
                UI.return_main_screen()
            self.download_requests.append(
                DownloadItem(url, Checksum(self.checksum_type, checksum)))

            if license_txt.getvalue() != "":
                logger.debug("Check license agreement.")
                UI.display(
                    LicenseAgreement(
                        strip_tags(license_txt.getvalue()).strip(),
                        self.start_download_and_install,
                        UI.return_main_screen))
            elif self.expect_license:
                logger.error(
                    "We were expecting to find a license on the download page, we didn't."
                )
                UI.return_main_screen()
            else:
                self.start_download_and_install()
        return
Esempio n. 4
0
 def test_license_agreement(self):
     """We can instantiate a license agreement interaction"""
     callback_yes = Mock()
     callback_no = Mock()
     inter = LicenseAgreement("License content", callback_yes, callback_no)
     self.assertEquals(inter.content, "License content")
     self.assertEquals(len(inter.choices), 2, str(inter.choices))
Esempio n. 5
0
    def check_data_and_start_download(self,
                                      url=None,
                                      checksum=None,
                                      license_txt=StringIO()):
        if url is None:
            logger.error(
                "Download page changed its syntax or is not parsable (url missing)"
            )
            UI.return_main_screen(status_code=1)
        if (self.checksum_type and checksum is None):
            logger.error(
                "Download page changed its syntax or is not parsable (checksum missing)"
            )
            logger.error("URL is: {}".format(url))
            UI.return_main_screen(status_code=1)
        self.download_requests.append(
            DownloadItem(url, Checksum(self.checksum_type, checksum)))

        if license_txt.getvalue() != "":
            logger.debug("Check license agreement.")
            UI.display(
                LicenseAgreement(
                    strip_tags(license_txt.getvalue()).strip(),
                    self.start_download_and_install, UI.return_main_screen))
        elif self.expect_license and not self.auto_accept_license:
            logger.error(
                "We were expecting to find a license on the download page, we didn't."
            )
            UI.return_main_screen(status_code=1)
        else:
            self.start_download_and_install()
Esempio n. 6
0
    def check_external_license(self, result):
        """Check external license which is in a separate page (can be factorized in BaseInstaller)"""
        logger.debug("Parse license page")
        error_msg = result[self.license_url].error
        if error_msg:
            logger.error("An error occurred while downloading {}: {}".format(self.license_url, error_msg))
            UI.return_main_screen(status_code=1)

        with StringIO() as license_txt:
            in_license = False
            for line in result[self.license_url].buffer:
                line = line.decode()
                if ('SOFTWARE LICENSE TERMS' in line):
                    in_license = True
                if in_license and "<strong>*   *   *</strong>" in line:
                    in_license = False
                    continue
                if in_license:
                    license_txt.write(line.strip() + "\n")

            if license_txt.getvalue() != "":
                logger.debug("Check license agreement.")
                UI.display(LicenseAgreement(strip_tags(license_txt.getvalue()).strip(),
                                            self.start_download_and_install,
                                            UI.return_main_screen))
            else:
                logger.error("We were expecting to find a license, we didn't.")
                UI.return_main_screen(status_code=1)
Esempio n. 7
0
 def test_license_agreement_input(self):
     """We return a license agreement input"""
     inter = LicenseAgreement("License content", lambda: "", lambda: "")
     self.assertEquals(inter.input, "[I Accept (a)/I don't accept (N)] ")