Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalo-bulnes committed Jan 25, 2022
1 parent 681e8f1 commit bfa9f9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
13 changes: 7 additions & 6 deletions tests/state/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import unittest

from securedrop_client import state
from securedrop_client import state as local


class TestDebugging(unittest.TestCase):
def test_file_identifiers_are_distinguishable(self):
id = state.FileId("some file ID")
assert "downloaded" not in id.__repr__()
def test_files_can_be_downloaded(self):
file = local.File("some opaque identifier")
assert file.id == local.FileId("some opaque identifier")
assert not file.is_downloaded

id = state.DownloadedFileId("another file ID")
assert "downloaded" in id.__repr__()
file.is_downloaded = True
assert file.is_downloaded
35 changes: 10 additions & 25 deletions tests/state/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,25 @@ def test_conversation_files_is_empty_by_default(self):
assert len(self.state.conversation_files(2)) == 0

def test_conversation_files_returns_the_conversation_files(self):
self.state.update_or_insert_conversation(4, [1, 7, 3])
print(self.state)
self.state.add_file(4, 1)
self.state.add_file(4, 7)
self.state.add_file(4, 3)
assert len(self.state.conversation_files(4)) == 3

self.state.update_or_insert_conversation(4, [1, 7, 3, 8])
self.state.add_file(4, 8)
assert len(self.state.conversation_files(4)) == 4

self.state.update_or_insert_conversation(4, [9])
assert len(self.state.conversation_files(4)) == 1

def test_displays_the_selected_conversation(self):
self.state.update_or_insert_conversation(4, [1, 7, 3, 8])
assert "selected_conversation: None" in str(self.state)

self.state.set_selected_conversation(3)
assert "selected_conversation: 3" in str(self.state)

def test_displays_all_conversation_files(self):
self.state.set_selected_conversation(7)
assert "conversation_files: {}" in str(self.state)

self.state.update_or_insert_conversation(4, [1, 7, 3, 8])
assert "conversation_files: {4: [1, 7, 3, 8]}" in str(self.state)

def test_records_downloads(self):
some_file_id = state.FileId("X")
another_file_id = state.FileId("Y")
self.state.update_or_insert_conversation("4", [some_file_id, another_file_id])
self.state.add_file("4", some_file_id)
self.state.add_file("4", another_file_id)
files = self.state.conversation_files("4")
assert len(files) == 2
assert isinstance(files[0], state.FileId)
assert isinstance(files[1], state.FileId)
assert not files[0].is_downloaded
assert not files[1].is_downloaded

self.state.record_file_download(some_file_id)
assert len(files) == 2
assert isinstance(files[0], state.DownloadedFileId)
assert isinstance(files[1], state.FileId)
assert files[0].is_downloaded
assert files[1].is_downloaded

0 comments on commit bfa9f9c

Please sign in to comment.