Example #1
0
    def test_get_existing(self):
        self.schema.save()

        schema = FormQuestionSchema.get_or_create(self.domain, self.app_id,
                                                  self.xmlns)
        self.assertIsNotNone(schema)
        self.assertEqual(schema._rev, self.schema._rev)
Example #2
0
    def test_migrate_old(self):
        self.schema._id = '123'
        self.schema.last_processed_version = 12
        self.schema.save()
        second_schema = FormQuestionSchema(domain=self.domain,
                                           app_id=self.app_id,
                                           xmlns=self.xmlns,
                                           _id='1234')
        second_schema.save()
        self.assertEqual(len(self.fakedb.mock_docs), 2)

        self.fakedb.add_view(
            'form_question_schema/by_xmlns',
            [({
                'key': [self.domain, self.app_id, self.xmlns],
                'include_docs': True
            }, [self.schema.to_json(),
                second_schema.to_json()])])

        schema = FormQuestionSchema.get_or_create(self.domain, self.app_id,
                                                  self.xmlns)
        self.assertEqual(schema.last_processed_version,
                         self.schema.last_processed_version)
        self.assertNotEqual(schema.get_id, self.schema.get_id)
        self.assertNotEqual(schema.get_id, second_schema.get_id)
        self.assertEqual(len(self.fakedb.mock_docs), 1)
        self.assertTrue(schema.get_id in self.fakedb.mock_docs)
Example #3
0
    def test_migrate_old(self):
        self.schema._id = '123'
        self.schema.last_processed_version = 12
        self.schema.save()
        second_schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id, xmlns=self.xmlns, _id='1234')
        second_schema.save()
        self.assertEqual(len(self.fakedb.mock_docs), 2)

        self.fakedb.add_view(
            'form_question_schema/by_xmlns',
            [(
                {'key': [self.domain, self.app_id, self.xmlns], 'include_docs': True},
                [
                    self.schema.to_json(), second_schema.to_json()
                ]
            )]
        )

        schema = FormQuestionSchema.get_or_create(self.domain, self.app_id, self.xmlns)
        self.assertEqual(schema.last_processed_version, self.schema.last_processed_version)
        self.assertNotEqual(schema.get_id, self.schema.get_id)
        self.assertNotEqual(schema.get_id, second_schema.get_id)
        self.assertEqual(len(self.fakedb.mock_docs), 1)
        self.assertTrue(schema.get_id in self.fakedb.mock_docs)
Example #4
0
 def question_schema(self):
     return FormQuestionSchema.get_or_create(self.domain, self.app_id, self.xmlns)
Example #5
0
 def question_schema(self):
     from corehq.apps.export.models import FormQuestionSchema
     return FormQuestionSchema.get_or_create(self.domain, self.app_id,
                                             self.xmlns)
Example #6
0
    def test_get_new(self):
        self.schema.save()

        schema = FormQuestionSchema.get_or_create('new_domain', self.app_id,
                                                  self.xmlns)
        self.assertIsNotNone(schema)
Example #7
0
 def question_schema(self):
     from corehq.apps.export.models import FormQuestionSchema
     return FormQuestionSchema.get_or_create(self.domain, self.app_id, self.xmlns)
Example #8
0
    def test_get_new(self):
        self.schema.save()

        schema = FormQuestionSchema.get_or_create('new_domain', self.app_id, self.xmlns)
        self.assertIsNotNone(schema)
Example #9
0
    def test_get_existing(self):
        self.schema.save()

        schema = FormQuestionSchema.get_or_create(self.domain, self.app_id, self.xmlns)
        self.assertIsNotNone(schema)
        self.assertEqual(schema._rev, self.schema._rev)