示例#1
0
 def _prepare_letters(self, letter_data):
     letters = []
     for created_on, created_by in letter_data:
         obj = LetterFactory(created_by=created_by)
         obj.created_on = make_aware(created_on)
         obj.save()
         letters.append(obj)
     return letters
示例#2
0
 def test_lr_new_letter_from_staff(self):
     l = LetterFactory(created_on=self.now + timedelta(days=2),
                       case=self.case,
                       created_by__is_staff=False)
     LetterFactory(created_on=self.now + timedelta(days=10),
                   case=self.case,
                   created_by__is_staff=True)
     self.assertEqual(Letter.objects.case(self.case).last_received(), l)
示例#3
0
 def _prepare_letters(self, letter_data):
     letters = []
     for created_on, created_by in letter_data:
         obj = LetterFactory(created_by=created_by)
         obj.created_on = make_aware(created_on)
         obj.save()
         letters.append(obj)
     return letters
示例#4
0
    def test_last_staff_send(self):
        l = LetterFactory(status='done', case=self.case, created_by__is_staff=True)
        self.assertEqual(Letter.objects.case(self.case).last_staff_send(), l)

        LetterFactory(status='staff', case=self.case, created_by__is_staff=True)
        self.assertEqual(Letter.objects.case(self.case).last_staff_send(), l)

        l2 = LetterFactory(status='done', case=self.case, created_by__is_staff=True)
        self.assertEqual(Letter.objects.case(self.case).last_staff_send(), l2)
示例#5
0
 def test_record_count(self):
     case = CaseFactory()
     LetterFactory.create_batch(size=25, case=case)
     admin_obj = CaseAdmin(Case, AdminSite())
     request = RequestFactory().get(reverse_lazy('admin:cases_case_changelist'))
     request.user = UserFactory(is_staff=True, is_superuser=True)
     qs = admin_obj.get_queryset(request)
     obj = qs.get(pk=case.pk)
     self.assertTrue(hasattr(obj, 'record_count'))
     self.assertEqual(admin_obj.record_count(obj), 25)
示例#6
0
 def test_render_as_html_decorates_text(self):
     text = "*italic* **bolded**\n# header1\n[link](www.google.pl)"
     html = ""
     letter = LetterFactory(text=text, html=html)
     if settings.RICH_TEXT_ENABLED:
         expected = '<pre><p><em>italic</em> <strong>bolded</strong></p>\n<h1>header1</h1>\n<p><a href="www.google.pl">link</a></p>\n</pre>'
     else:
         expected = "<{tag}><p>{text}</p>\n</{tag}>".format(tag="pre",
                                                            text=text)
     self.assertEqual(letter.render_as_html(), expected)
示例#7
0
 def _prepare_letters(self, letter_data, case):
     letters = []
     for accept, created_by, status in letter_data:
         obj = LetterFactory(created_by=created_by,
                             case=case,
                             status=status)
         obj.accept = make_aware(accept)
         obj.save()
         letters.append(obj)
     return letters
示例#8
0
 def _prepare_letters(self, letter_data, case):
     letters = []
     for accept, created_by, status in letter_data:
         obj = LetterFactory(created_by=created_by,
                             case=case,
                             status=status)
         obj.accept = make_aware(accept)
         obj.save()
         letters.append(obj)
     return letters
示例#9
0
 def test_lr_new_client_letter_update(self):
     l = LetterFactory(case=self.case,
                       created_by__is_staff=False)
     self.assertEqual(Letter.objects.case(self.case).last_received(), l)
     new = LetterFactory(case=self.case,
                         created_by__is_staff=False)
     self.assertEqual(Letter.objects.case(self.case).last_received(), new)
     t = self.now - timedelta(days=10)
     old = LetterFactory(created_on=t,
                         case=self.case,
                         created_by__is_staff=False)
     old.created_on = t
     old.save()
     self.assertEqual(Letter.objects.case(self.case).last_received(), new)
