Refs #27546 -- Tested some __repr__() methods.

This commit is contained in:
Keda87 2016-11-29 12:54:17 +07:00 committed by Tim Graham
parent 78500102b7
commit 794b7d8033
5 changed files with 36 additions and 0 deletions

View File

@ -11,6 +11,7 @@ answer newbie questions, and generally made Django that much better:
Adam Johnson <https://github.com/adamchainz> Adam Johnson <https://github.com/adamchainz>
Adam Malinowski <http://adammalinowski.co.uk> Adam Malinowski <http://adammalinowski.co.uk>
Adam Vandenberg Adam Vandenberg
Adiyat Mubarak <adiyatmubarak@gmail.com>
Adrian Holovaty <adrian@holovaty.com> Adrian Holovaty <adrian@holovaty.com>
Adrien Lemaire <lemaire.adrien@gmail.com> Adrien Lemaire <lemaire.adrien@gmail.com>
Afonso Fernández Nogueira <fonzzo.django@gmail.com> Afonso Fernández Nogueira <fonzzo.django@gmail.com>

View File

@ -0,0 +1,13 @@
import os
from django.core.management.commands.makemessages import TranslatableFile
from django.test import SimpleTestCase
class TranslatableFileTests(SimpleTestCase):
def test_repr(self):
dirpath = 'dir'
file_name = 'example'
trans_file = TranslatableFile(dirpath=dirpath, file_name=file_name, locale_dir=None)
self.assertEqual(repr(trans_file), '<TranslatableFile: %s>' % os.path.join(dirpath, file_name))

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from datetime import date from datetime import date
from decimal import Decimal from decimal import Decimal
from django.db.models.query import RawQuerySet
from django.db.models.query_utils import InvalidQuery from django.db.models.query_utils import InvalidQuery
from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, skipUnlessDBFeature
@ -90,6 +91,11 @@ class RawQueryTests(TestCase):
self.assertTrue(hasattr(result, annotation)) self.assertTrue(hasattr(result, annotation))
self.assertEqual(getattr(result, annotation), value) self.assertEqual(getattr(result, annotation), value)
def test_rawqueryset_repr(self):
queryset = RawQuerySet(raw_query='SELECT * FROM raw_query_author')
self.assertEqual(repr(queryset), '<RawQuerySet: SELECT * FROM raw_query_author>')
self.assertEqual(repr(queryset.query), '<RawQuery: SELECT * FROM raw_query_author>')
def test_simple_raw_query(self): def test_simple_raw_query(self):
""" """
Basic test of raw query with a simple database query Basic test of raw query with a simple database query

View File

@ -0,0 +1,12 @@
from django.core.serializers.base import DeserializedObject
from django.test import SimpleTestCase
from .models import Author
class TestDeserializedObjectTests(SimpleTestCase):
def test_repr(self):
author = Author(name='John', pk=1)
deserial_obj = DeserializedObject(obj=author)
self.assertEqual(repr(deserial_obj), '<DeserializedObject: serializers.Author(pk=1)>')

View File

@ -45,3 +45,7 @@ class TestBaseConv(TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
BaseConverter('abc', sign='a') BaseConverter('abc', sign='a')
self.assertIsInstance(BaseConverter('abc', sign='d'), BaseConverter) self.assertIsInstance(BaseConverter('abc', sign='d'), BaseConverter)
def test_repr(self):
base7 = BaseConverter('cjdhel3', sign='g')
self.assertEqual(repr(base7), '<BaseConverter: base7 (cjdhel3)>')