I'm trying to retrieve posts from a database that mention a username in the post.
def post_list_mentions(db, usernick, limit=50): """Return a list of posts that mention usernick, ordered by date return at most limit posts (default 50)
Returns a list of tuples (id, timestamp, usernick, avatar, content)
"""
cursor = db.cursor()
query = '''SELECT id, timestamp, usernick, avatar, content
FROM posts INNER JOIN users ON posts.usernick = users.nick
WHERE content LIKE ?
ORDER BY timestamp LIMIT ?'''
cursor.execute(query, ['%'+usernick+'%', limit])
list = cursor.fetchall()
When u unit test this code with:
def test_post_list_mentions(self): """Test getting a list of posts mentioning a user"""
user1 = 'Contrary'
user2 = 'Bobalooba'
user3 = 'Mandible'
posts = interface.post_list_mentions(self.db, usernick=user1)
# should include only posts with @Contrary
self.assertEqual(2, len(posts))
self.assertListEqual([2, 5], [p[0] for p in posts])
i get the error:
line 67, in test_post_list_mentions self.assertListEqual([2, 5], [p[0] for p in posts]) AssertionError: Lists differ: [2, 5] != [5, 2]
First differing element 0: 2 5
- [2, 5]
- [5, 2]
i'm not quite sure what im doing wrong in this instance or what this error means.
Any help would be appreciated
Thanks,
CM
Aucun commentaire:
Enregistrer un commentaire