Ejemplo n.º 1
0
 def test_post_ok_add_minimal(self):
     data = {
         'op': 'add',
         'file': (io.BytesIO(b'file content'), 'filename.txt'),
     }
     self.login(self.admin.name)
     rv = self.client.post(self.url, data=data, follow_redirects=True)
     assert 'zostały zaktualizowane' in rv.text
     assert Attachment.select().where(Attachment.page == self.page).count() == 1
Ejemplo n.º 2
0
 def test_post_ok_remove(self, mocker, attachment_factory):
     attachments = {
         'a1': attachment_factory(page=self.page, title='Załącznik 1'),
         'a2': attachment_factory(page=self.page, title='Załącznik 2'),
     }
     data = {
         'op': 'remove',
         'attachment': [attachments['a1'].pk],
     }
     fake_remove = mocker.Mock()
     mocker.patch('bip.admin.views.os.remove', fake_remove)
     self.login(self.admin.name)
     rv = self.client.post(self.url, data=data, follow_redirects=True)
     assert 'zostały zaktualizowane' in rv.text
     assert Attachment.select().where(Attachment.page == self.page).count() == 1
     assert (
         Attachment.get_or_none(Attachment.title == attachments['a1'].title)
     ) is None
     fake_remove.assert_called_once()
Ejemplo n.º 3
0
 def test_post_fail_add_invalid(self):
     data = {
         'op': 'add',
         'title': 'Tytuł załącznika 1',
         'description': 'Opis załącznika 1'
     }
     self.login(self.admin.name)
     rv = self.client.post(self.url, data=data, follow_redirects=True)
     assert 'zostały zaktualizowane' not in rv.text
     assert 'To pole jest wymagane.</div>' in rv.text
     assert Attachment.get_or_none(Attachment.page == self.page) is None
Ejemplo n.º 4
0
 def test_post_ok_add_full(self):
     data = {
         'op': 'add',
         'file': (io.BytesIO(b'file content'), 'filename.txt'),
         'title': 'Tytuł załącznika 1',
         'description': 'Opis załącznika 1'
     }
     self.login(self.admin.name)
     rv = self.client.post(self.url, data=data, follow_redirects=True)
     assert 'zostały zaktualizowane' in rv.text
     attachment = Attachment.get_or_none(Attachment.page == self.page)
     assert attachment is not None
     assert attachment.title == data['title']
     assert attachment.description == data['description']
Ejemplo n.º 5
0
 def test_detail_post(self, attachment_factory):
     title = 'Załącznik 1'
     attachment = attachment_factory(page=self.page, title=title)
     url = self.detail_url(attachment)
     new_title = 'Nowy tytuł'
     new_description = 'Nowy opis'
     data = {
         'title': new_title,
         'description': new_description,
     }
     self.login(self.admin_name)
     rv = self.client.post(url, data=data, follow_redirects=True)
     assert f'>{new_title}</a>' in rv.text
     attachment = Attachment.get_or_none(Attachment.pk == attachment.pk)
     assert attachment is not None
     assert attachment.description_html == markdown(new_description)
Ejemplo n.º 6
0
 def test_attach_ok(self, tmp_path, mocker, page_factory):
     actor = self.user
     mocker.patch('bip.cli.pages.commands.login_user',
                  mocker.Mock(return_value=actor))
     page = page_factory(created_by=actor, updated_by=actor)
     f = tmp_path / 'testfile.csv'
     f.write_text('c1,c2\nv1,v2')
     mocker.patch('bip.cli.pages.commands.click.confirm',
                  mocker.Mock(return_value=False))
     rv = self.runner.invoke(
         page_attach, ['-i', page.pk, '-f',
                       f.as_posix(), '-u', actor.name])
     assert rv.exit_code == 0
     assert 'został załączony do strony' in rv.output
     obj = Attachment.get_or_none(Attachment.page == page)
     assert obj is not None