[SEBA-126] Adding xproto support for min and max validators
Change-Id: I6141c678d88a894db2a86132bdbad4e9c6b31b2f
diff --git a/lib/xos-genx/xos-genx-tests/test_jinja2_django.py b/lib/xos-genx/xos-genx-tests/test_jinja2_django.py
index ea8738e..ab47443 100644
--- a/lib/xos-genx/xos-genx-tests/test_jinja2_django.py
+++ b/lib/xos-genx/xos-genx-tests/test_jinja2_django.py
@@ -44,6 +44,75 @@
res = xproto_optioned_fields_to_list(fields, 'feedback_state', 'True')
self.assertEqual(res, ["has_feedback_1", "has_feedback_2"])
+ def test_xproto_required_to_django(self):
+ field = {
+ 'name': 'foo',
+ 'options': {
+ 'modifier': 'required'
+ }
+ }
+
+ res = map_xproto_to_django(field)
+ self.assertEqual(res, {'blank': False, 'null': False})
+
+ def test_xproto_optional_to_django(self):
+ field = {
+ 'name': 'foo',
+ 'options': {
+ 'modifier': 'optional'
+ }
+ }
+
+ res = map_xproto_to_django(field)
+ self.assertEqual(res, {'blank': True, 'null': True})
+
+
+ def test_map_xproto_to_django(self):
+
+ options = {
+ 'help_text': 'bar',
+ 'default': 'default_value',
+ 'null': True,
+ 'db_index': False,
+ 'blank': False,
+ 'min_value': 16,
+ 'max_value': 16
+ }
+
+ field = {
+ 'name': 'foo',
+ 'options': options
+ }
+
+ res = map_xproto_to_django(field)
+ self.assertEqual(res, options)
+
+ def test_format_options_string(self):
+
+ options = {
+ 'null': True,
+ 'min_value': 16,
+ 'max_value': 16
+ }
+
+ res = format_options_string(options)
+ self.assertEqual(res, "null = True, validators=[MaxValueValidator(16), MinValueValidator(16)]")
+
+ options = {
+ 'min_value': 16,
+ 'max_value': 16
+ }
+
+ res = format_options_string(options)
+ self.assertEqual(res, "validators=[MaxValueValidator(16), MinValueValidator(16)]")
+
+ options = {
+ 'null': True,
+ }
+
+ res = format_options_string(options)
+ self.assertEqual(res, "null = True")
+
if __name__ == '__main__':
unittest.main()