Skip to content

Commit

Permalink
add more tests; fix type hint of is_record_type
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX committed Aug 27, 2023
1 parent 5a6d731 commit 1f84f77
Show file tree
Hide file tree
Showing 10 changed files with 459 additions and 231 deletions.
2 changes: 1 addition & 1 deletion atproto/xrpc_client/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def is_json(json_data: t.Union[str, bytes]) -> bool:
return False


def is_record_type(model: ModelBase, expected_type: t.Union[str, types.ModuleType]) -> bool:
def is_record_type(model: t.Union[ModelBase, DotDict], expected_type: t.Union[str, types.ModuleType]) -> bool:
"""Verify that the model is the expected Record type.
Args:
Expand Down
40 changes: 0 additions & 40 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,20 @@ def sync_main():
client = Client()
client.login(os.environ['USERNAME'], os.environ['PASSWORD'])

# post_ref = client.send_post(text='Hello World from Python!')

# We can put likes only with reference to the post. You need to create/get post first to be able to like it
# cid='bafyreidaszwnbzl65oqryswowxzrexlqfeoh47zhtvo65yv5wblosgdrkq' uri='at://did:plc:kvwvcn5iqfooopmyzvb4qzba/app.bsky.feed.like/3k5u5ammyg72r'
# r = client.like(models.ComAtprotoRepoStrongRef.Main(cid=post_ref.cid, uri=post_ref.uri))
# print(r)

feed = client.com.atproto.repo.get_record(
{'collection': 'app.bsky.feed.generator', 'repo': 'did:plc:2wqb5jjkxli4rcswpyb624xj', 'rkey': 'Filecoin'}
)
post = client.com.atproto.repo.get_record(
{'collection': 'app.bsky.feed.post', 'repo': 'test.marshal.dev', 'rkey': '3k2yihcrp6f2c'}
)
custom_post = client.com.atproto.repo.get_record(
{'collection': 'app.bsky.feed.post', 'repo': 'test.marshal.dev', 'rkey': '3k2yinh52ne2x'}
)
custom_like = client.com.atproto.repo.get_record(
{'collection': 'app.bsky.feed.like', 'repo': 'test.marshal.dev', 'rkey': '3k5u5ammyg72r'}
)
like = client.com.atproto.repo.get_record(
{'collection': 'app.bsky.feed.like', 'repo': 'test.marshal.dev', 'rkey': '3k5u7c7j7a52v'}
)
print(type(feed.value))
print(get_model_as_json(feed.value))
print(get_model_as_json(feed.value.avatar))

print(type(like.value))
print(type(post.value))
print(type(custom_like.value))
print(type(custom_post.value))
print(custom_post.value)
print(custom_like.value)

lexicon_correct_record = client.com.atproto.repo.get_record(
{'collection': 'app.bsky.feed.post', 'repo': 'test.marshal.dev', 'rkey': '3k2yihcrp6f2c'}
Expand All @@ -85,28 +67,6 @@ def sync_main():
print(extended_record.value.lol) # custom (out of lexicon) attribute
print(type(extended_record.value))

atproto_feed = client.com.atproto.repo.get_record(
{'collection': ids.AppBskyFeedGenerator, 'repo': 'marshal.dev', 'rkey': 'atproto'}
).value
print(atproto_feed)
print(atproto_feed.createdAt)
print(atproto_feed['createdAt'])
print(type(atproto_feed))

assert is_record_type(lexicon_correct_record.value, ids.AppBskyFeedPost) is True
assert is_record_type(lexicon_correct_record.value, ids.AppBskyFeedGenerator) is False

assert is_record_type(extended_record.value, ids.AppBskyFeedPost) is True
assert is_record_type(extended_record.value, ids.AppBskyFeedGenerator) is False
assert is_record_type(extended_record.value, models.AppBskyFeedPost) is True
assert is_record_type(extended_record.value, models.AppBskyFeedGenerator) is False
dict_model = get_model_as_dict(extended_record.value)
assert isinstance(dict_model, dict) is True

post_uri = 'at://did:plc:hbtuqflamm5j2i7yahtzsnue/app.bsky.feed.post/3k3ic43ucbq2f'
response = client.bsky.feed.get_post_thread({'uri': post_uri, 'depth': 1, 'parentHeight': 0})
assert response.thread.post.embed.py_type == 'app.bsky.embed.recordWithMedia#view'

exit(0)

# client.com.atproto.admin.get_moderation_actions()
Expand Down
4 changes: 2 additions & 2 deletions tests/models/fetch_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def main() -> None:
method='com.atproto.repo.get_record',
params={
'collection': 'app.bsky.feed.generator',
'repo': 'did:plc:2wqb5jjkxli4rcswpyb624xj',
'rkey': 'Filecoin',
'repo': 'marshal.dev',
'rkey': 'atproto',
},
),
Call(
Expand Down
18 changes: 9 additions & 9 deletions tests/models/test_data/feed_record.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"uri": "at://did:plc:2wqb5jjkxli4rcswpyb624xj/app.bsky.feed.generator/Filecoin",
"cid": "bafyreihd52t5wovnb634i7frncrzn4naussto5ksgehzpanrjtgrwa4lye",
"uri": "at://did:plc:s6jnht6koorxz7trghirytmf/app.bsky.feed.generator/atproto",
"cid": "bafyreifiexhek65jxj3ucz6y6zstj45rmtigybzygjkg6lretyqgtge5ai",
"value": {
"did": "did:web:filecoinbsky.com",
"did": "did:web:feed.atproto.blue",
"$type": "app.bsky.feed.generator",
"avatar": {
"$type": "blob",
"ref": {
"$link": "bafkreic4kwwb4zto7owfpmu7dyr7irvyuoghl2qnmlj7sawm2sakpsp2ji"
"$link": "bafkreignfeqych2ksvvqyyrrlbsiwb4jrrlhvfuxppgtn6wbqusfaqo35u"
},
"mimeType": "image/jpeg",
"size": 9826
"mimeType": "image/png",
"size": 40930
},
"createdAt": "2023-08-08T12:57:14.515280",
"description": "Filecoin Foundation Feed",
"displayName": "FilecoinFoundation"
"createdAt": "2023-07-20T10:17:40.298101",
"description": "Posts related to the protocol. Powered by The AT Protocol SDK for Python",
"displayName": "AT Protocol"
}
}
Loading

0 comments on commit 1f84f77

Please sign in to comment.