Exemplo n.º 1
0
async def test_async_like_unlike_media(async_agent_account, delay, settings,
                                       shortcode):
    photo = Media(shortcode)

    assert await async_agent_account.like(photo, settings=settings)
    await asyncio.sleep(delay)
    assert await async_agent_account.unlike(photo, settings=settings)
Exemplo n.º 2
0
async def test_async_comment(async_agent_account, delay, settings, shortcode):
    media = Media(shortcode)
    comment = await async_agent_account.add_comment(media,
                                                    "test",
                                                    settings=settings)
    await asyncio.sleep(delay)

    assert await async_agent_account.delete_comment(comment, settings=settings)
Exemplo n.º 3
0
def test_get_comments(agent, delay, settings, count, shortcode):
    media = Media(shortcode)
    data, pointer = agent.get_comments(media,
                                       count=count,
                                       delay=delay,
                                       settings=settings)

    assert min(media.comments_count, count) == len(data)
    assert (pointer is None) == (media.comments_count <= count)
Exemplo n.º 4
0
async def test_async_get_comments_pointer(async_agent, delay, settings, count, shortcode):
    media = Media(shortcode)
    pointer = None
    data = []

    for _ in range(count):
        tmp, pointer = await async_agent.get_comments(media, pointer=pointer, settings=settings)
        await asyncio.sleep(delay)
        data.extend(tmp)

    assert (pointer is None) == (media.likes_count == len(data))
Exemplo n.º 5
0
def test_get_likes_pointer(agent_account, delay, settings, count, shortcode):
    media = Media(shortcode)
    pointer = None
    data = []

    for _ in range(count):
        tmp, pointer = agent_account.get_likes(media,
                                               pointer=pointer,
                                               settings=settings)
        sleep(delay)
        data.extend(tmp)

    assert (pointer is None) == (media.likes_count <= count)
Exemplo n.º 6
0
def test_clear_cache_comment(id):
    account = Account("test")
    media = Media("test")
    comment = Comment(id,
                      media=media,
                      owner=account,
                      text="test",
                      created_at=0)
    assert Comment.cache == {id: comment}

    Comment.clear_cache()
    assert Comment.cache == dict()
    assert Media.cache == {"test": media}
    assert Account.cache == {"test": account}
Exemplo n.º 7
0
def test_update_media(agent, settings, shortcode):
    media = Media(shortcode)
    data = agent.update(media, settings=settings)

    assert not data is None
    assert not media.id is None
    assert not media.code is None
    assert not media.date is None
    assert not media.likes_count is None
    assert not media.comments_count is None
    assert not media.comments_disabled is None
    assert not media.is_video is None
    assert not media.display_url is None
    assert not media.resources is None
    assert not media.is_album is None
Exemplo n.º 8
0
def get_post_likes(shortcode: str):
    """
    Collects likes from instagram post by shortcode
    """

    media = Media(shortcode)
    pointer = None
    for i in range(3):
        time.sleep(random.random() * 2)
        try:
            likes, pointer = AG.get_likes(media, pointer)
            # if pointer is None:
            #     return media.likes
        except (ConnectionError, InternetException) as e:
            delay = random.randint(20, 100)
            if not ("404" in repr(e)):
                print(e, f"Sleep for {delay} sec...")
                time.sleep(delay)
    return media.likes
Exemplo n.º 9
0
def test_clear_cache_media(id):
    media = Media(id)
    assert Media.cache == {id: media}

    Media.clear_cache()
    assert Media.cache == dict()
Exemplo n.º 10
0
async def test_async_get_likes(async_agent, settings, shortcode):
    media = Media(shortcode)
    data, _ = await async_agent.get_likes(media, settings=settings)

    assert media.likes_count >= len(data)
Exemplo n.º 11
0
def test_comment(agent_account, delay, settings, shortcode):
    media = Media(shortcode)
    comment = agent_account.add_comment(media, "test", settings=settings)
    sleep(delay)

    assert agent_account.delete_comment(comment, settings=settings)
Exemplo n.º 12
0
def test_like_unlike_media(agent_account, delay, settings, shortcode):
    photo = Media(shortcode)

    assert agent_account.like(photo, settings=settings)
    sleep(delay)
    assert agent_account.unlike(photo, settings=settings)