Пример #1
0
 def test_get_max_num(self, rf):
     assert self.modeladmin.get_max_num(rf.get('/'), None) is None
     assert self.modeladmin.get_max_num(
         rf.get('/'),
         LegalTextVersionFactory.create(valid_from=timezone.now() +
                                        timedelta(days=1))) is None
     assert self.modeladmin.get_max_num(
         rf.get('/'),
         LegalTextVersionFactory.create(valid_from=timezone.now())) == 0
Пример #2
0
 def test_readonly_fields(self, rf):
     assert 'content' not in self.modeladmin.get_readonly_fields(
         rf.get('/'), None)
     assert 'content' not in self.modeladmin.get_readonly_fields(
         rf.get('/'),
         LegalTextVersionFactory.create(valid_from=timezone.now() +
                                        timedelta(days=1)))
     assert 'content' in self.modeladmin.get_readonly_fields(
         rf.get('/'),
         LegalTextVersionFactory.create(valid_from=timezone.now()))
Пример #3
0
 def test_readonly_fields(self, rf):
     assert self.modeladmin.get_readonly_fields(rf.get('/'), None) == ()
     assert self.modeladmin.get_readonly_fields(
         rf.get('/'),
         LegalTextVersionFactory.create(valid_from=timezone.now() +
                                        timedelta(days=1))) == ()
     assert self.modeladmin.get_readonly_fields(
         rf.get('/'),
         LegalTextVersionFactory.create(
             valid_from=timezone.now())) == ('legaltext', 'valid_from',
                                             'rendered_content')
Пример #4
0
    def test_render_content_unbalanced_blocks(self):
        legal_text_version = LegalTextVersionFactory.create(
            content='Text [block:foo]Text Text [block:bar]Text bar[/block]')

        assert legal_text_version.render_content().replace('\n', '') == (
            '<p>Text [block:foo]Text Text [block:bar]Text bar[/block]</p>'
        )
Пример #5
0
    def test_save_checkbox(self):
        legal_text_version = LegalTextVersionFactory.create()
        checkbox_1 = LegalTextCheckboxFactory.create(legaltext_version=legal_text_version)
        checkbox_2 = LegalTextCheckboxFactory.create(legaltext_version=legal_text_version)

        assert checkbox_1.order == 1
        assert checkbox_2.order == 2
Пример #6
0
 def test_get_fieldsets(self, rf, admin_user):
     request = rf.get('/')
     request.user = admin_user
     assert self.modeladmin.get_fieldsets(
         request,
         None)[0][1]['fields'] == ['legaltext', 'valid_from', 'content']
     assert self.modeladmin.get_fieldsets(
         request,
         LegalTextVersionFactory.create(
             valid_from=timezone.now() +
             timedelta(days=1)))[0][1]['fields'] == [
                 'legaltext', 'valid_from', 'content'
             ]
     assert self.modeladmin.get_fieldsets(
         request, LegalTextVersionFactory.create(
             valid_from=timezone.now()))[0][1]['fields'] == (
                 'legaltext', 'valid_from', 'rendered_content')
Пример #7
0
    def test_current_version(self):
        legal_text = LegalTextFactory.create(name='Foo Bar Text', slug='foo-bar')

        LegalTextVersionFactory.create(
            legaltext=legal_text,
            valid_from=timezone.make_aware(datetime(2015, 1, 1, 10, 0)))
        version_present = LegalTextVersionFactory.create(
            legaltext=legal_text,
            valid_from=timezone.make_aware(datetime(2016, 1, 1, 10, 0)))
        LegalTextVersionFactory.create(
            legaltext=legal_text,
            valid_from=timezone.make_aware(datetime(2017, 1, 1, 10, 0)))

        version = LegalText.current_version('foo-bar')

        assert version.legaltext.slug == 'foo-bar'
        assert version.legaltext.name == 'Foo Bar Text'
        assert version.pk == version_present.pk
Пример #8
0
    def test_render_content_with_nested_block(self):
        legal_text_version = LegalTextVersionFactory.create(
            content='Text\n\n[block:foo]Text Text\n\n[block:bar]Text bar[/block][/block]')

        assert legal_text_version.render_content().replace('\n', '') == (
            '<p>Text</p><div class="legaltext-block legaltext-block-foo"><span id="foo">'
            '</span><p>Text Text</p><div class="legaltext-block legaltext-block-bar">'
            '<span id="bar"></span><p>Text bar</p></div></div>'
        )
Пример #9
0
    def test_checkbox_ordering(self):
        legal_text_version = LegalTextVersionFactory.create()
        checkbox_3 = LegalTextCheckboxFactory.create(
            legaltext_version=legal_text_version, order=3)
        checkbox_1 = LegalTextCheckboxFactory.create(
            legaltext_version=legal_text_version, order=1)
        checkbox_2 = LegalTextCheckboxFactory.create(
            legaltext_version=legal_text_version, order=2)
        qs = LegalTextCheckbox.objects.all()

        assert list(qs) == [checkbox_1, checkbox_2, checkbox_3]
