~netlandish/django-wiki

10c66919a86883a91a71d75f1a7fa0ff58bd4c8d — Mads Jensen 5 years ago fd5b421
Changed assertTrue/assertFalse to better test methods.

assertTrue and assertFalse should not be used to test for not None or None
values.
M tests/core/test_accounts.py => tests/core/test_accounts.py +2 -6
@@ 86,9 86,7 @@ class LogoutViewTests(RequireRootArticleMixin, DjangoClientTestBase):
    def test_logout_account_handling(self):
        self.client.get(wiki_settings.LOGOUT_URL)
        user = auth.get_user(self.client)
        # Can be changed to assertIs(... False) when Django 1.11 is dropped
        # Django 1.11 returns CallableBoolean
        self.assertFalse(auth.get_user(self.client).is_authenticated)
        self.assertIs(auth.get_user(self.client).is_authenticated, False)
        self.assertIsInstance(user, AnonymousUser)




@@ 104,9 102,7 @@ class LoginTestViews(RequireRootArticleMixin, TestBase):
            wiki_settings.LOGIN_URL,
            {'username': SUPERUSER1_USERNAME, 'password': SUPERUSER1_PASSWORD}
        )
        # Can be changed to assertIs(... False) when Django 1.11 is dropped
        # Django 1.11 returns CallableBoolean
        self.assertTrue(self.superuser1.is_authenticated)
        self.assertIs(self.superuser1.is_authenticated, True)
        self.assertEqual(auth.get_user(self.client), self.superuser1)



M tests/core/test_models.py => tests/core/test_models.py +9 -9
@@ 38,17 38,17 @@ class ArticleModelTest(TestCase):

        a = Article.objects.create()

        self.assertFalse(a.current_revision)
        self.assertFalse(a.owner)
        self.assertFalse(a.group)
        self.assertIsNone(a.current_revision)
        self.assertIsNone(a.owner)
        self.assertIsNone(a.group)

        self.assertTrue(a.created)
        self.assertTrue(a.modified)
        self.assertIsNotNone(a.created)
        self.assertIsNotNone(a.modified)

        self.assertTrue(a.group_read)
        self.assertTrue(a.group_write)
        self.assertTrue(a.other_read)
        self.assertTrue(a.other_write)
        self.assertIsNotNone(a.group_read)
        self.assertIsNotNone(a.group_write)
        self.assertIsNotNone(a.other_read)
        self.assertIsNotNone(a.other_write)

    # XXX maybe redundant test
    def test_model_manager_class(self):

M tests/core/test_template_filters.py => tests/core/test_template_filters.py +12 -12
@@ 193,7 193,7 @@ class CanRead(TemplateTestCase):
        u = User.objects.create(username='Nobody', password='pass')

        output = can_read(a, u)
        self.assertTrue(output)
        self.assertIs(output, True)

        output = self.render({'article': a, 'user': u})
        self.assertIn('True', output)


@@ 205,7 205,7 @@ class CanRead(TemplateTestCase):
        u = User.objects.create(username='Noman', password='pass')

        output = can_read(a, u)
        self.assertFalse(output)
        self.assertIs(output, False)

        output = self.render({'article': a, 'user': u})
        self.assertIn('False', output)


@@ 226,7 226,7 @@ class CanWrite(TemplateTestCase):
        u = User.objects.create(username='Nobody', password='pass')

        output = can_write(a, u)
        self.assertTrue(output)
        self.assertIs(output, True)

        output = self.render({'article': a, 'user': u})
        self.assertIn('True', output)


@@ 238,7 238,7 @@ class CanWrite(TemplateTestCase):
        u = User.objects.create(username='Noman', password='pass')

        output = can_write(a, u)
        self.assertFalse(output)
        self.assertIs(output, False)

        output = self.render({'article': a, 'user': u})
        self.assertIn('False', output)


@@ 259,7 259,7 @@ class CanDelete(TemplateTestCase):
        u = User.objects.create(username='Nobody', password='pass')

        output = can_delete(a, u)
        self.assertTrue(output)
        self.assertIs(output, True)

        output = self.render({'article': a, 'user': u})
        self.assertIn('True', output)


