Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix localtime bug #487

Closed
wants to merge 2 commits into from
Closed

Conversation

ZahraEbrahimi01
Copy link
Contributor

fix #480 bug

@codecov
Copy link

codecov bot commented Dec 28, 2022

Codecov Report

Merging #487 (d97752f) into master (dff0dd0) will decrease coverage by 0.09%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master     #487      +/-   ##
==========================================
- Coverage   94.11%   94.01%   -0.10%     
==========================================
  Files          30       30              
  Lines         884      886       +2     
==========================================
+ Hits          832      833       +1     
- Misses         52       53       +1     
Impacted Files Coverage Δ
auditlog/mixins.py 90.35% <75.00%> (-0.73%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@hramezani
Copy link
Member

Thanks @ZahraEbrahimi01 for this patch 👍

Please

@nbensa
Copy link

nbensa commented Jan 26, 2023

Hello. I can provide a test case. I'm not sure if it is enough. Should it also test USE_TZ=True?

index 487a45d..beabe8d 100644
--- a/auditlog_tests/tests.py
+++ b/auditlog_tests/tests.py
@@ -1461,6 +1461,15 @@ class AdminPanelTest(TestCase):
                 created = self.admin.created(log_entry)
                 self.assertEqual(created.strftime("%Y-%m-%d %H:%M:%S"), timestamp)
 
+    @freezegun.freeze_time("2022-08-01 12:00:00Z")
+    def test_created_naive_datetime(self):
+        with self.settings(USE_TZ=False):
+            obj = SimpleModel.objects.create(text="For USE_TZ=False test")
+            log_entry = obj.history.latest()
+            created = self.admin.created(log_entry)
+            self.assertEqual(created.strftime("%Y-%m-%d %H:%M:%S"),
+                             "2022-08-01 12:00:00")
+
     def test_cid(self):
         self.client.force_login(self.user)
         expected_response = (

@hramezani
Copy link
Member

hramezani commented Jan 26, 2023

Hello @nbensa. Thanks for this. Yeah, this is enough I think.
@ZahraEbrahimi01 Could you please include the test in your patch?

@hramezani
Copy link
Member

Superseded by #511

@hramezani hramezani closed this Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

localtime() cannot be applied to a naive datetime
3 participants