summaryrefslogtreecommitdiff
path: root/tests/custom_columns
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /tests/custom_columns
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
downloaddjango-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/custom_columns')
-rw-r--r--tests/custom_columns/models.py22
-rw-r--r--tests/custom_columns/tests.py65
2 files changed, 47 insertions, 40 deletions
diff --git a/tests/custom_columns/models.py b/tests/custom_columns/models.py
index 575ca99a18..378a001820 100644
--- a/tests/custom_columns/models.py
+++ b/tests/custom_columns/models.py
@@ -19,32 +19,32 @@ from django.db import models
class Author(models.Model):
- Author_ID = models.AutoField(primary_key=True, db_column='Author ID')
- first_name = models.CharField(max_length=30, db_column='firstname')
- last_name = models.CharField(max_length=30, db_column='last')
+ Author_ID = models.AutoField(primary_key=True, db_column="Author ID")
+ first_name = models.CharField(max_length=30, db_column="firstname")
+ last_name = models.CharField(max_length=30, db_column="last")
class Meta:
- db_table = 'my_author_table'
- ordering = ('last_name', 'first_name')
+ db_table = "my_author_table"
+ ordering = ("last_name", "first_name")
def __str__(self):
- return '%s %s' % (self.first_name, self.last_name)
+ return "%s %s" % (self.first_name, self.last_name)
class Article(models.Model):
- Article_ID = models.AutoField(primary_key=True, db_column='Article ID')
+ Article_ID = models.AutoField(primary_key=True, db_column="Article ID")
headline = models.CharField(max_length=100)
- authors = models.ManyToManyField(Author, db_table='my_m2m_table')
+ authors = models.ManyToManyField(Author, db_table="my_m2m_table")
primary_author = models.ForeignKey(
Author,
models.SET_NULL,
- db_column='Author ID',
- related_name='primary_set',
+ db_column="Author ID",
+ related_name="primary_set",
null=True,
)
class Meta:
- ordering = ('headline',)
+ ordering = ("headline",)
def __str__(self):
return self.headline
diff --git a/tests/custom_columns/tests.py b/tests/custom_columns/tests.py
index 20e649de03..32a48b4840 100644
--- a/tests/custom_columns/tests.py
+++ b/tests/custom_columns/tests.py
@@ -5,22 +5,25 @@ from .models import Article, Author
class CustomColumnsTests(TestCase):
-
@classmethod
def setUpTestData(cls):
cls.a1 = Author.objects.create(first_name="John", last_name="Smith")
cls.a2 = Author.objects.create(first_name="Peter", last_name="Jones")
cls.authors = [cls.a1, cls.a2]
- cls.article = Article.objects.create(headline="Django lets you build web apps easily", primary_author=cls.a1)
+ cls.article = Article.objects.create(
+ headline="Django lets you build web apps easily", primary_author=cls.a1
+ )
cls.article.authors.set(cls.authors)
def test_query_all_available_authors(self):
self.assertQuerysetEqual(
- Author.objects.all(), [
- "Peter Jones", "John Smith",
+ Author.objects.all(),
+ [
+ "Peter Jones",
+ "John Smith",
],
- str
+ str,
)
def test_get_first_name(self):
@@ -31,10 +34,11 @@ class CustomColumnsTests(TestCase):
def test_filter_first_name(self):
self.assertQuerysetEqual(
- Author.objects.filter(first_name__exact="John"), [
+ Author.objects.filter(first_name__exact="John"),
+ [
"John Smith",
],
- str
+ str,
)
def test_field_error(self):
@@ -54,43 +58,42 @@ class CustomColumnsTests(TestCase):
def test_get_all_authors_for_an_article(self):
self.assertQuerysetEqual(
- self.article.authors.all(), [
+ self.article.authors.all(),
+ [
"Peter Jones",
"John Smith",
],
- str
+ str,
)
def test_get_all_articles_for_an_author(self):
self.assertQuerysetEqual(
- self.a1.article_set.all(), [
+ self.a1.article_set.all(),
+ [
"Django lets you build web apps easily",
],
- lambda a: a.headline
+ lambda a: a.headline,
)
def test_get_author_m2m_relation(self):
self.assertQuerysetEqual(
- self.article.authors.filter(last_name='Jones'), [
- "Peter Jones"
- ],
- str
+ self.article.authors.filter(last_name="Jones"), ["Peter Jones"], str
)
def test_author_querying(self):
self.assertSequenceEqual(
- Author.objects.all().order_by('last_name'),
+ Author.objects.all().order_by("last_name"),
[self.a2, self.a1],
)
def test_author_filtering(self):
self.assertSequenceEqual(
- Author.objects.filter(first_name__exact='John'),
+ Author.objects.filter(first_name__exact="John"),
[self.a1],
)
def test_author_get(self):
- self.assertEqual(self.a1, Author.objects.get(first_name__exact='John'))
+ self.assertEqual(self.a1, Author.objects.get(first_name__exact="John"))
def test_filter_on_nonexistent_field(self):
msg = (
@@ -98,25 +101,29 @@ class CustomColumnsTests(TestCase):
"Author_ID, article, first_name, last_name, primary_set"
)
with self.assertRaisesMessage(FieldError, msg):
- Author.objects.filter(firstname__exact='John')
+ Author.objects.filter(firstname__exact="John")
def test_author_get_attributes(self):
- a = Author.objects.get(last_name__exact='Smith')
- self.assertEqual('John', a.first_name)
- self.assertEqual('Smith', a.last_name)
- with self.assertRaisesMessage(AttributeError, "'Author' object has no attribute 'firstname'"):
- getattr(a, 'firstname')
-
- with self.assertRaisesMessage(AttributeError, "'Author' object has no attribute 'last'"):
- getattr(a, 'last')
+ a = Author.objects.get(last_name__exact="Smith")
+ self.assertEqual("John", a.first_name)
+ self.assertEqual("Smith", a.last_name)
+ with self.assertRaisesMessage(
+ AttributeError, "'Author' object has no attribute 'firstname'"
+ ):
+ getattr(a, "firstname")
+
+ with self.assertRaisesMessage(
+ AttributeError, "'Author' object has no attribute 'last'"
+ ):
+ getattr(a, "last")
def test_m2m_table(self):
self.assertSequenceEqual(
- self.article.authors.all().order_by('last_name'),
+ self.article.authors.all().order_by("last_name"),
[self.a2, self.a1],
)
self.assertSequenceEqual(self.a1.article_set.all(), [self.article])
self.assertSequenceEqual(
- self.article.authors.filter(last_name='Jones'),
+ self.article.authors.filter(last_name="Jones"),
[self.a2],
)