def test_delete_not_crashing(path=None): # although in above test we just use/interact with Keyring without specifying # any custom one, there we do not change it so I guess it is ok. Here we want # a real keyring backend which we will alter from keyrings.alt.file import PlaintextKeyring kb = PlaintextKeyring() kb.filename = path keyring = Keyring(keyring_backend=kb) cred = UserPassword("test1", keyring=keyring) cred.set(user="******", password="******") ok_file_has_content(path, ".*test1.*", re_=True) # keyring backend saves where we expect # manually delete one component of the credential cred._keyring.delete(cred.name, next(iter(cred._FIELDS))) # now delete entire credential -- we must not crash cred.delete() try: ok_file_has_content(path, ".*test1.*", re_=True) # keyring backend saves where we expect raise AssertionError("keyring still has our key") except AssertionError: pass
def test_credentials_from_env(): keyring = Keyring() cred = AWS_S3("test-s3", keyring=keyring) assert_false(cred.is_known) assert_equal(cred.get('key_id'), None) assert_equal(cred.get('secret_id'), None) with patch.dict('os.environ', {'DATALAD_test_s3_key_id': '1'}): assert_equal(cred.get('key_id'), '1') assert_false(cred.is_known) with patch.dict('os.environ', {'DATALAD_test_s3_secret_id': '2'}): assert_equal(cred.get('key_id'), '1') assert_equal(cred.get('secret_id'), '2') assert_true(cred.is_known) assert_false(cred.is_known) # no memory of the past
def test_credentials_from_env(): keyring = Keyring() cred = AWS_S3("test-s3", keyring=keyring) assert_false(cred.is_known) assert_equal(cred.get('key_id'), None) assert_equal(cred.get('secret_id'), None) def _check1(): assert_equal(cred.get('key_id'), '1') assert_false(cred.is_known) def _check2(): assert_equal(cred.get('key_id'), '1') assert_equal(cred.get('secret_id'), '2') assert_true(cred.is_known) # this is the old way, should still work with patch.dict('os.environ', {'DATALAD_test_s3_key_id': '1'}): _check1() with patch.dict('os.environ', {'DATALAD_test_s3_secret_id': '2'}): _check2() assert_false(cred.is_known) # no memory of the past # here is the new way import datalad try: with patch.dict('os.environ', {'DATALAD_CREDENTIAL_test__s3_key__id': '1'}): datalad.cfg.reload() _check1() with patch.dict('os.environ', {'DATALAD_CREDENTIAL_test__s3_secret__id': '2'}): datalad.cfg.reload() _check2() datalad.cfg.reload() assert_false(cred.is_known) # no memory of the past finally: datalad.cfg.reload()