def test_raising_exception_still_tries_to_show_basics_to_the_user_interface( self): expected_enterprise = Enterprise(name="Example Enterprise") expected_contact_method = ContactMethod( contact_method_type=ContactMethodType.EMAIL, value="*****@*****.**") subject, user_interface = self.get_subject( expected_enterprise=expected_enterprise, expected_contact_method=expected_contact_method, expected_cover_section_title="Cover Section", expected_cover_section_body="Cover Section Body", expected_sections=[]) # noinspection PyUnreachableCode def dummy() -> Tuple[CommandType, Dict]: raise Exception() return CommandType.SHOW_COVER, {} subject.process_command(command_provider=dummy) self.assertEqual( user_interface.exception_basics, Basics(enterprise=Enterprise(name="Example Enterprise"), contact_method=ContactMethod( contact_method_type=ContactMethodType.EMAIL, value="*****@*****.**")))
def test_show_section_shows_basics_to_the_user_interface(self): sections = [{"title": "A sub section", "body": "This is a subsection"}] expected_enterprise = Enterprise(name="Example Enterprise") expected_contact_method = ContactMethod(contact_method_type=ContactMethodType.EMAIL, value="*****@*****.**") subject, user_interface = self.get_subject(expected_enterprise=expected_enterprise, expected_contact_method=expected_contact_method, expected_cover_section_title="Cover Section Title", expected_cover_section_body="Cover Section Body", expected_sections=sections) subject.process_command(command_provider=lambda: (CommandType.SHOW_SECTION, {"identifier": 2})) expected_basics = Basics(enterprise=Enterprise(name="Example Enterprise"), contact_method=ContactMethod(contact_method_type=ContactMethodType.EMAIL, value="*****@*****.**")) self.assertEqual(expected_basics, user_interface.basics)
def test_unrecognized_command_behaves_like_unknown_command(self): sections = [{"title": "Another sub section", "body": "This is a subsection"}] expected_enterprise = Enterprise(name="Example Enterprise") expected_contact_method = ContactMethod(contact_method_type=ContactMethodType.EMAIL, value="*****@*****.**") subject, user_interface = self.get_subject(expected_enterprise=expected_enterprise, expected_contact_method=expected_contact_method, expected_cover_section_title="Cover Section Title", expected_cover_section_body="Cover Section Body", expected_sections=sections) subject.process_command(command_provider=lambda: (-1, {})) self.assertEqual(user_interface.unknown_basics, Basics(enterprise=Enterprise(name="Example Enterprise"), contact_method=ContactMethod( contact_method_type=ContactMethodType.EMAIL, value="*****@*****.**")))
def get_subject( expected_enterprise: Enterprise, expected_contact_method: ContactMethod, expected_cover_section_title: str, expected_cover_section_body: str, expected_sections: Iterable[Dict] ) -> Tuple[BrochureApplication, ReferenceUserInterface]: section_repository = ReferenceSectionRepository() cover_section_identifier = section_repository.create_cover_section( title=expected_cover_section_title, body=expected_cover_section_body) [ section_repository.create_section( parent_section_identifier=cover_section_identifier, **expected_section) for expected_section in expected_sections ] contact_method_fetcher = ReferenceContactMethodFetcher( **expected_contact_method._asdict()) enterprise_fetcher = ReferenceEnterpriseFetcher( **expected_enterprise._asdict()) user_interface = ReferenceUserInterface() application = BrochureApplication( contact_method_fetcher=contact_method_fetcher, section_repository=section_repository, enterprise_fetcher=enterprise_fetcher) application.register_user_interface(user_interface=user_interface) return application, user_interface
def test_show_cover_shows_basics_to_the_user_interface(self): expected_enterprise = Enterprise(name="Example Enterprise") expected_contact_method = ContactMethod( contact_method_type=ContactMethodType.EMAIL, value="*****@*****.**") subject, user_interface = self.get_subject( expected_enterprise=expected_enterprise, expected_contact_method=expected_contact_method, expected_cover_section_title="Cover Section", expected_cover_section_body="Cover Section Body", expected_sections=[]) subject.process_command( command_provider=lambda: (CommandType.SHOW_COVER, {})) self.assertEqual( user_interface.basics, Basics(enterprise=Enterprise(name="Example Enterprise"), contact_method=ContactMethod( contact_method_type=ContactMethodType.EMAIL, value="*****@*****.**")))
from brochure.values.enterprise import Enterprise from brochure_wsgi.deserializers.json_deserializer import JSONDeserializer from brochure_wsgi.value_fetchers.environment_variable_fetcher import EnvironmentVariableFetcher enterprise_json_deserializer = JSONDeserializer( deserializer=lambda eo: Enterprise(**eo)) environment_enterprise_fetcher = EnvironmentVariableFetcher( key="BROCHURE_ENTERPRISE", deserializer=enterprise_json_deserializer)