示例#10
0
class CaseAdminTestCase(AdminTestCaseMixin, TestCase):
    user_factory_cls = UserFactory
    factory_cls = CaseFactory
    model = Case

    def setUp(self):
        self.site = AdminSite()
        super().setUp()

    def assertIsValid(self, model_admin,
                      model):  # See django/tests/modeladmin/tests.py#L602
        admin_obj = model_admin(model, self.site)
        if django.VERSION > (1, 9):
            errors = admin_obj.check()
        else:
            errors = admin_obj.check(model)
        expected = []
        self.assertEqual(errors, expected)

    def test_is_valid(self):
        self.assertIsValid(CaseAdmin, Case)

    def test_record_count(self):
        case = CaseFactory()
        LetterFactory.create_batch(size=25, case=case)
        admin_obj = CaseAdmin(Case, AdminSite())
        request = RequestFactory().get(
            reverse_lazy("admin:cases_case_changelist"))
        request.user = UserFactory(is_staff=True, is_superuser=True)
        qs = admin_obj.get_queryset(request)
        obj = qs.get(pk=case.pk)
        self.assertTrue(hasattr(obj, "record_count"))
        self.assertEqual(admin_obj.record_count(obj), 25)
示例#11
0
 def _test_letter_for_user(self, staff, status, res):
     obj = LetterFactory(case__client__is_staff=staff, status=status)
     self.assertEqual(
         Record.objects.for_user(
             obj.case.client).filter(object_id=obj.pk).exists(),
         res,
     )
示例#12
0
 def test_lr_new_client_letter_update(self):
     l = LetterFactory(case=self.case, created_by__is_staff=False)
     self.assertEqual(Letter.objects.case(self.case).last_received(), l)
     new = LetterFactory(case=self.case, created_by__is_staff=False)
     self.assertEqual(Letter.objects.case(self.case).last_received(), new)
     t = self.now - timedelta(days=10)
     old = LetterFactory(created_on=t,
                         case=self.case,
                         created_by__is_staff=False)
     old.created_on = t
     old.save()
     self.assertEqual(Letter.objects.case(self.case).last_received(), new)
示例#13
0
 def _for_user(self, status, exists, is_superuser=False, is_staff=False):
     user = UserFactory(is_superuser=is_superuser, is_staff=is_staff)
     obj = LetterFactory(status=status, case__created_by=user)
     self.assertEqual(
         Letter.objects.for_user(user).filter(pk=obj.pk).exists(), exists)
示例#14
0
 def test_render_as_html_returns_html(self):
     text = "some text"
     html = "<pre>some_html</pre>"
     letter = LetterFactory(text=text, html=html)
     self.assertEqual(letter.render_as_html(), html)
示例#15
0
 def test_render_as_html_decorates_text(self):
     text = "some text"
     html = ""
     letter = LetterFactory(text=text, html=html)
     expected = "<{tag}>{text}</{tag}>".format(tag="pre", text=text)
     self.assertEqual(letter.render_as_html(), expected)
示例#16
0
 def test_for_user_letter_can_view(self):
     obj = LetterFactory()
     self.assertFalse(
         Record.objects.for_user(
             UserFactory()).filter(object_id=obj.pk).exists())
示例#17
0
 def test_with_record_count(self):
     obj = CaseFactory()
     LetterFactory.create_batch(size=25, case=obj)
     self.assertEqual(Case.objects.filter(pk=obj.pk).with_record_count().get().record_count, 25)
示例#18
0
 def setUp(self):
     self.object = LetterFactory(status=Letter.STATUS.staff)
     self.url = reverse("letters:send", kwargs={"pk": self.object.pk})
     self.user = UserFactory(is_staff=True, is_superuser=True)
     self.client.login(username=self.user.username, password="******")
示例#19
0
 def test_render_as_html_decorates_text(self):
     text = "some text"
     html = ""
     letter = LetterFactory(text=text, html=html)
     expected = "<{tag}>{text}</{tag}>".format(tag="pre", text=text)
     self.assertEqual(letter.render_as_html(), expected)
示例#20
0
 def test_with_record_count(self):
     obj = CaseFactory()
     LetterFactory.create_batch(size=25, case=obj)
     self.assertEqual(
         Case.objects.filter(
             pk=obj.pk).with_record_count().get().record_count, 25)
示例#21
0
 def test_render_as_html_returns_html(self):
     text = "some text"
     html = "<pre>some_html</pre>"
     letter = LetterFactory(text=text, html=html)
     self.assertEqual(letter.render_as_html(), html)