Skip to content
Permalink
Browse files

Merge pull request #972 from atombrella/assert_methods

Changed assertTrue/assertFalse to better test methods.
  • Loading branch information...
benjaoming committed Sep 26, 2019
2 parents f790df4 + 10c6691 commit cccf6d5dd16545f15e1ead9de9aec631289553aa
@@ -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 @@ def test_log_in(self):
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)


@@ -38,17 +38,17 @@ def test_default_fields_of_empty_article(self):

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):
@@ -193,7 +193,7 @@ def test_user_have_permission(self):
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 @@ def test_user_dont_have_permission(self):
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 @@ def test_user_have_permission(self):
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 @@ def test_user_dont_have_permission(self):
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 @@ def test_user_have_permission(self):
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 @@ def test_user_dont_have_permission(self):
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 @@ def test_user_have_permission(self):
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 @@ def test_user_dont_have_permission(self):
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 @@ def test_no_current_revision(self):
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 @@ def test_have_current_revision_and_not_locked(self):
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 @@ def test_have_current_revision_and_locked(self):
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)
@@ -508,9 +508,9 @@ def test_hierarchy_search(self):
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):

@@ -51,7 +51,7 @@ def _create_test_image(self, path):
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 @@ def test_delete_restore_revision(self):
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 @@ def test_purge(self):
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 @@ def test_purge(self):
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):

0 comments on commit cccf6d5

Please sign in to comment.
You can’t perform that action at this time.