Repository: django/django
File: tests/lookup/tests.py (Python)

Code before:
            "Unsupported lookup 'gt__lt' for DateTimeField or join on the field "
            "not permitted, perhaps you meant gt or gte?",
        ):
            Article.objects.filter(pub_date__gt__lt="blahblah")

        with self.assertRaisesMessage(
            FieldError,
            "Unsupported lookup 'gt__lt__foo' for DateTimeField or join"
            " on the field not permitted, perhaps you meant gt or gte?",
        ):
            Article.objects.filter(pub_date__gt__lt__foo="blahblah")

    def test_unsupported_lookups_custom_lookups(self):
        slug_field = Article._meta.get_field("slug")
        msg = (
            "Unsupported lookup 'lengtp' for SlugField or join on the field not "
            "permitted, perhaps you meant length?"
        )
        with self.assertRaisesMessage(FieldError, msg):
            with register_lookup(slug_field, Length):
                Article.objects.filter(slug__lengtp=20)

    def test_relation_nested_lookup_error(self):
        # An invalid nested lookup on a related field raises a useful error.
        msg = (
            "Unsupported lookup 'editor__name' for ForeignKey or join on the field not "
            "permitted."
        )
        with self.assertRaisesMessage(FieldError, msg):
            Article.objects.filter(author__editor__name="James")
        msg = (
            "Unsupported lookup 'foo' for ForeignKey or join on the field not "
            "permitted."
        )
        with self.assertRaisesMessage(FieldError, msg):
            Tag.objects.filter(articles__foo="bar")

    def test_unsupported_lookup_reverse_foreign_key(self):
        msg = (
            "Unsupported lookup 'title' for ManyToOneRel or join on the field not "
            "permitted."
        )
        with self.assertRaisesMessage(FieldError, msg):
            Author.objects.filter(article__title="Article 1")

    def test_unsupported_lookup_reverse_foreign_key_custom_lookups(self):
        msg = (
            "Unsupported lookup 'abspl' for ManyToOneRel or join on the field not "
            "permitted, perhaps you meant abspk?"
        )
        fk_field = Article._meta.get_field("author")

Review comment (suggestion):
We should make sure the error is being tested after the deprecation, perhaps:
```suggestion
    # RemovedInDjango70Warning: When the deprecation ends, replace with:
    # def test_values_list_flat_empty_error(self):
    #     msg = "'flat' is not valid when values_list is called with no fields."
    #     with self.assertRaisesMessage(TypeError, msg):
    #         Article.objects.values_list(flat=True)
    def test_values_list_flat_empty_warning(self):
```

Code after:
        args = ("name", "article__headline", "article__tag__name")
        self.assertSequenceEqual(
            Author.objects.values_list(*args).order_by(*args),
            [
                (self.au1.name, self.a1.headline, self.t1.name),
                (self.au1.name, self.a2.headline, self.t1.name),
                (self.au1.name, self.a3.headline, self.t1.name),
                (self.au1.name, self.a3.headline, self.t2.name),
                (self.au1.name, self.a4.headline, self.t2.name),
                (self.au2.name, self.a5.headline, self.t2.name),
                (self.au2.name, self.a5.headline, self.t3.name),
                (self.au2.name, self.a6.headline, self.t3.name),
                (self.au2.name, self.a7.headline, self.t3.name),
            ],
        )
        with self.assertRaises(TypeError):
            Article.objects.values_list("id", "headline", flat=True)

    # RemovedInDjango70Warning: When the deprecation ends, replace with:
    # def test_values_list_flat_empty_error(self):
    #     msg = (
    #         "'flat' is not valid when values_list is called with no fields."
    #     )
    #     with self.assertRaisesMessage(TypeError, msg):
    #         Article.objects.values_list(flat=True)
    def test_values_list_flat_empty_warning(self):
        msg = (
            "Calling values_list() with no field name and flat=True "
            "is deprecated. Pass an explicit field name instead, like "
            "'pk'."
        )
        with self.assertRaisesMessage(RemovedInDjango70Warning, msg):
            Article.objects.values_list(flat=True)

    def test_get_next_previous_by(self):
        # Every DateField and DateTimeField creates get_next_by_FOO() and
        # get_previous_by_FOO() methods. In the case of identical date values,
        # these methods will use the ID as a fallback check. This guarantees
        # that no records are skipped or duplicated.
        self.assertEqual(repr(self.a1.get_next_by_pub_date()), "<Article: Article 2>")
        self.assertEqual(repr(self.a2.get_next_by_pub_date()), "<Article: Article 3>")
        self.assertEqual(
            repr(self.a2.get_next_by_pub_date(headline__endswith="6")),
            "<Article: Article 6>",
        )
        self.assertEqual(repr(self.a3.get_next_by_pub_date()), "<Article: Article 7>")
        self.assertEqual(repr(self.a4.get_next_by_pub_date()), "<Article: Article 6>")
        with self.assertRaises(Article.DoesNotExist):
            self.a5.get_next_by_pub_date()
        self.assertEqual(repr(self.a6.get_next_by_pub_date()), "<Article: Article 5>")
        self.assertEqual(repr(self.a7.get_next_by_pub_date()), "<Article: Article 4>")