Skip to content
This repository has been archived by the owner on May 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #40 from lily-seabreeze/add-test-getting-messages
Browse files Browse the repository at this point in the history
add test for geting multiple messages
  • Loading branch information
kawa-kokosowa committed Jul 28, 2016
2 parents 56491e4 + b9c21b7 commit 09aa234
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions tests/msgboard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,25 @@ def test_get_wrong_user(self):
assert status == 404
assert name_response == no_name_fixture

def test_post(self):
def test_post(self, create_user=True):
"""Test creating a message.
"""

self.test_create_user()
if create_user:
self.test_create_user()

message_content = {"text": 'I am a message.'}
headers = self.make_base64_header("testuser", "testpass")
status, response = self.post('/message', headers=headers,
data=message_content)
assert status == 200

del response["created"]
del response["id"]
del response["user"]["created"]

post_fixture = {
"id": 1,
"text": 'I am a message.',
"user": {
"bio": None,
Expand All @@ -264,9 +266,37 @@ def test_post(self):
}
}

# you're getting NONE here because the user isn't created
assert post_fixture == response

# TODO: this test is lame and will only fetch one
# message through messages.
def test_get_messages(self):
self.test_post()
self.test_post(create_user=False)
self.test_post(create_user=False)
limit = msg.app.config['LIMITS_MESSAGES_GET_LIMIT']
message_range = {
"offset": 0,
"limit": limit,
}
status, response = self.get('/messages', data=message_range)
assert status == 200

post_fixture = {
"text": 'I am a message.',
"user": {
"bio": None,
"id": 1,
"username": 'testuser'
}
}

for message in response:
del message["created"]
del message["id"]
del message["user"]["created"]
assert post_fixture == message

def test_create_message_without_text(self):
"""Try to create a message without text.
Expand Down

0 comments on commit 09aa234

Please sign in to comment.