@@ 271,7 271,7 @@ class CanDelete(TemplateTestCase):
        u = User.objects.create(username='Noman', password='pass')

        output = can_delete(a, u)
        self.assertFalse(output)
        self.assertIs(output, False)

        output = self.render({'article': a, 'user': u})
        self.assertIn('False', output)


@@ 292,7 292,7 @@ class CanModerate(TemplateTestCase):
        u = User.objects.create(username='Nobody', password='pass')

        output = can_moderate(a, u)
        self.assertTrue(output)
        self.assertIs(output, True)

        output = self.render({'article': a, 'user': u})
        self.assertIn('True', output)


@@ 303,7 303,7 @@ class CanModerate(TemplateTestCase):
        u = User.objects.create(username='Noman', password='pass')

        output = can_moderate(a, u)
        self.assertFalse(output)
        self.assertIs(output, False)

        output = self.render({'article': a, 'user': u})
        self.assertIn('False', output)


@@ 321,7 321,7 @@ class IsLocked(TemplateTestCase):
        a = Article.objects.create()

        output = is_locked(a)
        self.assertFalse(output)
        self.assertIsNone(output)

        output = self.render({'article': a})
        self.assertIn('None', output)


@@ 335,10 335,10 @@ class IsLocked(TemplateTestCase):
        ArticleRevision.objects.create(article=b)

        output = is_locked(a)
        self.assertFalse(output)
        self.assertIs(output, False)

        output = is_locked(b)
        self.assertFalse(output)
        self.assertIs(output, False)

        output = self.render({'article': a})
        self.assertIn('False', output)


@@ 349,7 349,7 @@ class IsLocked(TemplateTestCase):
        ArticleRevision.objects.create(article=a, locked=True)

        output = is_locked(a)
        self.assertTrue(output)
        self.assertIs(output, True)

        output = self.render({'article': a})
        self.assertIn('True', output)

M tests/core/test_views.py => tests/core/test_views.py +3 -3
@@ 508,9 508,9 @@ class SearchViewTest(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientT
        def contains_title(articles, title):
            return any(article.current_revision.title == title for article in articles)

        self.assertTrue(contains_title(articles, 'Test0'))
        self.assertFalse(contains_title(articles, 'Test1'))
        self.assertTrue(contains_title(articles, 'Subtest0'))
        self.assertIs(contains_title(articles, 'Test0'), True)
        self.assertIs(contains_title(articles, 'Test1'), False)
        self.assertIs(contains_title(articles, 'Subtest0'), True)

    def test_hierarchy_search_404(self):


M tests/plugins/images/test_views.py => tests/plugins/images/test_views.py +4 -4
@@ 51,7 51,7 @@ class ImageTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestB
            if isinstance(plugin_instance, ImagePlugin):
                plugin_index = cnt
                break
        self.assertTrue(plugin_index >= 0, "Image plugin not activated")
        self.assertGreaterEqual(plugin_index, 0, msg="Image plugin not activated")
        base_edit_url = reverse('wiki:edit', kwargs={'path': path})
        url = base_edit_url + '?f=form{0:d}'.format(plugin_index)
        filestream = self._create_gif_filestream_from_base64(self.test_data)


@@ 183,7 183,7 @@ class ImageTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestB
        image = models.Image.objects.get()
        self.assertEqual(models.Image.objects.count(), 1)
        self.assertEqual(image.current_revision.previous_revision.revision_number, before_edit_rev)
        self.assertTrue(image.current_revision.deleted)
        self.assertIs(image.current_revision.deleted, True)

        # RESTORE
        before_edit_rev = image.current_revision.revision_number


@@ 209,7 209,7 @@ class ImageTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestB
        image_revision = image.current_revision.imagerevision
        f_path = image_revision.image.file.name

        self.assertTrue(os.path.exists(f_path))
        self.assertIs(os.path.exists(f_path), True)

        response = self.client.post(
            reverse('wiki:images_purge', kwargs={


@@ 221,7 221,7 @@ class ImageTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestB
            response, reverse('wiki:images_index', kwargs={'path': ''})
        )
        self.assertEqual(models.Image.objects.count(), 0)
        self.assertFalse(os.path.exists(f_path))
        self.assertIs(os.path.exists(f_path), False)

    @wiki_override_settings(ACCOUNT_HANDLING=True)
    def test_login_on_revision_add(self):