mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed tests for refs #24767 on databases that don't support microseconds.
This commit is contained in:
		| @@ -20,6 +20,10 @@ lorem_ipsum = """ | |||||||
|     tempor incididunt ut labore et dolore magna aliqua.""" |     tempor incididunt ut labore et dolore magna aliqua.""" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def truncate_microseconds(value): | ||||||
|  |     return value if connection.features.supports_microsecond_precision else value.replace(microsecond=0) | ||||||
|  |  | ||||||
|  |  | ||||||
| class FunctionTests(TestCase): | class FunctionTests(TestCase): | ||||||
|  |  | ||||||
|     def test_coalesce(self): |     def test_coalesce(self): | ||||||
| @@ -117,7 +121,7 @@ class FunctionTests(TestCase): | |||||||
|         articles = Article.objects.annotate( |         articles = Article.objects.annotate( | ||||||
|             last_updated=Greatest('written', 'published'), |             last_updated=Greatest('written', 'published'), | ||||||
|         ) |         ) | ||||||
|         self.assertEqual(articles.first().last_updated, now) |         self.assertEqual(articles.first().last_updated, truncate_microseconds(now)) | ||||||
|  |  | ||||||
|     @skipUnlessDBFeature('greatest_least_ignores_nulls') |     @skipUnlessDBFeature('greatest_least_ignores_nulls') | ||||||
|     def test_greatest_ignores_null(self): |     def test_greatest_ignores_null(self): | ||||||
| @@ -170,7 +174,7 @@ class FunctionTests(TestCase): | |||||||
|                 Coalesce('published', past_sql), |                 Coalesce('published', past_sql), | ||||||
|             ), |             ), | ||||||
|         ) |         ) | ||||||
|         self.assertEqual(articles.first().last_updated, now) |         self.assertEqual(articles.first().last_updated, truncate_microseconds(now)) | ||||||
|  |  | ||||||
|     def test_greatest_all_null(self): |     def test_greatest_all_null(self): | ||||||
|         Article.objects.create(title="Testing with Django", written=timezone.now()) |         Article.objects.create(title="Testing with Django", written=timezone.now()) | ||||||
| @@ -212,7 +216,7 @@ class FunctionTests(TestCase): | |||||||
|         articles = Article.objects.annotate( |         articles = Article.objects.annotate( | ||||||
|             first_updated=Least('written', 'published'), |             first_updated=Least('written', 'published'), | ||||||
|         ) |         ) | ||||||
|         self.assertEqual(articles.first().first_updated, before) |         self.assertEqual(articles.first().first_updated, truncate_microseconds(before)) | ||||||
|  |  | ||||||
|     @skipUnlessDBFeature('greatest_least_ignores_nulls') |     @skipUnlessDBFeature('greatest_least_ignores_nulls') | ||||||
|     def test_least_ignores_null(self): |     def test_least_ignores_null(self): | ||||||
| @@ -265,7 +269,7 @@ class FunctionTests(TestCase): | |||||||
|                 Coalesce('published', future_sql), |                 Coalesce('published', future_sql), | ||||||
|             ), |             ), | ||||||
|         ) |         ) | ||||||
|         self.assertEqual(articles.first().last_updated, now) |         self.assertEqual(articles.first().last_updated, truncate_microseconds(now)) | ||||||
|  |  | ||||||
|     def test_least_all_null(self): |     def test_least_all_null(self): | ||||||
|         Article.objects.create(title="Testing with Django", written=timezone.now()) |         Article.objects.create(title="Testing with Django", written=timezone.now()) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user