File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ def clean(self):
200200 super ().clean ()
201201
202202 # Verify that JSON data is provided as an object
203- if self .local_context_data and type (self .local_context_data ) is not dict :
203+ if self .local_context_data is not None and type (self .local_context_data ) is not dict :
204204 raise ValidationError (
205205 {'local_context_data' : _ ('JSON data must be in object form. Example:' ) + ' {"foo": 123}' }
206206 )
Original file line number Diff line number Diff line change 1+ from django .forms import ValidationError
12from django .test import TestCase
23
34from core .models import ObjectType
@@ -478,3 +479,30 @@ def test_multiple_tags_return_distinct_objects_with_seperate_config_contexts(sel
478479 annotated_queryset = Device .objects .filter (name = device .name ).annotate_config_context_data ()
479480 self .assertEqual (ConfigContext .objects .get_for_object (device ).count (), 2 )
480481 self .assertEqual (device .get_config_context (), annotated_queryset [0 ].get_config_context ())
482+
483+ def test_valid_local_context_data (self ):
484+ device = Device .objects .first ()
485+ device .local_context_data = None
486+ device .clean ()
487+
488+ device .local_context_data = {"foo" : "bar" }
489+ device .clean ()
490+
491+ def test_invalid_local_context_data (self ):
492+ device = Device .objects .first ()
493+
494+ device .local_context_data = ""
495+ with self .assertRaises (ValidationError ):
496+ device .clean ()
497+
498+ device .local_context_data = 0
499+ with self .assertRaises (ValidationError ):
500+ device .clean ()
501+
502+ device .local_context_data = False
503+ with self .assertRaises (ValidationError ):
504+ device .clean ()
505+
506+ device .local_context_data = 'foo'
507+ with self .assertRaises (ValidationError ):
508+ device .clean ()
You can’t perform that action at this time.
0 commit comments