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)
def test_unique_key(self): self.schema.save() dupe_schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id, xmlns=self.xmlns) with self.assertRaises(ResourceConflict): dupe_schema.save()
def test_required_props(self): with self.assertRaises(BadValueError): schema = FormQuestionSchema(app_id=self.app_id, xmlns=self.xmlns) schema.save() # with self.assertRaises(BadValueError): # schema = FormQuestionSchema(domain=self.domain, xmlns=self.xmlns) # schema.save() with self.assertRaises(BadValueError): schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id) schema.save()
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)
class TestGetOrCreateSchema(SimpleTestCase): def setUp(self): self.db = FormQuestionSchema.get_db() self.fakedb = FakeCouchDb() FormQuestionSchema.set_db(self.fakedb) self.domain = 'test' self.app_id = '123' self.xmlns = 'this_xmlns' self.schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id, xmlns=self.xmlns) def tearDown(self): FormQuestionSchema.set_db(self.db) def test_required_props(self): with self.assertRaises(BadValueError): schema = FormQuestionSchema(app_id=self.app_id, xmlns=self.xmlns) schema.save() # with self.assertRaises(BadValueError): # schema = FormQuestionSchema(domain=self.domain, xmlns=self.xmlns) # schema.save() with self.assertRaises(BadValueError): schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id) schema.save() def test_unique_key(self): self.schema.save() dupe_schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id, xmlns=self.xmlns) with self.assertRaises(ResourceConflict): dupe_schema.save() 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) def test_get_new(self): self.schema.save() schema = FormQuestionSchema.get_or_create('new_domain', self.app_id, self.xmlns) self.assertIsNotNone(schema) 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)
class TestGetOrCreateSchema(SimpleTestCase): def setUp(self): self.db = FormQuestionSchema.get_db() self.fakedb = FakeCouchDb() FormQuestionSchema.set_db(self.fakedb) self.domain = 'test' self.app_id = '123' self.xmlns = 'this_xmlns' self.schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id, xmlns=self.xmlns) def tearDown(self): FormQuestionSchema.set_db(self.db) def test_required_props(self): with self.assertRaises(BadValueError): schema = FormQuestionSchema(app_id=self.app_id, xmlns=self.xmlns) schema.save() # with self.assertRaises(BadValueError): # schema = FormQuestionSchema(domain=self.domain, xmlns=self.xmlns) # schema.save() with self.assertRaises(BadValueError): schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id) schema.save() def test_unique_key(self): self.schema.save() dupe_schema = FormQuestionSchema(domain=self.domain, app_id=self.app_id, xmlns=self.xmlns) with self.assertRaises(ResourceConflict): dupe_schema.save() 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) def test_get_new(self): self.schema.save() schema = FormQuestionSchema.get_or_create('new_domain', self.app_id, self.xmlns) self.assertIsNotNone(schema) 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)