-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
60 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
from flitter.flitter import Flitter | ||
from flitter.in_memory_message_store import InMemoryMessageStore | ||
|
||
|
||
def before_scenario(context, step): | ||
context.errorMessage = 'Unimplemented step. ' + \ | ||
'Please provide the implementation.' | ||
|
||
context.app = Flitter(message_store=InMemoryMessageStore()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class InMemoryMessageStore: | ||
def __init__(self): | ||
self.messages = [] | ||
|
||
def save(self, message): | ||
self.messages.append(message) | ||
|
||
def fetch_by_author(self, author): | ||
return self.messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Message: | ||
def __init__(self, author, text): | ||
self.author = author | ||
self.text = text | ||
|
||
def __repr__(self): | ||
return f'Message(author={self.author}, text={self.text})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from flitter.in_memory_message_store import InMemoryMessageStore | ||
from flitter.message import Message | ||
|
||
|
||
def test_fetch_by_author_returns_a_list(): | ||
store = InMemoryMessageStore() | ||
|
||
assert store.fetch_by_author('alice') == [] | ||
|
||
|
||
def test_fetch_by_author_returns_messages_by_the_author(): | ||
message1 = Message(author='alice', text='hi1') | ||
message2 = Message(author='alice', text='hi2') | ||
store = InMemoryMessageStore() | ||
|
||
store.save(message1) | ||
store.save(message2) | ||
|
||
messages = store.fetch_by_author('alice') | ||
|
||
assert message1 in messages, f'{message1} was not in {messages}' | ||
assert message2 in messages, f'{message2} was not in {messages}' |