diff --git a/kepi/daemon/flavour.py b/kepi/daemon/flavour.py new file mode 100644 index 0000000..5f52d6a --- /dev/null +++ b/kepi/daemon/flavour.py @@ -0,0 +1,6 @@ +def flavour_to_message(flavour): + pass + +def message_to_flavour(message): + pass + diff --git a/test/daemon/test_flavour.py b/test/daemon/test_flavour.py new file mode 100644 index 0000000..34c25aa --- /dev/null +++ b/test/daemon/test_flavour.py @@ -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': '

Hello world!

', + '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": ( + "

Hello world!

", + ), + "contentMap": { + "en": "

Hello world!

", + }, + "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", + }, + )