Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
    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
Esempio n. 4
0
    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"
Esempio n. 5
0
    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"
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
 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
Esempio n. 9
0
    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)
Esempio n. 10
0
    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
Esempio n. 11
0
    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
Esempio n. 12
0
    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
Esempio n. 13
0
    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
Esempio n. 14
0
    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
Esempio n. 15
0
 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
Esempio n. 16
0
    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
Esempio n. 17
0
 def setup_class(self, monkeypatch):
     self.profile = Profile()
     self.profile.username = '******'
     self.profile.account_id = 'foo-twitter'
     self.profile.fullname = "Foo Bar"
Esempio n. 18
0
 def setup_class(self, monkeypatch):
     self.profile = Profile()
     self.profile.username = '******'
     self.profile.account_id = 'foo-twitter'
     self.profile.fullname = "Foo Bar"
Esempio n. 19
0
 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
Esempio n. 20
0
 def __init__(self):
     self.profile = Profile()
     self.friends = []
     self.http = DummyHttp()