Skip to content

Commit

Permalink
tests: comments: Fix flaky sort order
Browse files Browse the repository at this point in the history
In isso/views/comments.py:feed() we are adding a "<thr:in-reply-to>"
element:
```
    ET.SubElement(entry, 'thr:in-reply-to', {
        'ref': '[...]',
        'href': '[...],
    })
```
This dict is unsorted an can be emitted in either order when generating
"/feed".

Fix this by normalizing the generated data with str.replace().

Fixes error(abridged):
```
Traceback (most recent call last):
  File "/home/user/isso/isso/tests/test_comments.py", line 389, in testFeed
    self.assertEqual(data, """<?xml version=\'1.0\' encoding=\'utf-8\'?>
AssertionError: '<?xm[537 chars]y-to ref="tag:example.org,2018:/isso/1/1" href[295 chars]eed>' \
  != '<?xm[537 chars]y-to href="https://example.org/path/#isso-1" r[295 chars]eed>'
```
  • Loading branch information
ix5 committed Dec 28, 2019
1 parent 56272c7 commit 1c6f955
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions isso/tests/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,15 @@ def testFeed(self):
data = rv.data.decode('utf-8')
data = re.sub('[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]+Z',
'2018-04-01T10:00:00Z', data)
self.assertEqual(data, """<?xml version=\'1.0\' encoding=\'utf-8\'?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0"><updated>2018-04-01T10:00:00Z</updated><id>tag:example.org,2018:/isso/thread/path/</id><title>Comments for example.org/path/</title><entry><id>tag:example.org,2018:/isso/1/2</id><title>Comment #2</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-2" /><content type="html">&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;&lt;/p&gt;</content><thr:in-reply-to href="https://example.org/path/#isso-1" ref="tag:example.org,2018:/isso/1/1" /></entry><entry><id>tag:example.org,2018:/isso/1/1</id><title>Comment #1</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-1" /><content type="html">&lt;p&gt;First&lt;/p&gt;</content></entry></feed>""")
# Since ElementTree.SubElement.attrib is a dict, it can be emitted in any order. Normalize:
data = data.replace(
'ref="tag:example.org,2018:/isso/1/1" href="https://example.org/path/#isso-1"',
'href="https://example.org/path/#isso-1" ref="tag:example.org,2018:/isso/1/1"',
1 # count
)
expected_data = """<?xml version=\'1.0\' encoding=\'utf-8\'?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0"><updated>2018-04-01T10:00:00Z</updated><id>tag:example.org,2018:/isso/thread/path/</id><title>Comments for example.org/path/</title><entry><id>tag:example.org,2018:/isso/1/2</id><title>Comment #2</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-2" /><content type="html">&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;&lt;/p&gt;</content><thr:in-reply-to href="https://example.org/path/#isso-1" ref="tag:example.org,2018:/isso/1/1" /></entry><entry><id>tag:example.org,2018:/isso/1/1</id><title>Comment #1</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-1" /><content type="html">&lt;p&gt;First&lt;/p&gt;</content></entry></feed>"""
self.assertEqual(data, expected_data)

def testCounts(self):

Expand Down

0 comments on commit 1c6f955

Please sign in to comment.