Repository: browniebroke/django-codemod

Issue:
Codemodder: `django.utils.http.cookie_date()`
From Django 3.0 removals:

> django.utils.http.cookie_date() will be removed.

Deprecated [in Django 2.1](https://docs.djangoproject.com/en/2.1/releases/2.1/#deprecated-features-2-1):

> `django.utils.http.cookie_date()` is deprecated in favor of [`django.utils.http.http_date()`](https://docs.djangoproject.com/en/2.1/ref/utils/#django.utils.http.http_date), which follows the format of the latest RFC.




Discussion:

Resolving patch:
diff --git a/django_codemod/visitors/__init__.py b/django_codemod/visitors/__init__.py
--- a/django_codemod/visitors/__init__.py
+++ b/django_codemod/visitors/__init__.py
@@ -9,6 +9,7 @@
 )
 from .html import UnescapeEntitiesTransformer
 from .http import (
+    CookieDateTransformer,
     HttpRequestXReadLinesTransformer,
     HttpUrlQuotePlusTransformer,
     HttpUrlQuoteTransformer,
@@ -43,6 +44,7 @@
     "AssignmentTagTransformer",
     "AvailableAttrsTransformer",
     "ContextDecoratorTransformer",
+    "CookieDateTransformer",
     "FixedOffsetTransformer",
     "FloatRangeFormFieldTransformer",
     "FloatRangeModelFieldTransformer",
diff --git a/django_codemod/visitors/http.py b/django_codemod/visitors/http.py
--- a/django_codemod/visitors/http.py
+++ b/django_codemod/visitors/http.py
@@ -1,7 +1,7 @@
 from libcst import BaseExpression, Call
 from libcst import matchers as m
 
-from django_codemod.constants import DJANGO_2_0, DJANGO_3_0, DJANGO_4_0
+from django_codemod.constants import DJANGO_2_0, DJANGO_2_1, DJANGO_3_0, DJANGO_4_0
 from django_codemod.visitors.base import (
     BaseDjCodemodTransformer,
     BaseFuncRenameTransformer,
@@ -78,3 +78,12 @@ def leave_Call(self, original_node: Call, updated_node: Call) -> BaseExpression:
         if m.matches(updated_node, self.matcher):
             return updated_node.func.value
         return super().leave_Call(original_node, updated_node)
+
+
+class CookieDateTransformer(BaseFuncRenameTransformer):
+    """Replace `django.utils.http.cookie_date()` by `http_date`."""
+
+    deprecated_in = DJANGO_2_1
+    removed_in = DJANGO_3_0
+    rename_from = "django.utils.http.cookie_date"
+    rename_to = "django.utils.http.http_date"


Test patch:
diff --git a/tests/visitors/test_http.py b/tests/visitors/test_http.py
--- a/tests/visitors/test_http.py
+++ b/tests/visitors/test_http.py
@@ -1,6 +1,7 @@
 from parameterized import parameterized
 
 from django_codemod.visitors import (
+    CookieDateTransformer,
     HttpRequestXReadLinesTransformer,
     HttpUrlQuotePlusTransformer,
     HttpUrlQuoteTransformer,
@@ -160,3 +161,28 @@ def test_substitution_nested_attribute(self, attribute_name) -> None:
                 print(line)
         """
         self.assertCodemod(before, after)
+
+
+class TestCookieDateTransformer(BaseVisitorTest):
+    transformer = CookieDateTransformer
+
+    def test_noop(self):
+        before = after = """
+            from django.utils.http import http_date
+
+            http_date(12345)
+        """
+        self.assertCodemod(before, after)
+
+    def test_basic(self):
+        before = """
+            from django.utils.http import cookie_date
+
+            cookie_date(12345)
+        """
+        after = """
+            from django.utils.http import http_date
+
+            http_date(12345)
+        """
+        self.assertCodemod(before, after)