def test_before_render_hook(self): context = self.create_dummy() request = self.create_dummy() builder = self.mocker.mock() self.replay() layout = DefaultLayout(context, request, builder) layout.before_render_hook() packages = '\n'.join([ r'\usepackage[utf8]{inputenc}', r'\usepackage{ae,aecompl}', r'\usepackage[ngerman]{babel}', r'\usepackage{fancyhdr}', r'\usepackage[left=35mm, right=10mm, top=55mm, ' + \ r'bottom=10.5mm]{geometry}', r'\usepackage{graphicx}', r'\usepackage{lastpage}', r'\usepackage[neveradjust]{paralist}', r'\usepackage{textcomp}', r'\usepackage[absolute, overlay]{textpos}', r'\usepackage[compact]{titlesec}', r'\usepackage{wrapfig}', r'\usepackage{array,supertabular}', r'\usepackage{setspace}', '', ]) self.assertEqual(layout.get_packages_latex(), packages)
def test_get_render_arguments(self): context = self.mocker.mock() request = self.create_dummy() builder = self.create_dummy() member = self.mocker.mock() self.expect(context.Creator()).result('john.doe') self.expect( self.portal_membership.getMemberById('john.doe')).result(member) self.expect(member.getProperty('phone_number', ' ')).result('012 345 6789') self.replay() layout = DefaultLayout(context, request, builder) args = { 'client_title': FAKE_CLIENT_TITLE, 'member_phone': '012 345 6789', 'show_contact': False, 'show_logo': False, 'show_organisation': False, 'location': FAKE_LOCATION, } self.assertEqual(layout.get_render_arguments(), args)
def test_box_sizes_and_positions(self): context = self.stub() request = self.create_dummy() builder = self.stub() self.expect(builder.add_file('logo.pdf', data=ANY)) member = self.stub() self.expect(context.Creator()).result('john.doe') self.expect(self.portal_membership.getMemberById('john.doe')).result( member) self.expect(member.getProperty('phone_number', ' ')).result( '012 345 6789') self.replay() layout = DefaultLayout(context, request, builder) layout.show_organisation = True latex = layout.render_latex('LATEX CONTENT') self.assertIn(r'\begin{textblock}{58mm\TPHorizModule} ' r'(136mm\TPHorizModule', latex) self.assertIn(r'\begin{textblock}{100mm\TPHorizModule} ' r'(100mm\TPHorizModule, 10mm\TPVertModule)', latex)
def test_box_sizes_and_positions(self): context = self.stub() request = self.create_dummy() builder = self.stub() self.expect(builder.add_file('logo.pdf', data=ANY)) member = self.stub() self.expect(context.Creator()).result('john.doe') self.expect( self.portal_membership.getMemberById('john.doe')).result(member) self.expect(member.getProperty('phone_number', ' ')).result('012 345 6789') self.replay() layout = DefaultLayout(context, request, builder) layout.show_organisation = True latex = layout.render_latex('LATEX CONTENT') self.assertIn( r'\begin{textblock}{58mm\TPHorizModule} ' r'(136mm\TPHorizModule', latex) self.assertIn( r'\begin{textblock}{100mm\TPHorizModule} ' r'(100mm\TPHorizModule, 10mm\TPVertModule)', latex)
def test_get_render_arguments(self): context = self.mocker.mock() request = self.create_dummy() builder = self.create_dummy() member = self.mocker.mock() self.expect(context.Creator()).result('john.doe') self.expect(self.portal_membership.getMemberById('john.doe')).result( member) self.expect(member.getProperty('phone_number', ' ')).result( '012 345 6789') self.replay() layout = DefaultLayout(context, request, builder) args = { 'client_title': FAKE_CLIENT_TITLE, 'member_phone': '012 345 6789', 'show_contact': False, 'show_logo': False, 'show_organisation': False, 'location': FAKE_LOCATION, } self.assertEqual(layout.get_render_arguments(), args)
def setUp(self): super(TestDossierCoverRenderArguments, self).setUp() create( Builder('admin_unit').having( unit_id=u'OG', title=u'Department of forest & hunt', abbreviation=u'DoFH').as_current_admin_unit()) self.user = create_ogds_user('hugo.boss') self.repository = create( Builder('repository_root').having( version='Repository 2013 & 2014')) repofolder = create(Builder('repository').within(self.repository)) dossier = create( Builder('dossier').having(title=u'Foo & bar', responsible='hugo.boss', start=date(2013, 11, 1), end=date(2013, 12, 31)).within(repofolder)) provide_request_layer(dossier.REQUEST, IDossierCoverLayer) layout = DefaultLayout(dossier, dossier.REQUEST, PDFBuilder()) self.dossiercover = getMultiAdapter((dossier, dossier.REQUEST, layout), ILaTeXView)
def test_dossier_tasks_history(self, browser): repository = create(Builder('repository_root') .titled(u'Repository')) dossier = create(Builder('dossier') .titled(u'Anfr\xf6gen 2015') .within(repository) .having(responsible=self.user.userid)) browser.login().visit(dossier) factoriesmenu.add('Task') browser.fill({'Title': 'Task title', 'Task Type': 'To comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill(TEST_USER_ID) browser.find('Save').click() browser.open('http://nohost/plone/repository/dossier-1/task-1') browser.click_on("task-transition-open-resolved") browser.fill({'Response': 'response text'}) browser.click_on("Save") with provide_dossier_task_layer(dossier.REQUEST): layout = DefaultLayout(dossier, dossier.REQUEST, PDFBuilder()) dossiertasks = getMultiAdapter((dossier, dossier.REQUEST, layout), ILaTeXView) tasks_data = dossiertasks.get_render_arguments()['task_data_list'] self.assertEqual(1, len(tasks_data)) self.assertIn("response text", tasks_data[0]['history'])
def setUp(self): super(TestOpenTaskReport, self).setUp() self.user, self.org_unit, self.admin_unit = create( Builder('fixture').with_all_unit_setup()) self.hans = create( Builder('ogds_user').having(userid='hans.meier', firstname='Hans', lastname='Meier').assign_to_org_units( [self.org_unit])) create(Builder('user').with_userid('hans.meier')) self.peter = create( Builder('ogds_user').having(userid='peter.peter', firstname='Peter', lastname='Peter')) self.task = create( Builder("task").titled(u'Task 1').having( task_type='comment', issuer='peter.peter', responsible='hans.meier', responsible_client='org-unit-1', deadline=date(2014, 07, 01))) provide_request_layer(self.task.REQUEST, IOpenTaskReportLayer) layout = DefaultLayout(self.task, self.task.REQUEST, PDFBuilder()) self.opentaskreport = getMultiAdapter( (self.task, self.task.REQUEST, layout), ILaTeXView)
def test_shows_only_task_on_admin_unit(self): additional_admin_unit = create(Builder('admin_unit').id(u'additional')) create( Builder('org_unit').id(u'additional').having( admin_unit=additional_admin_unit)) successor = create( Builder('task').titled(u'Successor').successor_from( self.task).having(task_type='comment', issuer='peter.peter', responsible='hans.meier', responsible_client='org-unit-1', deadline=date(2014, 07, 01))) successor.get_sql_object().admin_unit_id = 'additional' layout = DefaultLayout(self.portal, self.request, None) view = OpenTaskReportLaTeXView(self.portal, self.request, layout) arguments = view.get_render_arguments() self.assertEqual([ '1 & Task 1 & To comment & & Client1 & Peter Peter & ' 'Org Unit 1 / Meier Hans & 01.07.2014 & task"=state"=open' ], arguments['outgoing']) self.assertEqual( [ '1 & Task 1 & To comment & & Client1 & Org Unit 1 / Peter ' 'Peter & Meier Hans & 01.07.2014 & task"=state"=open' ], arguments['incoming'], )
def test_journal_label(self, browser): dossier = create(Builder('dossier').titled(u'Anfr\xf6gen 2015')) provide_request_layer(dossier.REQUEST, IDossierJournalLayer) layout = DefaultLayout(dossier, dossier.REQUEST, PDFBuilder()) dossier_journal = getMultiAdapter((dossier, dossier.REQUEST, layout), ILaTeXView) self.assertEquals(u'Journal of dossier Anfr\xf6gen 2015 (Client1 / 1)', dossier_journal.get_render_arguments().get('label'))
def test_journal_label(self): self.login(self.regular_user) layout = DefaultLayout(self.dossier, self.request, PDFBuilder()) dossier_journal = getMultiAdapter((self.dossier, self.request, layout), ILaTeXView) self.assertEqual( 'Journal of dossier "`Vertr\xc3\xa4ge mit der kantonalen' ' Finanzverwaltung (Client1 1.1 / 1)"\'', dossier_journal.get_render_arguments().get('label'), )
def test_rendering(self): context = self.stub() request = self.create_dummy() builder = self.stub() self.expect(builder.add_file('logo.pdf', data=ANY)) member = self.stub() self.expect(context.Creator()).result('john.doe') self.expect(self.portal_membership.getMemberById('john.doe')).result( member) self.expect(member.getProperty('phone_number', ' ')).result( '012 345 6789') self.replay() layout = DefaultLayout(context, request, builder) latex = layout.render_latex('LATEX CONTENT') self.assertIn('LATEX CONTENT', latex) self.assertIn(layout.get_packages_latex(), latex) self.assertIn(r'\phantom{foo}\vspace{-2\baselineskip}', latex)
def test_rendering(self): context = self.stub() request = self.create_dummy() builder = self.stub() self.expect(builder.add_file('logo.pdf', data=ANY)) member = self.stub() self.expect(context.Creator()).result('john.doe') self.expect( self.portal_membership.getMemberById('john.doe')).result(member) self.expect(member.getProperty('phone_number', ' ')).result('012 345 6789') self.replay() layout = DefaultLayout(context, request, builder) latex = layout.render_latex('LATEX CONTENT') self.assertIn('LATEX CONTENT', latex) self.assertIn(layout.get_packages_latex(), latex) self.assertIn(r'\phantom{foo}\vspace{-2\baselineskip}', latex)
def test_dossier_tasks_label(self, browser): dossier = create(Builder('dossier').titled(u'Anfr\xf6gen 2015')) with provide_dossier_task_layer(dossier.REQUEST): layout = DefaultLayout(dossier, dossier.REQUEST, PDFBuilder()) dossier_tasks = getMultiAdapter( (dossier, dossier.REQUEST, layout), ILaTeXView) self.assertEquals( 'Task list for dossier "`Anfr\xc3\xb6gen 2015 (Client1 / 1)"\'', dossier_tasks.get_render_arguments().get('label'))
def test_configuration(self): context = self.create_dummy() request = self.create_dummy() builder = self.create_dummy() self.replay() layout = DefaultLayout(context, request, builder) self.assertEqual(layout.show_contact, False) self.assertEqual(layout.show_logo, False) self.assertEqual(layout.show_organisation, False)
def test_handle_special_white_space_characters(self): self.login(self.regular_user) self.dossier.title = u' '.join( (u'vertical\x0btab', self.dossier.title)) layout = DefaultLayout(self.dossier, self.request, PDFBuilder()) dossier_journal = getMultiAdapter((self.dossier, self.request, layout), ILaTeXView) self.assertEqual( 'Journal of dossier "`vertical tab Vertr\xc3\xa4ge mit der' ' kantonalen Finanzverwaltung (Client1 1.1 / 1)"\'', dossier_journal.get_render_arguments().get('label'), )
def test_journal_listing(self, browser): repo = create(Builder('repository')) with freeze(datetime(2016, 4, 12, 10, 35)): browser.login().open(repo) factoriesmenu.add('Business Case Dossier') browser.fill({'Title': u'Dossier A'}) browser.find('Save').click() dossier = browser.context factoriesmenu.add('Document') browser.fill({'Title': u'Document A'}) browser.find('Save').click() expected_date = DateTime() provide_request_layer(dossier.REQUEST, IDossierJournalLayer) layout = DefaultLayout(dossier, dossier.REQUEST, PDFBuilder()) dossierjournal = getMultiAdapter((dossier, dossier.REQUEST, layout), ILaTeXView) expected = [{ 'action': { 'visible': True, 'type': 'Dossier added', 'title': u'label_dossier_added' }, 'comments': '', 'actor': 'test_user_1_', 'time': expected_date }, { 'action': { 'visible': True, 'type': 'Document added', 'title': u'label_document_added' }, 'comments': '', 'actor': 'test_user_1_', 'time': expected_date }, { 'action': { 'visible': False, 'type': 'Dossier modified', 'title': u'label_dossier_modified' }, 'comments': '', 'actor': 'test_user_1_', 'time': expected_date }] self.assertEquals(expected, dossierjournal.get_journal_data())
def test_handle_complex_urls(self): self.login(self.regular_user) self.dossier.title = (u'https://example.com/some.php?get1=1234' '&weird_get_%5Bbracketed%5D=5678&somemore=blah' ) # Do not add commas above, this is a string! layout = DefaultLayout(self.dossier, self.request, PDFBuilder()) dossier_journal = getMultiAdapter((self.dossier, self.request, layout), ILaTeXView) self.assertEqual( 'Journal of dossier "`https://example.com""/some.php?get1=1234' '""\\&weird\\_get\\_\\%5Bbracketed\\%5D=5678' '""\\&somemore=blah (Client1 1.1 / 1)"\'', dossier_journal.get_render_arguments().get('label'), )
def setUp(self): super(TestDossierCoverRenderArguments, self).setUp() registry = getUtility(IRegistry) proxy = registry.forInterface(IBaseClientID) proxy.client_title = u'Department of forest & hunt' create_ogds_user('hugo.boss') self.repository = create( Builder('repository_root').having( version='Repository 2013 & 2014')) repofolder = create(Builder('repository').within(self.repository)) dossier = create( Builder('dossier').having(title=u'Foo & bar', responsible='hugo.boss', start=date(2013, 11, 1), end=date(2013, 12, 31)).within(repofolder)) provide_request_layer(dossier.REQUEST, IDossierCoverLayer) layout = DefaultLayout(dossier, dossier.REQUEST, PDFBuilder()) self.dossiercover = getMultiAdapter((dossier, dossier.REQUEST, layout), ILaTeXView)
def test_dossier_tasks_data(self, browser): repository = create(Builder('repository_root') .titled(u'Repository')) dossier = create(Builder('dossier') .titled(u'Anfr\xf6gen 2015') .within(repository) .having(responsible=self.user.userid)) subdossier = create(Builder('dossier') .within(dossier) .titled(u'Subdossier')) with freeze(datetime(2016, 4, 12, 10, 35)): task1 = create(Builder('task') .within(dossier) .having(responsible=self.user.userid, issuer=SITE_OWNER_NAME, title="task 1")) task2 = create(Builder('task') .within(subdossier) .having(responsible=self.user.userid, issuer=self.user.userid, title="task 2")) expected_deadline = datetime(2016, 4, 17, 0, 0) with freeze(datetime(2016, 10, 12, 13, 20)): api.content.transition(task1, to_state='task-state-resolved') completion_date = date.today() with provide_dossier_task_layer(dossier.REQUEST): layout = DefaultLayout(dossier, dossier.REQUEST, PDFBuilder()) dossiertasks = getMultiAdapter((dossier, dossier.REQUEST, layout), ILaTeXView) self.assertEquals([task1, task2], dossiertasks.get_tasks()) expected = {'label': 'Task list for dossier "`Anfr\xc3\xb6gen 2015 (Client1 / 1)"\'', 'task_data_list': [{'completion_date': completion_date.strftime('%d.%m.%Y'), 'deadline': expected_deadline.strftime('%d.%m.%Y'), 'description': '', 'responsible': 'Test User (test\\_user\\_1\\_)', 'issuer': 'admin (admin)', 'sequence_number': 1, 'title': 'task 1', 'type': ''}, {'completion_date': None, 'deadline': expected_deadline.strftime('%d.%m.%Y'), 'description': '', 'responsible': 'Test User (test\\_user\\_1\\_)', 'issuer': 'Test User (test\\_user\\_1\\_)', 'sequence_number': 2, 'title': 'task 2', 'type': ''}]} values = dossiertasks.get_render_arguments() # remove history attribute from the dicts, history is tested in # a separate test [item.pop('history') for item in values['task_data_list']] self.assertEquals(expected['label'], values['label']) self.assertEquals(expected['task_data_list'], values['task_data_list'])
def get_dossierdetails_view(self, dossier): provide_request_layer(dossier.REQUEST, IDossierDetailsLayer) layout = DefaultLayout(dossier, dossier.REQUEST, PDFBuilder()) return getMultiAdapter((dossier, dossier.REQUEST, layout), ILaTeXView)
def get_view(self, disposition): provide_request_layer(disposition.REQUEST, IRemovalProtocolLayer) layout = DefaultLayout(disposition, disposition.REQUEST, PDFBuilder()) return getMultiAdapter((disposition, disposition.REQUEST, layout), ILaTeXView)
def test_journal_listing(self): self.login(self.regular_user) layout = DefaultLayout(self.dossier, self.request, PDFBuilder()) dossier_journal = getMultiAdapter((self.dossier, self.request, layout), ILaTeXView) expected_journal = [ { 'action': { 'visible': True, 'type': 'Dossier added', 'title': u'label_dossier_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Document added', 'title': u'label_document_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Document added', 'title': u'label_document_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Document added', 'title': u'label_document_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Document added', 'title': u'label_document_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Document added', 'title': u'label_document_added', }, 'comments': '', 'actor': 'franzi.muller', }, { 'action': { 'visible': True, 'type': 'Task added', 'title': u'label_task_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task modified', 'title': u'label_task_modified', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task modified', 'title': u'label_task_modified', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task added', 'title': u'label_task_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task modified', 'title': u'label_task_modified', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task modified', 'title': u'label_task_modified', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task modified', 'title': u'label_task_modified', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task added', 'title': u'label_task_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task added', 'title': u'label_task_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Task added', 'title': u'label_task_added', }, 'comments': '', 'actor': 'robert.ziegler', }, { 'action': { 'visible': True, 'type': 'Document added', 'title': u'label_document_added', }, 'comments': '', 'actor': 'robert.ziegler', }, ] self.assertEqual(expected_journal, strip_timestamps(dossier_journal.get_journal_data()))