def test_save_method(self): token_mock = self.build_token_mock("dnlksn12lndsn1lsdn1elndn") self.mocker.replay() account = TwitterAccount(jid="[email protected]/Adium123") account._token = token_mock account.save() self.mocker.verify() assert 1 == User.objects(jid="*****@*****.**").count() assert 1 == User.objects(token="dnlksn12lndsn1lsdn1elndn").count()
def test_verify_with_invalid_code(self): auth = self.mocker.mock() auth.get_access_token(mocker.ARGS) self.mocker.throw(TweepError("error")) self.mocker.replay() account = TwitterAccount("[email protected]/Adium123") account._auth = auth verified = account.verify("code") self.mocker.verify() assert not verified assert not account.verified assert account.authenticating
def test_verify_with_valid_code(self): auth = self.mocker.mock() auth.get_access_token(mocker.ARGS) tweepy = self.mocker.replace("tweepy") tweepy.API(mocker.ARGS) self.mocker.result("api_instance") self.mocker.replay() account = TwitterAccount("[email protected]/Adium123") account._auth = auth verified = account.verify("code") self.mocker.verify() assert verified assert account.verified assert not account.authenticating
def test_authenticate(self): handler = self.mocker.mock() handler.get_authorization_url() self.mocker.result("http://twitter.com/authorize") tweepy = self.mocker.replace("tweepy") tweepy.OAuthHandler(mocker.ARGS) self.mocker.result(handler) self.mocker.replay() account = TwitterAccount("[email protected]/Adium123") redirect_url = account.authenticate() self.mocker.verify() assert "http://twitter.com/authorize" == redirect_url assert account.authenticating assert not account.verified
def test_save_method_updates_token_if_user_already_exists(self): token_mock1 = self.build_token_mock("dnjabndakjbdajsdbas") token_mock2 = self.build_token_mock("12nkn21kn1lk2nkl1n2") self.mocker.replay() account1 = TwitterAccount(jid="[email protected]/Adium123") account1._token = token_mock1 account1.save() account2 = TwitterAccount(jid="[email protected]/Psi456") account2._token = token_mock2 account2.save() self.mocker.verify() assert 1 == User.objects(jid="*****@*****.**").count() assert 1 == User.objects(token="12nkn21kn1lk2nkl1n2").count()
def test_reload_authentication_method(self): token_mock = self.build_token_mock("oauth_token_secret=secret&oauth_token=token") self.mocker.replay() account = TwitterAccount(jid="[email protected]/Adium123") account._token = token_mock assert not account.reload_authentication() account.save() assert account.reload_authentication() account.reload_authentication() assert "secret" == account._token.secret assert "token" == account._token.key assert isinstance(account.api, tweepy.API)