Skip to content

Commit

Permalink
fixed bug when thread is not defined in a message.
Browse files Browse the repository at this point in the history
  • Loading branch information
javipalanca committed Sep 27, 2018
1 parent 8dd448b commit 0127178
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions spade/message.py
Expand Up @@ -234,9 +234,10 @@ def prepare(self):
)
)

data.fields.append(forms_xso.Field(var="_thread_node",
type_=forms_xso.FieldType.TEXT_SINGLE,
values=[self.thread]))
if self.thread:
data.fields.append(forms_xso.Field(var="_thread_node",
type_=forms_xso.FieldType.TEXT_SINGLE,
values=[self.thread]))

data.title = SPADE_X_METADATA
msg.xep0004_data = [data]
Expand Down
13 changes: 13 additions & 0 deletions tests/test_message.py
Expand Up @@ -73,6 +73,19 @@ def test_body_with_languages():
assert new_msg.body == "Hello World"


def test_thread_empty():
msg = Message(thread=None)

assert msg.thread is None
assert msg.metadata == {}

aiomsg = msg.prepare()
for data in aiomsg.xep0004_data:
if data.title == SPADE_X_METADATA:
for field in data.fields:
assert field.var != "_thread_node"


def test_equal(message):
assert message == copy.copy(message)

Expand Down

0 comments on commit 0127178

Please sign in to comment.