Skip to content

Commit

Permalink
Fix #9320: Remove jinja (#12757)
Browse files Browse the repository at this point in the history
  • Loading branch information
aasiffaizal committed May 19, 2021
1 parent f8c8089 commit 77ce5b6
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 340 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -620,7 +620,6 @@
/core/templates/pages/header_js_libs.html @jameesjohn @vojtechjelinek
/core/templates/services/csrf-token.service*.ts @jameesjohn @vojtechjelinek
/core/templates/third-party-imports/ @vojtechjelinek
/jinja_utils*.py @jameesjohn @vojtechjelinek
/.lighthouserc.js @jimbyo @jameesjohn @vojtechjelinek
/.lighthouserc-accessibility.js @jimbyo
/puppeteer-login-script.js @jimbyo @vojtechjelinek
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Expand Up @@ -2,6 +2,6 @@
force_single_line=true
force_sort_within_sections=true
ignore_whitespace=true
known_third_party=apache_beam,backports.functools_lru_cache,browsermobproxy,cloudstorage,contextlib2,elasticsearch,firebase_admin,google.api_core,google.appengine,google.cloud,google.protobuf,jinja2,mapreduce,mock,mutagen,pipeline,pkg_resources,psutil,pylatexenc,pylint,requests,requests_mock,selenium,six,skulpt,webapp2,webapp2_extras,webtest,yaml
known_third_party=apache_beam,backports.functools_lru_cache,browsermobproxy,cloudstorage,contextlib2,elasticsearch,firebase_admin,google.api_core,google.appengine,google.cloud,google.protobuf,mapreduce,mock,mutagen,pipeline,pkg_resources,psutil,pylatexenc,pylint,requests,requests_mock,selenium,six,skulpt,webapp2,webapp2_extras,webtest,yaml
line_length=80
sections=FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,LOCALFOLDER
2 changes: 0 additions & 2 deletions app_dev.yaml
Expand Up @@ -268,8 +268,6 @@ handlers:
secure: always

libraries:
- name: jinja2
version: "2.6"
- name: PIL
version: "1.1.7"
# This is needed for sending requests to a mailgun HTTPS URL.
Expand Down
46 changes: 2 additions & 44 deletions core/controllers/reader_test.py
Expand Up @@ -402,54 +402,12 @@ def test_get_init_params(self):
"""Test the get_init_params() method."""
independent_pc = param_domain.ParamChange(
'a', 'Copier', {'value': 'firstValue', 'parse_with_jinja': False})
dependent_pc = param_domain.ParamChange(
'b', 'Copier', {'value': '{{a}}', 'parse_with_jinja': True})

exp_param_specs = {
'a': param_domain.ParamSpec('UnicodeString'),
'b': param_domain.ParamSpec('UnicodeString'),
}
new_params = self.get_updated_param_dict(
{}, [independent_pc, dependent_pc], exp_param_specs)
self.assertEqual(new_params, {'a': 'firstValue', 'b': 'firstValue'})

# Jinja string evaluation fails gracefully on dependencies that do not
# exist.
new_params = self.get_updated_param_dict(
{}, [dependent_pc, independent_pc], exp_param_specs)
self.assertEqual(new_params, {'a': 'firstValue', 'b': ''})

def test_update_learner_params(self):
"""Test the update_learner_params() method."""
independent_pc = param_domain.ParamChange(
'a', 'Copier', {'value': 'firstValue', 'parse_with_jinja': False})
dependent_pc = param_domain.ParamChange(
'b', 'Copier', {'value': '{{a}}', 'parse_with_jinja': True})

exp_param_specs = {
'a': param_domain.ParamSpec('UnicodeString'),
'b': param_domain.ParamSpec('UnicodeString'),
}

old_params = {}
new_params = self.get_updated_param_dict(
old_params, [independent_pc, dependent_pc], exp_param_specs)
self.assertEqual(new_params, {'a': 'firstValue', 'b': 'firstValue'})
self.assertEqual(old_params, {})

old_params = {'a': 'secondValue'}
new_params = self.get_updated_param_dict(
old_params, [dependent_pc], exp_param_specs)
self.assertEqual(new_params, {'a': 'secondValue', 'b': 'secondValue'})
self.assertEqual(old_params, {'a': 'secondValue'})

# Jinja string evaluation fails gracefully on dependencies that do not
# exist.
old_params = {}
new_params = self.get_updated_param_dict(
old_params, [dependent_pc], exp_param_specs)
self.assertEqual(new_params, {'b': ''})
self.assertEqual(old_params, {})
{}, [independent_pc], exp_param_specs)
self.assertEqual(new_params, {'a': 'firstValue'})


class RatingsIntegrationTests(test_utils.GenericTestBase):
Expand Down
26 changes: 12 additions & 14 deletions extensions/value_generators/models/generators.py
Expand Up @@ -22,7 +22,6 @@
import copy

from core.domain import value_generators_domain
import jinja_utils
import utils


Expand All @@ -31,23 +30,22 @@ class Copier(value_generators_domain.BaseValueGenerator):

default_value = ''

def generate_value(self, context_params, value, parse_with_jinja=False):
def generate_value(
self, unused_context_params, value, parse_with_jinja=False): # pylint: disable=unused-argument
"""Returns a copy of the input value.
If parse_with_jinja is True, strings within the input value are treated
as templates and parsed against context_params. The output will be a
unicode string.
Args:
unused_context_params: dict. Context params parsed with input
value which is treated as a template. Not used.
value: str. Value whose copy should be returned.
parse_with_jinja: bool. It is a part of ParamChange object.
The parsing of input value against context_params
based on parse_with_jinja is done in the FE. Not used.
If parse_with_jinja is False, the input value is copied and returned
without changing its type.
Returns:
str. Copy of the input value.
"""
if context_params is None:
context_params = {}

if parse_with_jinja:
return jinja_utils.evaluate_object(value, context_params)
else:
return copy.deepcopy(value)
return copy.deepcopy(value)


class RandomSelector(value_generators_domain.BaseValueGenerator):
Expand Down
10 changes: 2 additions & 8 deletions extensions/value_generators/models/generators_test.py
Expand Up @@ -28,15 +28,9 @@ class ValueGeneratorUnitTests(test_utils.GenericTestBase):

def test_copier(self):
generator = generators.Copier()
self.assertEqual(generator.generate_value({}, **{'value': 'a'}), 'a')
self.assertEqual(generator.generate_value(None, **{'value': 'a'}), 'a')
self.assertEqual(generator.generate_value(
{}, **{'value': 'a', 'parse_with_jinja': False}), 'a')
self.assertEqual(generator.generate_value(
None, **{'value': 'a', 'parse_with_jinja': False}), 'a')
self.assertEqual(generator.generate_value(
{}, **{'value': '{{a}}', 'parse_with_jinja': False}), '{{a}}')
self.assertEqual(generator.generate_value(
{'a': 'b'}, **{'value': '{{a}}', 'parse_with_jinja': True}), 'b')
None, **{'value': '{{a}}'}), '{{a}}')
self.assertIn(
'init-args="initArgs" value="customizationArgs.value"',
generator.get_html_template())
Expand Down
131 changes: 0 additions & 131 deletions jinja_utils.py

This file was deleted.

0 comments on commit 77ce5b6

Please sign in to comment.