Skip to content

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradIT committed Oct 22, 2022
1 parent e0ce3aa commit 8fb738e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 41 deletions.
7 changes: 6 additions & 1 deletion Parler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ def add_missing_values(row):
row["Domain"] = "parler.com"
return row


def is_ok(data: dict) -> bool:
return (
"status" in data and \
data.get("status") == "success" and \
"data" in data
)
def check_login(func):
def wrapper(*args):
if not args[0].is_logged_in:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This **UNOFFICIAL** library designed to programatically fetch data from parler.c

~~This library supports the new (as of 2022-02-06) Parler `open-api` / logged-in endpoints. Both logged in and guest modes are supported.~~

**Show is back on!** Now this library supports the *even newer* (as of 2022-10-21) Parler `/v0/` and `/v0/public` endpoints. Same caveats, both logged in and guest modes are supported \#champagnepapi
**Show is back on!** Now this library supports the *even newer* (as of 2022-10-21) Parler `/v0/` and `/v0/public` endpoints. Same caveats, both logged in and guest modes are supported

# To do list:

Expand Down
22 changes: 11 additions & 11 deletions tests/test_feed.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Parler
from Parler import with_auth as authed
import os
from Parler import utils

p = Parler.Parler(debug=True)
au = authed.AuthSession(debug=False)

posts_per_feed_page = 20
trending_length = 8
trending_user_length = 6
posts_per_feed_page = 10
trending_length = 12
trending_user_length = 20


def test_get_feed():
assert os.getenv("PARLER_USERNAME") is not None
Expand All @@ -16,6 +18,7 @@ def test_get_feed():
identifier=os.getenv("PARLER_USERNAME"), password=os.getenv("PARLER_PASSWORD")
)
assert au.is_logged_in
assert utils.is_ok(au.feed())
r1 = au.feed()["data"]
r2 = au.feed(False, 2, False)["data"]
r3 = au.feed(False, 3, False)["data"]
Expand All @@ -26,9 +29,9 @@ def test_get_feed():

# deep dive: get IDs of each post in user feed, sort alphabetically, compare against n+1

fp1 = [x.get("primary").get("uuid") for x in r1]
fp2 = [x.get("primary").get("uuid") for x in r2]
fp3 = [x.get("primary").get("uuid") for x in r3]
fp1 = [x.get("postuuid") for x in r1]
fp2 = [x.get("postuuid") for x in r2]
fp3 = [x.get("postuuid") for x in r3]

fp1.sort()
fp2.sort()
Expand All @@ -37,13 +40,10 @@ def test_get_feed():
assert fp1 != fp2
assert fp2 != fp3


def test_trending():
assert len(p.trending("today")["data"]) == trending_length
assert len(p.trending("top")["data"]) == trending_length

def test_discover_feed():
r = p.discover_feed()
assert len(r["data"]) >= posts_per_feed_page

def test_trending_users():
assert os.getenv("PARLER_USERNAME") is not None
Expand All @@ -52,4 +52,4 @@ def test_trending_users():
identifier=os.getenv("PARLER_USERNAME"), password=os.getenv("PARLER_PASSWORD")
)
assert au.is_logged_in
assert len(au.trending_users()) == trending_user_length
assert len(au.trending_users().get("data")) == trending_user_length
15 changes: 5 additions & 10 deletions tests/test_post.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import Parler
from Parler import with_auth as authed
import os
from Parler import utils

p = Parler.Parler(debug=True)
au = authed.AuthSession(debug=False)


def test_get_post():
r = p.post_info("ef4d02fe-7a5a-4ab4-8e82-7c0ee5e32960")
assert r.get("status") == "ok"

