Пример #1
0
    def test_read_config(self):
        # unset env
        at = None
        ac = None
        if "STAROID_ACCESS_TOKEN" in os.environ:
            at = os.environ["STAROID_ACCESS_TOKEN"]
            del os.environ["STAROID_ACCESS_TOKEN"]
        if "STAROID_ACCOUNT" in os.environ:
            ac = os.environ["STAROID_ACCOUNT"]
            del os.environ["STAROID_ACCOUNT"]

        # given
        fp = tempfile.NamedTemporaryFile()
        fp.write(b"access_token: abc\naccount: GITHUB/user1")
        fp.flush()

        # when
        s = Staroid(config_path=fp.name)

        # then
        self.assertEqual("abc", s.get_access_token())
        self.assertEqual("GITHUB/user1", s.get_account())

        # restore env
        if at != None:
            os.environ["STAROID_ACCESS_TOKEN"] = at
        if ac != None:
            os.environ["STAROID_ACCOUNT"] = ac
Пример #2
0
    def test_read_default_account(self):
        # given access_token is set but account is not set
        ac = None
        if "STAROID_ACCOUNT" in os.environ:
            ac = os.environ["STAROID_ACCOUNT"]
            del os.environ["STAROID_ACCOUNT"]

        # when
        s = Staroid()

        # then
        self.assertNotEqual(None, s.get_account())

        # restore env
        if ac != None:
            os.environ["STAROID_ACCOUNT"] = ac