-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for
BaseContext
, Context
, ContextPopException
and…
… `RequestContext` compatibility imports removal
- Loading branch information
1 parent
1492be1
commit b3f58bd
Showing
4 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django_codemod.constants import DJANGO_1_7, DJANGO_3_1 | ||
from django_codemod.visitors.base import BaseRenameTransformer | ||
|
||
|
||
class BaseContextTransformer(BaseRenameTransformer): | ||
"""Replace `django.template.base.BaseContext` compatibility import.""" | ||
|
||
deprecated_in = DJANGO_1_7 | ||
removed_in = DJANGO_3_1 | ||
rename_from = "django.template.base.BaseContext" | ||
rename_to = "django.template.context.BaseContext" | ||
|
||
|
||
class ContextTransformer(BaseRenameTransformer): | ||
"""Replace `django.template.base.Context` compatibility import.""" | ||
|
||
deprecated_in = DJANGO_1_7 | ||
removed_in = DJANGO_3_1 | ||
rename_from = "django.template.base.Context" | ||
rename_to = "django.template.context.Context" | ||
|
||
|
||
class RequestContextTransformer(BaseRenameTransformer): | ||
"""Replace `django.template.base.RequestContext` compatibility import.""" | ||
|
||
deprecated_in = DJANGO_1_7 | ||
removed_in = DJANGO_3_1 | ||
rename_from = "django.template.base.RequestContext" | ||
rename_to = "django.template.context.RequestContext" | ||
|
||
|
||
class ContextPopExceptionTransformer(BaseRenameTransformer): | ||
"""Replace `django.template.base.ContextPopException` compatibility import.""" | ||
|
||
deprecated_in = DJANGO_1_7 | ||
removed_in = DJANGO_3_1 | ||
rename_from = "django.template.base.ContextPopException" | ||
rename_to = "django.template.context.ContextPopException" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from django_codemod.visitors import ( | ||
BaseContextTransformer, | ||
ContextPopExceptionTransformer, | ||
ContextTransformer, | ||
RequestContextTransformer, | ||
) | ||
from tests.visitors.base import BaseVisitorTest | ||
|
||
|
||
class TestBaseContextTransformer(BaseVisitorTest): | ||
|
||
transformer = BaseContextTransformer | ||
|
||
def test_simple_substitution(self) -> None: | ||
before = """ | ||
from django.template.base import BaseContext | ||
BaseContext({}) | ||
""" | ||
after = """ | ||
from django.template.context import BaseContext | ||
BaseContext({}) | ||
""" | ||
self.assertCodemod(before, after) | ||
|
||
|
||
class TestContextTransformer(BaseVisitorTest): | ||
|
||
transformer = ContextTransformer | ||
|
||
def test_simple_substitution(self) -> None: | ||
before = """ | ||
from django.template.base import Context | ||
Context({}) | ||
""" | ||
after = """ | ||
from django.template.context import Context | ||
Context({}) | ||
""" | ||
self.assertCodemod(before, after) | ||
|
||
|
||
class TestRequestContextTransformer(BaseVisitorTest): | ||
|
||
transformer = RequestContextTransformer | ||
|
||
def test_simple_substitution(self) -> None: | ||
before = """ | ||
from django.template.base import RequestContext | ||
RequestContext({}) | ||
""" | ||
after = """ | ||
from django.template.context import RequestContext | ||
RequestContext({}) | ||
""" | ||
self.assertCodemod(before, after) | ||
|
||
|
||
class TestContextPopExceptionTransformer(BaseVisitorTest): | ||
|
||
transformer = ContextPopExceptionTransformer | ||
|
||
def test_simple_substitution(self) -> None: | ||
before = """ | ||
from django.template.base import ContextPopException | ||
raise ContextPopException() | ||
""" | ||
after = """ | ||
from django.template.context import ContextPopException | ||
raise ContextPopException() | ||
""" | ||
self.assertCodemod(before, after) |