Exemple #1
0
def test_following_follow_unfollow(pgsql):
    users = PgUsers(pgsql)
    user = users.user(12345)
    user.following().follow(users.user(11111))
    assert [u.id() for u in user.following().users()] == [11111]
    user.following().unfollow(users.user(11111))
    assert [u.id() for u in user.following().users()] == []
Exemple #2
0
def test_follow_schedule_mark_rejected_nonexistent(pgsql):
    """
    Does nothing if record to be marked rejected is not present
    """
    users = PgUsers(pgsql)
    schedule = PgFollowSchedule(pgsql, users)
    schedule.mark_rejected(users.user(123), users.user(321))
Exemple #3
0
def test_follow_schedule_mark_rejected(pgsql):
    """
    should mark records as rejected
    """
    users = PgUsers(pgsql)
    schedule = PgFollowSchedule(pgsql, users)
    schedule.add_record(users.user(123), users.user(321))
    schedule.mark_rejected(users.user(123), users.user(321))
    assert list(schedule.users_to_be_followed(users.user(123))) == []
Exemple #4
0
def test_unfollow_schedule_add_record_already_not_following(pgsql):
    """
    Should raise AlreadyNotFollowing error when trying to add record
    for an already nonexistent relation
    """
    users = PgUsers(pgsql)
    user = users.user(123)
    with pytest.raises(AlreadyNotFollowing):
        PgUnfollowSchedule(pgsql, users).add_record(user, users.user(456))
Exemple #5
0
def test_follow_schedule_add_record_already_following(pgsql):
    """
    Should raise AlreadyFollowing error when trying to add record
    for an existing relation
    """
    users = PgUsers(pgsql)
    user = users.user(123)
    user.following().follow(users.user(456))
    with pytest.raises(AlreadyFollowing):
        PgFollowSchedule(pgsql, users).add_record(user, users.user(456))
Exemple #6
0
def test_unfollow_schedule_mark_rejected(pgsql):
    """
    should mark records as rejected
    """
    users = PgUsers(pgsql)
    user1, user2 = users.user(123), users.user(321)
    user1.following().follow(user2)
    schedule = PgUnfollowSchedule(pgsql, users)
    schedule.add_record(user1, user2)
    schedule.mark_rejected(user1, user2)
    assert list(schedule.users_to_be_unfollowed(user1)) == []
Exemple #7
0
def test_following(pgsql):
    users = PgUsers(pgsql)
    user = users.user(12345)
    user.following().update_following(
        [users.user(i) for i in range(400)]
    )
    assert {u.id() for u in user.following().users()} == set(range(400))
    user.following().update_following(
        [users.user(i) for i in range(20, 440)]
    )
    assert {u.id() for u in user.following().users()} == set(range(20, 440))
Exemple #8
0
def test_follow_schedule_add_record(pgsql):
    """
    Should add records correctly
    """
    users = PgUsers(pgsql)
    user = users.user(123)
    PgFollowSchedule(pgsql, users).add_record(user, users.user(456))
    PgFollowSchedule(pgsql, users).add_record(user, users.user(436),
                                              ("some_tag", ), 4)
    to_be_followed = PgFollowSchedule(pgsql, users).users_to_be_followed(user)
    ids = [u.id() for u in to_be_followed]
    assert len(ids) == 2
    assert set(ids) == {456, 436}
Exemple #9
0
def test_unfollow_schedule_mark_rejected_repeat(pgsql):
    """
    If a rejected record for given follow relation is present in db,
    attempts to schedule follow for the same two users will not succeed
    """
    users = PgUsers(pgsql)
    schedule = PgUnfollowSchedule(pgsql, users)
    user1, user2 = users.user(123), users.user(555)
    user1.following().follow(user2)
    schedule.add_record(user1, user2)
    schedule.mark_rejected(user1, user2)
    schedule.add_record(user1, user2)
    assert list(schedule.users_to_be_unfollowed(users.user(123))) == []