Пример #10
0
 def test_add_form_initial(self, rf, admin_user):
     legal_text_version = LegalTextVersionFactory.create(content='foobar')
     request = rf.get('/',
                      data={'legaltext': legal_text_version.legaltext.pk})
     request.user = admin_user
     response = self.modeladmin.add_view(request)
     assert response.status_code == 200
     assert response.context_data['adminform'].form.initial == {
         'content': 'foobar',
         'legaltext': '1'
     }
Пример #11
0
 def test_export_legaltext_version_action(self, admin_client):
     legal_text_version = LegalTextVersionFactory.create(content='foobar')
     url = reverse('admin:legaltext_legaltextversion_changelist')
     data = {
         'action': 'export_legaltext_version',
         '_selected_action': [str(legal_text_version.pk)]
     }
     response = admin_client.post(url, data)
     assert response['Content-Type'] == 'application/zip'
     assert response['Content-Disposition'] == (
         'filename=legaltext_export_2016-01-02_09-21-55.zip')
Пример #12
0
    def test_render_content_with_multiline_block(self):
        legal_text_version = LegalTextVersionFactory.create(
            content='Text\n\n[block:foo]\nText **bar**\n\nfoo\n[/block]\n\n'
            'Text\n\n[block:bar]\nText bar\n[/block] lorem'
        )

        assert legal_text_version.render_content().replace('\n', '') == (
            '<p>Text</p><div class="legaltext-block legaltext-block-foo"><span id="foo">'
            '</span><p>Text <strong>bar</strong></p><p>foo</p></div><p>Text</p>'
            '<div class="legaltext-block legaltext-block-bar">'
            '<span id="bar"></span><p>Text bar</p></div><p>lorem</p>'
        )
Пример #13
0
    def test_get_current_version(self):
        legal_text = LegalTextFactory.create(name='Foo Bar Text', slug='foo-bar-test')

        LegalTextVersionFactory.create(
            legaltext=legal_text,
            valid_from=timezone.make_aware(datetime(2015, 1, 1, 10, 0)),
            content='Test content 1')
        version_present = LegalTextVersionFactory.create(
            legaltext=legal_text,
            valid_from=timezone.make_aware(datetime(2016, 1, 1, 10, 0)),
            content='Test content 2')
        LegalTextVersionFactory.create(
            legaltext=legal_text,
            valid_from=timezone.make_aware(datetime(2017, 1, 1, 10, 0)),
            content='Test content 3')

        version = legal_text.get_current_version()
        assert isinstance(version, LegalTextVersion)
        assert version.legaltext.slug == 'foo-bar-test'
        assert version.legaltext.name == 'Foo Bar Text'
        assert version.content == 'Test content 2'
        assert version.pk == version_present.pk
Пример #14
0
 def test_legaltext_name(self):
     legal_text_version = LegalTextVersionFactory.create(
         legaltext__name='foo')
     assert self.modeladmin.legaltext_name(legal_text_version) == 'foo'
Пример #15
0
 def test_rendered_content(self):
     legal_text_version = LegalTextVersionFactory.create(content='foo')
     assert self.modeladmin.rendered_content(
         legal_text_version) == legal_text_version.render_content()
Пример #16
0
 def test_render_content(self):
     legal_text_version = LegalTextVersionFactory.create(content='Text Text Text')
     assert legal_text_version.render_content() == '<p>Text Text Text</p>'
Пример #17
0
    def test_checkbox_order_unique(self):
        legal_text_version = LegalTextVersionFactory.create()
        LegalTextCheckboxFactory.create(legaltext_version=legal_text_version, order=5)

        with pytest.raises(IntegrityError):
            LegalTextCheckboxFactory.create(legaltext_version=legal_text_version, order=5)
Пример #18
0
 def test_str(self):
     legal_text_version = LegalTextVersionFactory.create(legaltext__name='Foo Bar Text')
     assert 'Foo Bar Text' in str(legal_text_version)
     assert '{0:%x}'.format(legal_text_version.valid_from) in str(legal_text_version)
Пример #19
0
 def test_name(self):
     legal_text_version = LegalTextVersionFactory.create(legaltext__name='Foo Bar Text')
     assert legal_text_version.name == 'Foo Bar Text'
Пример #20
0
 def setup(self):
     self.legal_text_version = LegalTextVersionFactory.create(content='foo')
     self.checkbox1 = LegalTextCheckboxFactory.create(
         legaltext_version=self.legal_text_version, content='cb1')
     self.checkbox2 = LegalTextCheckboxFactory.create(
         legaltext_version=self.legal_text_version, content='cb2')
Пример #21
0
 def test_get_initial_extra_change(self, rf):
     assert self.modeladmin.get_initial_extra(
         rf.get('/'), LegalTextVersionFactory.create()) == []