From d4cfeca0060198853f89c26a5d79a8f7bc0570a1 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 11 Oct 2016 12:09:37 -0400 Subject: [PATCH] Tested Model.get_next/prev_by_FIELD() on unsaved models. --- tests/model_regress/tests.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/model_regress/tests.py b/tests/model_regress/tests.py index 6c4cecf43b..23390c0d81 100644 --- a/tests/model_regress/tests.py +++ b/tests/model_regress/tests.py @@ -178,6 +178,13 @@ class ModelTests(TestCase): e.get_previous_by_when().when, datetime.datetime(2000, 1, 1, 6, 1, 1) ) + def test_get_next_prev_by_field_unsaved(self): + msg = 'get_next/get_previous cannot be used on unsaved objects.' + with self.assertRaisesMessage(ValueError, msg): + Event().get_next_by_when() + with self.assertRaisesMessage(ValueError, msg): + Event().get_previous_by_when() + def test_primary_key_foreign_key_types(self): # Check Department and Worker (non-default PK type) d = Department.objects.create(id=10, name="IT")