def test_no_acct(self): # Given url = "https://acme.com" auth_url = url + "/accounts/user/info/" config = Configuration() config.update(store_url=url) def callback(request): if auth != ("valid_user", "valid_password"): return (403, {}, "") return (200, {}, json.dumps(R_JSON_AUTH_RESP)) responses.add_callback(responses.GET, auth_url, callback) write_default_config(self.f) with Session.from_configuration(config) as session: config = Configuration() config.update(store_url=url) auth = ("invalid_user", "invalid_password") with self.assertRaises(AuthFailedError): usr = config._checked_change_auth(auth, session, self.f) config = Configuration() auth = ("valid_user", "valid_password") usr = config._checked_change_auth(auth, session, self.f) self.assertTrue(usr.is_authenticated) self.assertEqual(config.auth, UserPasswordAuth("valid_user", "valid_password"))
def test_remote_success(self): write_default_config(self.f) config = Configuration() auth = ("usr", "password") session = Session(DummyAuthenticator(old_auth_user), self.d) with session: usr = config._checked_change_auth(auth, session, self.f) self.assertEqual(usr, UserInfo(True))