Example #1
0
    def test_migration(self):
        doc = CustomDataFieldsDefinition(
            domain='botswana',
            field_type='UserFields',
            fields=[
                CustomDataField(
                    slug='color',
                    is_required=True,
                    label='Color',
                    choices=['red', 'orange', 'yellow'],
                ),
            ],
        )
        doc.save(sync_to_sql=False)
        call_command('populate_custom_data_fields')
        self.assertIsNone(
            Command.diff_couch_and_sql(
                doc.to_json(),
                SQLCustomDataFieldsDefinition.objects.get(
                    couch_id=doc.get_id)))

        # Additional call should apply any updates
        doc = CustomDataFieldsDefinition.get(doc.get_id)
        doc.field_type = 'LocationFields'
        doc.save(sync_to_sql=False)
        call_command('populate_custom_data_fields')
        self.assertIsNone(
            Command.diff_couch_and_sql(
                doc.to_json(),
                SQLCustomDataFieldsDefinition.objects.get(
                    couch_id=doc.get_id)))
Example #2
0
    def test_sync_to_sql(self):
        doc = CustomDataFieldsDefinition(
            domain='botswana',
            field_type='UserFields',
            fields=[
                CustomDataField(
                    slug='color',
                    is_required=True,
                    label='Color',
                    choices=['red', 'orange', 'yellow'],
                ),
                CustomDataField(
                    slug='size',
                    is_required=False,
                    label='Size',
                    regex='^[0-9]+$',
                    regex_msg='Εισαγάγετε',
                ),
            ],
        )
        doc.save()
        self.assertIsNone(
            Command.diff_couch_and_sql(
                doc.to_json(),
                SQLCustomDataFieldsDefinition.objects.get(
                    couch_id=doc.get_id)))

        doc.fields[0].label = 'Hue'
        doc.save()
        self.assertEquals(
            'Hue',
            SQLCustomDataFieldsDefinition.objects.get(
                couch_id=doc.get_id).get_fields()[0].label)