assert "uuid" in r.get("data")[0].get("primary")
assert utils.is_ok(r)
assert "postuuid" in r.get("data")
assert (
r.get("data")[0].get("primary").get("uuid")
r.get("data").get("postuuid")
== "ef4d02fe-7a5a-4ab4-8e82-7c0ee5e32960"
)
assert "id" in r.get("data")[0].get("primary")
assert "uuid" in r.get("data")[0].get("primary")
assert "body" in r.get("data")[0].get("primary")
assert "full_body" in r.get("data")[0].get("primary")
assert "image" in r.get("data")[0].get("primary")
assert "domain_name" in r.get("data")[0].get("primary")
assert "body" in r.get("data")
51 changes: 33 additions & 18 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from Parler import with_auth as authed
import os
import random
from Parler import utils

p = Parler.Parler(debug=True)
au = authed.AuthSession(debug=False)

posts_per_user = 20
search_hits_per_page = 50
posts_per_user = 10
search_hits_per_page = 10

badge_types = [
"gold",
Expand All @@ -24,25 +25,40 @@ def test_get_profile():
r = p.profile("TheWesternJournal").get("data")
assert r is not None
assert "username" in r
assert "dateCreated" in r
assert (
"uuid" in r and r.get("uuid") == "40f28d1a-ee94-4d6f-ad9a-ed4cd3a39228"
) # https://web.archive.org/web/20220213155807/https://parler.com/open-api/parley.php
assert "bio" in r
assert "website" in r
assert "location" in r
assert "joinedAt" in r
assert "joined_date" in r
assert "birthday" in r
assert "gender" in r
assert "real_name" in r
assert "joined_date" in r
assert "following_count" in r
assert "follower_count" in r
assert "is_private" in r
assert "is_public" in r


def test_get_profile_feed():
r = p.user_feed(username="TheWesternJournal")
assert utils.is_ok(r)

assert len(r.get("data")) == posts_per_user # posts per user
assert "id" in r.get("data")[0].get("primary")
assert "uuid" in r.get("data")[0].get("primary")
assert "body" in r.get("data")[0].get("primary")
assert "full_body" in r.get("data")[0].get("primary")
assert "image" in r.get("data")[0].get("primary")
assert "domain_name" in r.get("data")[0].get("primary")
assert "postuuid" in r.get("data")[0]
assert "body" in r.get("data")[0]
assert "title" in r.get("data")[0]
assert "total_comments" in r.get("data")[0]
assert "upvotes" in r.get("data")[0]
assert "echos" in r.get("data")[0]
assert "views" in r.get("data")[0]
assert "is_echo" in r.get("data")[0]
assert "is_comment" in r.get("data")[0]
assert "link" in r.get("data")[0]
assert "trolling" in r.get("data")[0]
assert "ad" in r.get("data")[0]


def test_get_profile_feed_pagination():
Expand All @@ -59,9 +75,9 @@ def test_get_profile_feed_pagination():

# deep dive: get IDs of each post in user feed, sort alphabetically, compare against n+1

fp1 = [x.get("primary").get("uuid") for x in r1.get("data")]
fp2 = [x.get("primary").get("uuid") for x in r2.get("data")]
fp3 = [x.get("primary").get("uuid") for x in r3.get("data")]
fp1 = [x.get("postuuid") for x in r1.get("data")]
fp2 = [x.get("postuuid") for x in r2.get("data")]
fp3 = [x.get("postuuid") for x in r3.get("data")]

fp1.sort()
fp2.sort()
Expand All @@ -83,17 +99,16 @@ def test_login():

def test_search_users():
r = au.users("qanon")
assert len(r) == search_hits_per_page
assert utils.is_ok(r)

assert len(r.get("data")) == search_hits_per_page

# pick one at random

user = r[random.randint(0, search_hits_per_page - 1)]
user = r.get("data")[random.randint(0, search_hits_per_page - 1)]

assert "name" in user
assert "username" in user
assert "followed" in user
assert "profile_picture" in user

assert "badges" in user

for x in badge_types:
Expand Down

0 comments on commit 8fb738e

Please sign in to comment.