def setup_function(): Account.clear_cache() Comment.clear_cache() Location.clear_cache() Media.clear_cache() Story.clear_cache() Tag.clear_cache()
def setup_function(): Account.clear_cache() Media.clear_cache() Location.clear_cache() Tag.clear_cache() if not anon["global_delay"] is None: min_delay = anon["global_delay"].get("min", 0) max_delay = anon["global_delay"].get("max", 120) sleep(random() * (max_delay - min_delay) + min_delay)
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)
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)
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)
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))
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)
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}
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
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
def test_clear_cache_media(id): media = Media(id) assert Media.cache == {id: media} Media.clear_cache() assert Media.cache == dict()
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)
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)
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)