コード例 #1
0
 def test_save(self):
     initial_values  = self.initial_values
     data = get_values().copy()
     data["version"] = 'test'
     now = datetime.datetime(2018, 1, 1, 23, 0, 0)
     data['DATETIME_VALUE_0'] = now.date()
     data['DATETIME_VALUE_1'] = now.time()
     del data['DATETIME_VALUE']
     f = ConstanceForm(initial=initial_values, data=data)
     self.assertTrue(f.is_valid(), msg=f.errors.as_data())
     f.save()
     self.assertEqual(f.cleaned_data['DATETIME_VALUE'], now)
コード例 #2
0
 def test_datetime_custom(self):
     initial_values = get_values()
     f = ConstanceForm(initial=initial_values)
     value = initial_values['DATETIME_VALUE']
     field = f.fields['DATETIME_VALUE']
     clean_value = field.clean(field.to_python((value.date(), value.time())))
     self.assertEqual(initial_values['DATETIME_VALUE'], clean_value)
コード例 #3
0
    def test_form_field_types(self):

        f = ConstanceForm({})

        self.assertIsInstance(f.fields['INT_VALUE'], fields.IntegerField)
        self.assertIsInstance(f.fields['LONG_VALUE'], fields.IntegerField)
        self.assertIsInstance(f.fields['BOOL_VALUE'], fields.BooleanField)
        self.assertIsInstance(f.fields['STRING_VALUE'], fields.CharField)
        self.assertIsInstance(f.fields['UNICODE_VALUE'], fields.CharField)
        self.assertIsInstance(f.fields['DECIMAL_VALUE'], fields.DecimalField)
        self.assertIsInstance(f.fields['DATETIME_VALUE'], fields.SplitDateTimeField)
        self.assertIsInstance(f.fields['TIMEDELTA_VALUE'], fields.DurationField)
        self.assertIsInstance(f.fields['FLOAT_VALUE'], fields.FloatField)
        self.assertIsInstance(f.fields['DATE_VALUE'], fields.DateField)
        self.assertIsInstance(f.fields['TIME_VALUE'], fields.TimeField)

        # from CONSTANCE_ADDITIONAL_FIELDS
        self.assertIsInstance(f.fields['CHOICE_VALUE'], fields.ChoiceField)
        self.assertIsInstance(f.fields['EMAIL_VALUE'], fields.EmailField)
コード例 #4
0
 def post(self, request, *args, **kwargs):
     """
     Update App Config\n
         POST params:
         - auto_login: bool
         - standard_optional_locators: list[str]
         see settings.OPTIONAL_LOCATORS
     """
     initial = get_values()
     form = ConstanceForm(data=request.data, initial=initial)
     form.data['version'] = initial.get('version')
     if form.is_valid():
         form.save()
         message = 'Application settings updated successfully.'
     else:
         message = form.errors
     return JsonResponse(message, safe=False)
コード例 #5
0
 def post(self, request, *args, **kwargs):
     """
     Update App Config\n
         Params:
             - auto_login: bool
             - standard_optional_locators: list[str], see settings.OPTIONAL_LOCATORS
             - data: json, - custom settings for project
     """
     initial = get_values()
     data = initial.copy()
     data.update(request.data)
     if 'data' in data:
         data['data'] = json.dumps(data['data'])
     form = ConstanceForm(data=data, initial=initial)
     form.data['version'] = initial.get('version')
     if form.is_valid():
         form.save()
         return Response('Application settings updated successfully.')
     else:
         return Response(form.errors, status=500)
コード例 #6
0
    def post(self, request, *args, **kwargs):
        """
        Update App Config data\n
            Params:
                dictionary {key1: val2, key2: val2, ...} - json, custom settings for project
        """
        initial_config = get_values()

        data = json.loads(initial_config['data'])
        data.update(request.data)

        updated_config = initial_config.copy()
        updated_config['data'] = json.dumps(data)

        form = ConstanceForm(data=updated_config, initial=initial_config)
        form.data['version'] = initial_config.get('version')
        if form.is_valid():
            form.save()
            return Response('Application settings updated successfully.')
        else:
            return Response(form.errors, status=500)
コード例 #7
0
    def delete(self, request, *args, **kwargs):
        """
        Delete specific key from App Config data
        """
        initial_config = get_values()
        param = request.data.get('param')

        if not param:
            raise APIException('Provide key to delete')

        data = json.loads(initial_config['data'])
        data.pop(param, None)
        updated_config = initial_config.copy()
        updated_config['data'] = json.dumps(data)

        form = ConstanceForm(data=updated_config, initial=initial_config)
        form.data['version'] = initial_config.get('version')
        if form.is_valid():
            form.save()
            return Response('OK')
        else:
            return Response(form.errors, status=500)