Esempio n. 1
0
 def test_load_from_f(self):
     with tempfile.NamedTemporaryFile('w+t') as f:
         f.write(self.access_key_val)
         f.flush()
         access_key = AccessKey()
         access_key.load_from_f(f.name)
         self.assertEqual(access_key, self.access_key)
Esempio n. 2
0
class TestAccessKey(unittest.TestCase):
    def setUp(self):
        self.access_key_val = "123:123"
        self.id = "123"
        self.secret = "123"
        self.access_key = AccessKey("123", "123")

    def test_clean(self):
        with self.assertRaises(LoadAccessKeyError):
            AccessKey.clean("123123")
        self.assertEqual(AccessKey.clean(self.access_key_val), (self.id, self.secret))

    def test_load_from_val(self):
        access_key = AccessKey()
        with self.assertRaises(LoadAccessKeyError):
            access_key.load_from_val("2123")
        access_key.load_from_val(self.access_key_val)
        self.assertEqual(access_key, self.access_key)

    def test_load_from_env(self):
        env_var = "XX_ACCESS_KEY"
        os.environ[env_var] = self.access_key_val
        access_key = AccessKey()
        access_key.load_from_env(env_var)
        self.assertEqual(access_key, self.access_key)

    def test_load_from_f(self):
        with tempfile.NamedTemporaryFile('w+t') as f:
            f.write(self.access_key_val)
            f.flush()
            access_key = AccessKey()
            access_key.load_from_f(f.name)
            self.assertEqual(access_key, self.access_key)

    def test_save_to_f(self):
        tmpf = tempfile.mktemp()
        self.access_key.save_to_f(tmpf)
        print(tmpf)
        with open(tmpf, 'rt') as f:
            val = f.read().strip()
            self.assertEqual(val, self.access_key_val)
        os.unlink(tmpf)
Esempio n. 3
0
 def setUp(self):
     self.access_key_val = "123:123"
     self.id = "123"
     self.secret = "123"
     self.access_key = AccessKey("123", "123")
     self.key_env_var = "XXX_ACCESS_KEY"
     self.key_file = tempfile.mktemp()
     config = {
         'ACCESS_KEY_ENV': self.key_env_var,
         'ACCESS_KEY': self.access_key_val,
         'ACCESS_KEY_FILE': self.key_file,
     }
     self.mock_app = MockApp(config)
     self.app_access_key = AppAccessKey(self.mock_app)
Esempio n. 4
0
 def test_load_from_env(self):
     env_var = "XX_ACCESS_KEY"
     os.environ[env_var] = self.access_key_val
     access_key = AccessKey()
     access_key.load_from_env(env_var)
     self.assertEqual(access_key, self.access_key)
Esempio n. 5
0
 def test_load_from_val(self):
     access_key = AccessKey()
     with self.assertRaises(LoadAccessKeyError):
         access_key.load_from_val("2123")
     access_key.load_from_val(self.access_key_val)
     self.assertEqual(access_key, self.access_key)
Esempio n. 6
0
 def test_clean(self):
     with self.assertRaises(LoadAccessKeyError):
         AccessKey.clean("123123")
     self.assertEqual(AccessKey.clean(self.access_key_val), (self.id, self.secret))
Esempio n. 7
0
 def setUp(self):
     self.access_key_val = "123:123"
     self.id = "123"
     self.secret = "123"
     self.access_key = AccessKey("123", "123")
Esempio n. 8
0
 def setUp(self):
     self.access_key = AccessKey(id="123123123", secret="1231231231")
     self.req = MockRequest()