def test_from_configfile_fp_invalid(self): """ Test loading store with missing section in config. """ fp = StringIO(u"[invalid]\nusername=password") auth = SimpleAuthenticator() try: auth.from_configfile(fp) self.fail("Expected error with missing section.") except ValueError as e: pass
def test_from_configfile(self): """ Test the loading store from config file path. """ filename = resource_filename('tests.resources', 'auth.ini') auth = SimpleAuthenticator() auth.from_configfile(filename) assert auth.authenticate('juniper', 'b3rr1es') == True assert auth.authenticate('oak', 'ac$rrubrum') == True assert auth.authenticate('pinetree', 'str0bus') == True assert auth.authenticate('foo', 'bar') == False
def test_from_configfile_invalid(self): """ Test loading store with invalid file path. """ filename = resource_filename('tests.resources', 'auth-invlaid.ini') auth = SimpleAuthenticator() try: auth.from_configfile(filename) self.fail("Expected error with invalid filename.") except ValueError as e: pass
def test_from_configfile_fp(self): """ Test loading store from file-like object. """ with open(resource_filename('tests.resources', 'auth.ini'), 'r') as fp: auth = SimpleAuthenticator() auth.from_configfile(fp) assert auth.authenticate('juniper', 'b3rr1es') == True assert auth.authenticate('oak', 'ac$rrubrum') == True assert auth.authenticate('pinetree', 'str0bus') == True assert auth.authenticate('foo', 'bar') == False