First pass of model tests complete
This commit is contained in:
parent
d8f0beec43
commit
e14177c069
@ -5,6 +5,7 @@ from app.models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Accounts
|
||||||
def test_accounts_creation(session):
|
def test_accounts_creation(session):
|
||||||
"""Account creation"""
|
"""Account creation"""
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ def test_get_followed_accounts(session):
|
|||||||
assert acct2 in accts_followed
|
assert acct2 in accts_followed
|
||||||
|
|
||||||
|
|
||||||
|
# Hashtags
|
||||||
def test_hashtags_access(session):
|
def test_hashtags_access(session):
|
||||||
"""Test we can access hashtags table"""
|
"""Test we can access hashtags table"""
|
||||||
|
|
||||||
@ -62,7 +64,7 @@ def test_create_hashtag(session):
|
|||||||
assert ht.url == h_url
|
assert ht.url == h_url
|
||||||
|
|
||||||
|
|
||||||
def test_create_or_add_hashtag(session):
|
def test_get_or_create_hashtag(session):
|
||||||
"""Check we can retrieve existing hashtag"""
|
"""Check we can retrieve existing hashtag"""
|
||||||
|
|
||||||
h_name = "MyHashtag"
|
h_name = "MyHashtag"
|
||||||
@ -92,6 +94,7 @@ def test_get_followed_hashtags(session):
|
|||||||
assert hashtag2 in hashtags_followed
|
assert hashtag2 in hashtags_followed
|
||||||
|
|
||||||
|
|
||||||
|
# Posts
|
||||||
def test_create_posts(session):
|
def test_create_posts(session):
|
||||||
"""Test we can create posts"""
|
"""Test we can create posts"""
|
||||||
|
|
||||||
@ -115,3 +118,98 @@ def test_get_by_post_id(session):
|
|||||||
|
|
||||||
assert post is post1
|
assert post is post1
|
||||||
assert post is not post2
|
assert post is not post2
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_or_create_post(session):
|
||||||
|
"""Check we can retrieve existing post"""
|
||||||
|
|
||||||
|
post_id = "109666763623624576"
|
||||||
|
|
||||||
|
post = Posts.get_or_create(session, post_id)
|
||||||
|
post2 = Posts.get_or_create(session, post_id)
|
||||||
|
assert post is post2
|
||||||
|
|
||||||
|
|
||||||
|
def test_max_post_id_empty(session):
|
||||||
|
"""Test max_post_id with empty table"""
|
||||||
|
|
||||||
|
max_post_id = Posts.max_post_id(session)
|
||||||
|
assert max_post_id is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_max_post_id_one(session):
|
||||||
|
"""Test max_post_id with one entry"""
|
||||||
|
|
||||||
|
post_id = "109666763623624576"
|
||||||
|
post = Posts(session, post_id)
|
||||||
|
|
||||||
|
max_post_id = Posts.max_post_id(session)
|
||||||
|
assert max_post_id == post_id
|
||||||
|
|
||||||
|
|
||||||
|
def test_max_post_id_three(session):
|
||||||
|
"""Test max_post_id with three entries"""
|
||||||
|
|
||||||
|
post1_id = "109666763623624576"
|
||||||
|
post2_id = "209666763623624576" # highest ID
|
||||||
|
post3_id = "109666763623624577"
|
||||||
|
|
||||||
|
post1 = Posts(session, post1_id)
|
||||||
|
post2 = Posts(session, post2_id)
|
||||||
|
post3 = Posts(session, post3_id)
|
||||||
|
|
||||||
|
max_post_id = Posts.max_post_id(session)
|
||||||
|
assert max_post_id == post2_id
|
||||||
|
|
||||||
|
|
||||||
|
# PostTags
|
||||||
|
def test_add_hashtag_to_post(session):
|
||||||
|
"""Test adding a hashtag to a post"""
|
||||||
|
|
||||||
|
ht1 = "HashTagOne"
|
||||||
|
ht1_url = "https://one.example.com"
|
||||||
|
ht2 = "HashTagTwo"
|
||||||
|
ht2_url = "https://two.example.com"
|
||||||
|
|
||||||
|
hashtag1 = Hashtags.get_or_create(session, ht1, ht1_url)
|
||||||
|
hashtag2 = Hashtags.get_or_create(session, ht2, ht2_url)
|
||||||
|
|
||||||
|
post1_id = "109666763623624576"
|
||||||
|
post2_id = "209666763623624576"
|
||||||
|
post3_id = "109666763623624577"
|
||||||
|
|
||||||
|
post1 = Posts(session, post1_id)
|
||||||
|
post2 = Posts(session, post2_id)
|
||||||
|
post3 = Posts(session, post3_id)
|
||||||
|
|
||||||
|
post1.hashtags.append(hashtag2)
|
||||||
|
|
||||||
|
assert len(post1.hashtags) == 1
|
||||||
|
assert post1.hashtags[0] is hashtag2
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_two_hashtags_to_post(session):
|
||||||
|
"""Test adding two hashtags to a post"""
|
||||||
|
|
||||||
|
ht1 = "HashTagOne"
|
||||||
|
ht1_url = "https://one.example.com"
|
||||||
|
ht2 = "HashTagTwo"
|
||||||
|
ht2_url = "https://two.example.com"
|
||||||
|
|
||||||
|
hashtag1 = Hashtags.get_or_create(session, ht1, ht1_url)
|
||||||
|
hashtag2 = Hashtags.get_or_create(session, ht2, ht2_url)
|
||||||
|
|
||||||
|
post1_id = "109666763623624576"
|
||||||
|
post2_id = "209666763623624576"
|
||||||
|
post3_id = "109666763623624577"
|
||||||
|
|
||||||
|
post1 = Posts(session, post1_id)
|
||||||
|
post2 = Posts(session, post2_id)
|
||||||
|
post3 = Posts(session, post3_id)
|
||||||
|
|
||||||
|
post1.hashtags.append(hashtag2)
|
||||||
|
post1.hashtags.append(hashtag1)
|
||||||
|
|
||||||
|
assert len(post1.hashtags) == 2
|
||||||
|
assert hashtag1 in post1.hashtags
|
||||||
|
assert hashtag2 in post1.hashtags
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user