Flavour stub and tests

commandline
Marnanel Thurman 2023-09-27 15:15:12 +01:00
rodzic 1c3a4733d8
commit a2c02abc2c
2 zmienionych plików z 118 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,6 @@
def flavour_to_message(flavour):
pass
def message_to_flavour(message):
pass

Wyświetl plik

@ -0,0 +1,112 @@
from kepi.daemon.flavour import (
flavour_to_message,
message_to_flavour,
)
from test import *
import pytest
def compare(flavour, message,
note = None,
non_normalised_messages = [],
):
assert flavour_to_message(flavour)==message, note
assert message_to_flavour(message)==flavour, note
for nnm in non_normalised_messages:
assert message_to_flavour(nnm)==flavour, note
def test_flavour_post():
compare(
flavour = {
'type': 'post',
'content': '<p>Hello world!</p>',
'activity-id': 'https://them.example.org/a1234',
'content-id': 'https://them.example.org/c5678',
'atom': 'https://them.example.org/c5678/atom',
'from': 'https://them.example.org/users/them',
'date': "Thu, 04 Apr 2019 21:56:50 GMT",
},
message = {
"actor": "https://them.example.org/users/them",
"to": [
"https://www.w3.org/ns/activitystreams#Public",
],
"cc": [
"https://them.example.org/users/them/followers",
"https://us.example.org/users/us",
],
"id": "https://them.example.org/a5678",
"object": {
"atomUri": "https://them.example.org/c5678/atom",
"attachment": [],
"attributedTo": "https://them.example.org/users/them",
"cc": [
"https://them.example.org/users/them/followers",
"https://us.example.org/users/us",
],
"content": (
"<p>Hello world!</p>",
),
"contentMap": {
"en": "<p>Hello world!</p>",
},
"conversation": (
"tag:them.example.org,2019-04-04:objectId=13169876:"
"objectType=Conversation"
),
"id": "https://them.example.org/101869969117276738",
"published": "2019-04-04T21:12:50Z",
"sensitive": False,
"summary": None,
"tag": [
{
"href": "https://us.example.org/users/us",
"name": "@us@us.example.org",
"type": "Mention"
}
],
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"type": "Note",
"url": "https://them.example.org/c5678",
},
"published": "2019-04-04T21:12:50Z",
"type": "Create",
}
)
def test_flavour_follow():
compare(
flavour = {
'type': 'follow',
'us': 'https://us.example.org/users/us',
'them': 'https://them.example.org/users/them',
},
message = {
"actor": "https://them.example.org/users/them",
"id": "https://them.example.org/c9876",
"object": "https://us.example.org/users/us",
"type": "Follow",
},
)
def test_flavour_unfollow():
compare(
flavour = {
'type': 'unfollow',
'us': 'https://us.example.org/users/us',
'them': 'https://them.example.org/users/them',
},
message = {
"actor": "https://us.example.org/users/them",
"id": "https://us.example.org/c5678",
"object": {
"actor": "https://them.example.org/users/them",
"id": "https://them.example.org/c9876",
"object": "https://us.example.org/users/us",
"type": "Follow",
},
"type": "Undo",
},
)