Ejemplo n.º 1
0
def setup_function():
    Account.clear_cache()
    Comment.clear_cache()
    Location.clear_cache()
    Media.clear_cache()
    Story.clear_cache()
    Tag.clear_cache()
Ejemplo n.º 2
0
def test_get_comments(web_agent, delay, count, shortcode):
    media = Media(shortcode)
    data, pointer = web_agent.get_comments(
        media,
        count=count,
        delay=delay,
    )

    assert min(media.comments_count, count) == len(data)
    assert (pointer is None) == (media.comments_count <= count)
Ejemplo n.º 3
0
def test_get_comments_pointer(web_agent, delay, count, shortcode):
    media = Media(shortcode)
    pointer = None
    data = []

    for _ in range(count):
        tmp, pointer = web_agent.get_comments(media, pointer=pointer)
        time.sleep(delay)
        data.extend(tmp)

    assert (pointer is None) == (media.likes_count == len(data))
Ejemplo n.º 4
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}
Ejemplo n.º 5
0
def test_comment_creation(id):
    account = Account("test")
    media = Media("test")
    comment = Comment(id,
                      media=media,
                      owner=account,
                      text="test",
                      created_at=0)
    assert getattr(comment, comment.primary_key) == id
    assert comment.media is media
    assert comment.owner is account
    assert comment.text == "test"
    assert comment.created_at == 0
    assert len(Comment.cache) == 1 and Comment.cache[id] is comment
Ejemplo n.º 6
0
def test_update_media(web_agent, shortcode):
    media = Media(shortcode)
    data = web_agent.update(media)

    assert data is not None
    assert media.id is not None
    assert media.code is not None
    assert media.date is not None
    assert media.likes_count is not None
    assert media.comments_count is not None
    assert media.comments_disabled is not None
    assert media.is_video is not None
    assert media.display_url is not None
    assert media.resources is not None
    assert media.is_album is not None
Ejemplo n.º 7
0
def test_clear_cache_media(id):
    media = Media(id)
    assert Media.cache == {id: media}

    Media.clear_cache()
    assert Media.cache == dict()
Ejemplo n.º 8
0
def teardown_function():
    Account.clear_cache()
    Media.clear_cache()
    Location.clear_cache()
    Tag.clear_cache()
Ejemplo n.º 9
0
def test_get_likes(web_agent, shortcode):
    media = Media(shortcode)
    data, _ = web_agent.get_likes(media)

    assert media.likes_count >= len(data)
Ejemplo n.º 10
0
def test_media_creation(id):
    media = Media(id)
    assert getattr(media, media.primary_key) == id
    assert len(Media.cache) == 1 and Media.cache[id] is media