def test_unblock(self, monkeypatch): profile = Profile() profile.username = "******" monkeypatch.setattr(self.account, "unblock", lambda x: profile) response = self.core.unblock(self.acc_id, "foo") assert response == profile
def test_report_as_spam(self, monkeypatch): profile = Profile() profile.username = "******" monkeypatch.setattr(self.account, "report_as_spam", lambda x: profile) monkeypatch.setattr(self.core, "remove_friend", lambda x: None) response = self.core.report_as_spam(self.acc_id, "foo") assert response == profile
def test_follow(self, monkeypatch): profile = Profile() profile.username = "******" monkeypatch.setattr(self.account, "follow", lambda x, y: profile) monkeypatch.setattr(self.core, "add_friend", lambda x: None) response = self.core.follow(self.acc_id, "foo") assert response == profile response = self.core.follow(self.acc_id, "123", True) assert response == profile
def test_get_following(self, monkeypatch): profile = Profile() profile.id_ = "dummy" result = [profile] monkeypatch.setattr(self.account, "get_following", lambda x: result) response = self.core.get_following(self.acc_id) assert isinstance(response, list) assert response[0].id_, "dummy"
def test_get_all_friends_list(self, monkeypatch): account = Account.new("twitter") accounts = [account] profile = Profile() profile.username = "******" result = [profile] monkeypatch.setattr(self.core.accman, "accounts", lambda: accounts) monkeypatch.setattr(account, "get_following", lambda: result) friends = self.core.get_all_friends_list() assert isinstance(friends, list) assert friends[0], "dummy"
class TestProfile: @classmethod @pytest.fixture(autouse=True) def setup_class(self, monkeypatch): self.profile = Profile() self.profile.username = '******' self.profile.account_id = 'foo-twitter' self.profile.fullname = "Foo Bar" def test_structure(self): profile = Profile() assert profile.id_ == None assert profile.account_id == None assert profile.fullname == None assert profile.username == None assert profile.avatar == None assert profile.location == '' assert profile.url == '' assert profile.bio == '' assert profile.following == None assert profile.followed_by == None assert profile.follow_request == False assert profile.followers_count == 0 assert profile.friends_count == 0 assert profile.link_color == None assert profile.statuses_count == 0 assert profile.favorites_count == 0 assert profile.last_update == None assert profile.last_update_id == None assert profile.recent_updates == [] assert profile.tmp_avatar_path == None assert profile.protected == False assert profile.verified == False assert profile.muted == False def test_repr(self): assert str(self.profile) == "libturpial.api.models.Profile foo" def test_is_me(self, monkeypatch): assert self.profile.is_me() == True monkeypatch.setattr(self.profile, 'username', 'dummy') assert self.profile.is_me() == False def test_get_protocol_id(self, monkeypatch): assert self.profile.get_protocol_id() == 'twitter' monkeypatch.setattr(self.profile, 'account_id', None) assert self.profile.get_protocol_id() == None
def test_structure(self): profile = Profile() assert profile.id_ == None assert profile.account_id == None assert profile.fullname == None assert profile.username == None assert profile.avatar == None assert profile.location == '' assert profile.url == '' assert profile.bio == '' assert profile.following == None assert profile.followed_by == None assert profile.follow_request == False assert profile.followers_count == 0 assert profile.friends_count == 0 assert profile.link_color == None assert profile.statuses_count == 0 assert profile.favorites_count == 0 assert profile.last_update == None assert profile.last_update_id == None assert profile.recent_updates == [] assert profile.tmp_avatar_path == None assert profile.protected == False assert profile.verified == False assert profile.muted == False
def __init__(self, username, account_id, protocol_id, password, auth, config=None): self.id_ = account_id # username-protocol_id self.username = username self.protocol_id = protocol_id if protocol_id == ProtocolType.TWITTER: self.protocol = twitter.Main(username, self.id_, auth) elif protocol_id == ProtocolType.IDENTICA: self.protocol = identica.Main(username, self.id_, auth) self.profile = Profile() self.profile.username = username self.profile.password = password self.friends = None self.columns = [] self.lists = None self.token = None self.logged_in = LoginStatus.NONE if config: self.config = config else: self.config = AccountConfig(account_id, password)
def test_get_user_profile(self, monkeypatch): profile = Profile() self.account.profile = profile result = [profile] monkeypatch.setattr(self.account, "get_profile", lambda x: profile) monkeypatch.setattr(self.account, "is_friend", lambda x: True) monkeypatch.setattr(self.core, "is_muted", lambda x: False) profile.id_ = "dummy" response = self.core.get_user_profile(self.acc_id) assert isinstance(response, Profile) assert response.id_, "dummy" profile.id_ = "user" response = self.core.get_user_profile(self.acc_id, "user") assert isinstance(response, Profile) assert response.id_, "user" assert response.followed_by, True assert not response.muted, True
def test_is_authenticated(self, monkeypatch): monkeypatch.setattr(self.account, 'profile', None) monkeypatch.setattr(self.account, 'id_', None) assert self.account.is_authenticated() == False monkeypatch.setattr(self.account, 'id_', '123') assert self.account.is_authenticated() == False profile = Profile() monkeypatch.setattr(self.account, 'profile', profile) monkeypatch.setattr(self.account, 'id_', None) assert self.account.is_authenticated() == False monkeypatch.setattr(self.account, 'id_', '123') assert self.account.is_authenticated() == True
def test_update_profile(self, monkeypatch): profile = Profile() monkeypatch.setattr(self.account, "update_profile", lambda w, x, y, z: profile) # TODO: Test with no params # response = self.core.update_profile(self.acc_id) # raise excetion response = self.core.update_profile(self.acc_id, fullname="Another fullname") assert response == profile response = self.core.update_profile(self.acc_id, bio="Dummy bio") assert response == profile response = self.core.update_profile(self.acc_id, url="http://crazy.url") assert response == profile response = self.core.update_profile(self.acc_id, location="Nowhere") assert response == profile response = self.core.update_profile(self.acc_id, "Another fullname", "http://crazy.url", "Dummy bio", "Nowhere") assert response == profile
def test_has_stored_passwwd(self, monkeypatch): account = Account.new("twitter") profile = Profile() profile.username = "******" account.profile = profile monkeypatch.setattr(self.core.accman, "get", lambda x: account) profile.password = None response = self.core.has_stored_passwd("foo") assert response == False profile.password = '' response = self.core.has_stored_passwd("foo") assert response == False profile.password = '******' response = self.core.has_stored_passwd("foo") assert response == True
def json_to_profile(self, response): if isinstance(response, list): profiles = [] for pf in response: profile = self.json_to_profile(pf) profiles.append(profile) return profiles else: profile = Profile() profile.id_ = str(response['id']) profile.account_id = self.account_id profile.fullname = response['name'] profile.username = response['screen_name'] profile.avatar = response['profile_image_url'] profile.location = response['location'] profile.url = response['url'] profile.bio = response['description'] profile.following = response['following'] profile.followers_count = response['followers_count'] profile.friends_count = response['friends_count'] profile.statuses_count = response['statuses_count'] profile.follow_request = response['follow_request_sent'] profile.favorites_count = response['favourites_count'] profile.protected = response['protected'] profile.verified = response['verified'] if response.has_key('status'): profile.last_update = response['status']['text'] profile.last_update_id = response['status']['id'] profile.link_color = ('#' + response['profile_link_color']) or Profile.DEFAULT_LINK_COLOR return profile
def json_to_profile(self, response): if isinstance(response, list): profiles = [] for pf in response: profile = self.json_to_profile(json_to_profile) profiles.append(profile) return profiles else: profile = Profile() profile.id_ = str(response['id']) profile.account_id = self.account_id profile.fullname = response['name'] profile.username = response['screen_name'] profile.avatar = response['profile_image_url'] profile.location = response['location'] profile.url = response['url'] profile.bio = response['description'] profile.following = response['following'] profile.followers_count = response['followers_count'] profile.friends_count = response['friends_count'] profile.statuses_count = response['statuses_count'] profile.favorites_count = response['favourites_count'] profile.protected = response['protected'] if response.has_key('status'): profile.last_update = response['status']['text'] profile.last_update_id = response['status']['id'] profile.link_color = Profile.DEFAULT_LINK_COLOR return profile
def test_update_profile_image(self, monkeypatch): profile = Profile() monkeypatch.setattr(self.account, "update_profile_image", lambda x: profile) response = self.core.update_profile_image(self.acc_id, "/path/to/ble") assert response == profile
def setup_class(self, monkeypatch): self.profile = Profile() self.profile.username = '******' self.profile.account_id = 'foo-twitter' self.profile.fullname = "Foo Bar"
def json_to_profile(self, response): if isinstance(response, list): profiles = [] for pf in response: profile = self.json_to_profile(json_to_profile) profiles.append(profile) return profiles else: profile = Profile() profile.id_ = str(response["id"]) profile.account_id = self.account_id profile.fullname = response["name"] profile.username = response["screen_name"] profile.avatar = response["profile_image_url"] profile.location = response["location"] profile.url = response["url"] profile.bio = response["description"] profile.following = response["following"] profile.followers_count = response["followers_count"] profile.friends_count = response["friends_count"] profile.statuses_count = response["statuses_count"] profile.favorites_count = response["favourites_count"] profile.protected = response["protected"] if "status" in response: profile.last_update = response["status"]["text"] profile.last_update_id = response["status"]["id"] profile.link_color = Profile.DEFAULT_LINK_COLOR return profile
def __init__(self): self.profile = Profile() self.friends = [] self.http = DummyHttp()