Exemple #10
0
def test_unfollow_schedule_mark_fulfilled_add_record(pgsql):
    """
    Should add records correctly
    """
    users = PgUsers(pgsql)
    user1 = users.user(123)
    user1.following().follow(users.user(456))
    user1.following().follow(users.user(436))
    schedule = PgUnfollowSchedule(pgsql, users)
    schedule.add_record(user1, users.user(456))
    schedule.add_record(user1, users.user(436), ("some_tag", ), 4)
    to_be_unfollowed = schedule.users_to_be_unfollowed(user1)
    ids = [u.id() for u in to_be_unfollowed]
    assert len(ids) == 2
    assert set(ids) == {456, 436}
Exemple #11
0
def test_simple_insta_user_save_info(pgsql):
    bot = Bot()
    users = PgUsers(pgsql)
    user = users.user(42)
    locations = PgLocations(pgsql)
    with patch.object(bot,
                      "get_user_info",
                      return_value=dict(
                          full_name="John",
                          username="******",
                          follower_count=100,
                          following_count=200,
                          media_count=5,
                          biography="Some bio text",
                          category="some_category_tag",
                      )) as get_user_info:
        SimpleInstaUser(bot, user, Mock(), Mock()).save_info()
    record = pgsql.exec("select * from users where id = 42")[0]
    assert record.username == "john_doe"
    assert record.name == "John"
    assert record.nfollowers == 100
    assert record.nfollows == 200
    assert record.posts_number == 5
    assert record.bio == "Some bio text"
    assert record.account_type == "some_category_tag"
    get_user_info.assert_called_once_with(42)
Exemple #12
0
def test_follow_schedule_mark_fulfilled_repeat(pgsql):
    """
    If a fulfilled record for given follow relation is present in db,
    attempts to schedule follow for the same two users will succeed
    """
    users = PgUsers(pgsql)
    schedule = PgFollowSchedule(pgsql, users)
    schedule.add_record(users.user(123), users.user(555))
    schedule.mark_fulfilled(users.user(123), users.user(555))
    schedule.add_record(users.user(123), users.user(555))
    assert list(schedule.users_to_be_followed(users.user(123))) == []
Exemple #13
0
def test_simple_insta_user_save_following(pgsql):
    bot = Bot()
    users = PgUsers(pgsql)
    user = users.user(42)
    with patch.object(bot,
                      "get_user_following",
                      return_value=(234, 342, 555, 99,
                                    100)) as get_user_following:
        SimpleInstaUser(bot, user, Mock(), Mock()).save_following()
    assert set(
        (u.id()
         for u in user.following().users())) == {234, 342, 555, 99, 100}
    get_user_following.assert_called_once_with(42, nfollows=1500)
Exemple #14
0
def test_simple_insta_user_save_following(pgsql):
    def make_user(id_: int) -> InstaUser:
        return SimpleInstaUser(bot,
                               PgUsers(pgsql).user(id_), make_user, make_posts)

    def make_posts(user: User) -> InstaUserPosts:
        pass

    bot = Bot()
    users = PgUsers(pgsql)
    user = users.user(42)
    with patch.object(bot,
                      "get_user_followers",
                      return_value=(234, 342, 555, 99,
                                    100)) as get_user_followers:
        SimpleInstaUser(bot, user, make_user, make_posts).save_followers()
    assert set(
        (u.id()
         for u in user.followers().users())) == {234, 342, 555, 99, 100}
    get_user_followers.assert_called_once_with(42, nfollows=2000)
def test_actions_followers_explored(pgsql):
    users = PgUsers(pgsql)
    users.user(1234)
    actions = PgActions(pgsql)
    actions.mark_followers_explored(1234)
    assert actions.followers_explored(1234)
def test_actions_posts_info_saved(pgsql):
    users = PgUsers(pgsql)
    users.user(1234)
    actions = PgActions(pgsql)
    actions.mark_posts_info_saved(1234)
    assert actions.posts_info_saved(1234)