Skip to content
Snippets Groups Projects
Select Git revision
  • ceed44de742fa5e17196a3a603ef8a1b0f661297
  • main default protected
2 results

test_keyring.py

Blame
  • test_keyring.py 2.26 KiB
    import keyring
    from pytest import fixture, mark
    from main import parse_credentials
    import sys, os
    
    
    @fixture
    def ex_whoami(ex_user):
        if ex_user is None:
            if sys.platform == 'darwin':
                return os.getenv('USER')
            else:
                return os.getlogin()
        else:
            return ex_user
    
    
    @fixture
    def ex_service(ex_host):
        return 'MDDB (' + ex_host + ')'
    
    
    @mark.parametrize("uri,ex_user,ex_host", [(
            "https://kashuba@metadata.institut2c.physik.rwth-aachen.de:8123/api/",
                'kashuba', 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
            "https://o.kashuba@metadata.institut2c.physik.rwth-aachen.de:8123",
                'o.kashuba', 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
            "https://metadata.institut2c.physik.rwth-aachen.de:8123",
                None, 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
            "https://metadata.institut2c.physik.rwth-aachen.de",
                None, 'metadata.institut2c.physik.rwth-aachen.de')])
    def test_parse_credentials(uri, ex_whoami, ex_service):
        service, username = parse_credentials(uri)
        assert service == ex_service
        assert username == ex_whoami
    
    
    @mark.parametrize("ex_pass", ['TESTpass3£$%^$%', '', 'any'])
    def test_set_get_pass(ex_pass):
        service, user = parse_credentials("https://metadata.institut2c.physik.rwth-aachen.de")
        keyring.set_password(service, user, ex_pass)
        password = keyring.get_password(service, user)
        assert password == ex_pass
    
    
    # @mark.parametrize("uri,ex_user,ex_host", [(
    #         "https://kashuba@metadata.institut2c.physik.rwth-aachen.de:8123/api/",
    #             'kashuba', 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
    #         "https://o.kashuba@metadata.institut2c.physik.rwth-aachen.de:8123",
    #             'o.kashuba', 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
    #         "https://metadata.institut2c.physik.rwth-aachen.de:8123",
    #             None, 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
    #         "https://metadata.institut2c.physik.rwth-aachen.de",
    #             None, 'metadata.institut2c.physik.rwth-aachen.de')])
    # def test_set_pass():
    #     print()
    #     user, service = parse_credentials("https://metadata.institut2c.physik.rwth-aachen.de")
    #     keyring.set_password(service, user, 'TESTpass3465£$%^$%111')