Ejemplo n.º 1
0
class SauceTestCase(BaseTestCase):
    def setUp(self):
        super(SauceTestCase, self).setUp()

        class PO(Page):
            pass

        self.PO = PO

    @raises(exceptions.MissingSauceOptionError)
    def test_missing_sauce_apikey_should_raise_missing_sauce_option_error(
            self):
        self.set_baseurl_env(base_file=False,
                             arbitrary_base="http://www.ncbi.nlm.nih.gov")
        os.environ["PO_SAUCE_USERNAME"] = "******"
        self.PO.uri = "/foo"
        self.PO()

    @raises(exceptions.MissingSauceOptionError)
    def test_missing_sauce_username_should_raise_missing_sauce_option_error(
            self):
        self.set_baseurl_env(base_file=False,
                             arbitrary_base="http://www.ncbi.nlm.nih.gov")
        os.environ["PO_SAUCE_APIKEY"] = "abc"
        self.PO.uri = "/foo"
        self.PO()

    @raises(exceptions.SauceConnectionError)
    def test_sauce_connection_error(self):
        self.set_baseurl_env(base_file=False,
                             arbitrary_base="http://www.ncbi.nlm.nih.gov")
        os.environ["PO_BROWSER"] = "Firefox"
        os.environ["PO_SAUCE_BROWSERVERSION"] = "27"
        os.environ["PO_SAUCE_USERNAME"] = "******"
        os.environ["PO_SAUCE_APIKEY"] = "bar"
        os.environ["PO_SAUCE_PLATFORM"] = "Windows 8.1"
        self.PO.uri = "/foo"
        p = self.PO()
        p.open()

    @skipUnless(BaseTestCase.are_sauce_creds_set_for_testing(),
                "SAUCE_USERNAME and SAUCE_APIKEY env vars must be set to test")
    @raises(selenium.common.exceptions.WebDriverException)
    def test_sauce_invalid_browser(self):
        self.set_baseurl_env(base_file=False,
                             arbitrary_base="http://www.ncbi.nlm.nih.gov")
        os.environ["PO_BROWSER"] = "Firefox"
        os.environ["PO_SAUCE_BROWSERVERSION"] = "27"
        username, apikey = self.get_sauce_creds()
        os.environ["PO_SAUCE_USERNAME"] = username
        os.environ["PO_SAUCE_APIKEY"] = apikey
        os.environ["PO_SAUCE_PLATFORM"] = "Winows 8.1"
        self.PO.uri = "/foo"
        p = self.PO()
        p.open()
Ejemplo n.º 2
0
class SauceTestCase(BaseTestCase):
    """
    Sauce exception tests are in the unit tests, not the
    functional tests.
    """
    def get_job_data(self, sid):
        username, apikey = self.get_sauce_creds()
        rest_url = "https://%s:%[email protected]/rest/v1/%s/jobs/%s" % (
            username, apikey, username, sid)
        resp = requests.get(rest_url)
        return json.loads(resp.content)

    def get_sid_from_log(self, is_robot=False):
        log_path = self.get_log_path(is_robot)
        try:
            f = open(log_path)
            content = f.read()
            try:
                return re.search(r"session ID: (.{32})", content).group(1)
            except (AttributeError, IndexError):
                raise Exception("Couldn't get the session ID from the log %s" %
                                log_path)

        except OSError:
            raise "Couldn't find a log file at %s" % log_path
        except IOError:
            raise Exception("Couldn't open log file %s" % log_path)
        finally:
            f.close()

    @unittest.skipUnless(BaseTestCase.are_sauce_creds_set_for_testing(),
                         "Must set 'SAUCE_USERNAME' and 'SAUCE_APIKEY' ("
                         "not PO_SAUCE."
                         ".) "
                         "as an env "
                         "variables to run this test")
    def test_sauce_unittest(self):
        self.assertFalse(os.path.exists(self.get_log_path()))
        run = self.run_scenario("test_sauce.py")
        job_data = self.get_job_data(self.get_sid_from_log())

        # Just check an arbitrary entry in the job data returned from sauce.
        self.assertEquals(job_data["browser"], "firefox",
                          "The job ran in Sauce")

        # We expect this to fail, because the test makes a purposely false assertion
        # to test that we can assert against things going on in Sauce.
        self.assert_run(
            run,
            expected_returncode=1,
            search_output="Title should have been 'foo' but was 'Home - "
            "PubMed - NCBI")

    @unittest.skipUnless(BaseTestCase.are_sauce_creds_set_for_testing(),
                         "Must set 'SAUCE_USERNAME' and 'SAUCE_APIKEY' ("
                         "not "
                         "PO_SAUCE..) "
                         "as an env "
                         "variables to run this test")
    def test_sauce_robot(self):
        self.assertFalse(os.path.exists(self.get_log_path(is_robot=True)))
        run = self.run_scenario("test_sauce.robot",
                                variablefile=os.path.join(
                                    self.test_dir, "sauce_vars.py"))

        job_data = self.get_job_data(self.get_sid_from_log(is_robot=True))

        # Just check an arbitrary entry in the job data returned from sauce.
        self.assertEquals(job_data["browser"], "firefox",
                          "The job ran in Sauce")
        self.assert_run(
            run,
            expected_returncode=1,
            search_output="Title should have been 'foo' but was 'Home - "
            "PubMed - NCBI")