예제 #1
0
 def test_serializer_handles_paddings(self):
     """serializer handles missing paddings"""
     for i in xrange(100):
         wet = 'Lorem ipsum %s' % ('a' * i)
         dry = serializer.dumps(wet)
         self.assertFalse(dry.endswith('='))
         self.assertEqual(wet, serializer.loads(dry))
예제 #2
0
    def test_serializer(self):
        """serializer dehydrates and hydrates values"""
        TEST_CASES = (
            'LoremIpsum', 123, [1, 2, '4d'], {'bawww': 'zong', 23: True}
        )

        for wet in TEST_CASES:
            dry = serializer.dumps(wet)
            self.assertEqual(wet, serializer.loads(dry))
예제 #3
0
    def test_serializer(self):
        """serializer dehydrates and hydrates values"""
        TEST_CASES = ('LoremIpsum', 123, [1, 2, '4d'], {
            'bawww': 'zong',
            23: True
        })

        for wet in TEST_CASES:
            dry = serializer.dumps(wet)
            self.assertEqual(wet, serializer.loads(dry))
예제 #4
0
def migrate_setting(Setting, group, setting_fixture, order, old_value):
    setting_fixture['group'] = group
    setting_fixture['order'] = order

    setting_fixture['name'] = setting_fixture['name']
    if setting_fixture.get('description'):
        setting_fixture['description'] = setting_fixture.get('description')

    if (setting_fixture.get('field_extra')
            and setting_fixture.get('field_extra').get('choices')):
        untranslated_choices = setting_fixture['field_extra']['choices']
        if untranslated_choices == '#TZ#':
            setting_fixture['field_extra']['choices'] = '#TZ#'
        else:
            translated_choices = []
            for val, name in untranslated_choices:
                translated_choices.append((val, name))
            setting_fixture['field_extra']['choices'] = tuple(
                translated_choices)

    if old_value is None:
        value = setting_fixture.pop('value', None)
    else:
        value = old_value
    setting_fixture.pop('value', None)

    field_extra = setting_fixture.pop('field_extra', None)

    setting = Setting(**setting_fixture)
    setting.dry_value = dehydrate_value(setting.python_type, value)

    if setting_fixture.get("default_value"):
        setting.default_value = dehydrate_value(
            setting.python_type, setting_fixture.get("default_value"))

    if field_extra:
        setting.pickled_field_extra = serializer.dumps(field_extra)

    setting.save()
예제 #5
0
def migrate_setting(Setting, group, setting_fixture, order, old_value):
    setting_fixture['group'] = group
    setting_fixture['order'] = order

    setting_fixture['name'] = setting_fixture['name']
    if setting_fixture.get('description'):
        setting_fixture['description'] = setting_fixture.get('description')

    if (setting_fixture.get('field_extra') and
            setting_fixture.get('field_extra').get('choices')):
        untranslated_choices = setting_fixture['field_extra']['choices']
        translated_choices = []
        for val, name in untranslated_choices:
            translated_choices.append((val, name))
        setting_fixture['field_extra']['choices'] = tuple(
            translated_choices)

    if old_value is None:
        value = setting_fixture.pop('value', None)
    else:
        value = old_value
    setting_fixture.pop('value', None)

    field_extra = setting_fixture.pop('field_extra', None)

    setting = Setting(**setting_fixture)
    setting.dry_value = dehydrate_value(setting.python_type, value)

    if setting_fixture.get("default_value"):
        setting.default_value = dehydrate_value(
            setting.python_type, setting_fixture.get("default_value"))

    if field_extra:
        setting.pickled_field_extra = serializer.dumps(field_extra)

    setting.save()
예제 #6
0
def pickle_permissions(role, permissions):
    role.pickled_permissions = serializer.dumps(permissions)
예제 #7
0
def pickle_permissions(role, permissions):
    role.pickled_permissions = serializer.dumps(permissions)
예제 #8
0
 def permissions(self, permissions):
     self.permissions_cache = permissions
     self.pickled_permissions = serializer.dumps(permissions)
예제 #9
0
 def permissions(self, permissions):
     self.permissions_cache = permissions
     self.pickled_permissions = serializer.dumps(permissions)
예제 #10
0
 def field_extra(self, new_extra):
     if new_extra:
         self.pickled_field_extra = serializer.dumps(new_extra)
예제 #11
0
 def field_extra(self, new_extra):
     if new_extra:
         self.pickled_field_extra = serializer.dumps(new_extra)