def test_simple_find_imports(self): # note: more complex testing of this find_importing_schema_names() is # in test_multi.py name = "goober" loc = "goober.xsd" content = "<schema />" self.test_load_schema() sc = models.SchemaCommon.objects.get(name=name) newver = models.SchemaVersion( name=name, common=sc, location=loc, status=RECORD.AVAILABLE, content="<schema></schema>", digest="yyz", version=models.SchemaVersion.next_version_for(name)) newver.save() first = models.Schema.get_by_name(name) self.assertEquals(first.find_importing_schema_names(), []) # pdb.set_trace() self.load_schema("foofoo", "foo.xsd") self.assertEquals(first.find_importing_schema_names(), []) first._wrapped.imports = ['foo.xsd::foofoo'] first._wrapped.save() self.assertEquals(first.find_importing_schema_names(), []) second = models.Schema.get_by_name('foofoo') self.assertEquals(second.find_importing_schema_names(), ['goober'])
def test_versions(self): name = "goober" loc = "goober.xsd" content = "<schema />" self.test_load_schema() sc = models.SchemaCommon.objects.get(name=name) newver = models.SchemaVersion( name=name, common=sc, location=loc, status=RECORD.AVAILABLE, content="<schema></schema>", digest="yyz", version=models.SchemaVersion.next_version_for(name)) newver.save() svs = models.SchemaVersion.objects.filter(name='goober') vers = map(lambda s: s.version, svs) self.assertEquals(len(vers), 2) vers.sort() self.assertEquals(vers, [1, 2]) schema = models.Schema.get_by_name('goober', 1) self.assertEquals(schema.version, 1) schema = models.Schema.get_by_name('goober', 2) self.assertEquals(schema.version, 2) self.load_schema("foofoo", "foo.xsd") svs = models.SchemaVersion.objects.filter(name='foofoo') vers = map(lambda s: s.version, svs) self.assertEquals(len(vers), 1) vers.sort() self.assertEquals(vers, [1]) schema = models.Schema.get_by_name('foofoo', 1) self.assertEquals(schema.version, 1)
def load_schema(self, name, location, ns="urn:experiments", content="<schema />"): schema = models.SchemaCommon(namespace=ns, name=name, current=1) schema.save() schemaVer = models.SchemaVersion( name=name, common=schema, location=location, status=RECORD.IS_CURRENT, content=content, digest="xxx", version=models.SchemaVersion.next_version_for(name)) schemaVer.save()
def test_next_version(self): self.assertEquals(models.SchemaVersion.next_version_for('goober'), 1) self.test_load_schema() self.assertEquals(models.SchemaVersion.next_version_for('goober'), 2) sc = models.SchemaCommon.objects.get(name='goober') newver = models.SchemaVersion( name='goober', common=sc, location='g.xsd', status=RECORD.AVAILABLE, content="<schema></schema>", digest="yyz", version=models.SchemaVersion.next_version_for('goober')) newver.save() self.assertEquals(models.SchemaVersion.next_version_for('goober'), 3) self.assertEquals(models.SchemaVersion.next_version_for('foofoo'), 1)
def test_delete(self): name = "goober" loc = "goober.xsd" content = "<schema />" self.test_load_schema() sc = models.SchemaCommon.objects.get(name=name) newver = models.SchemaVersion( name=name, common=sc, location=loc, status=RECORD.AVAILABLE, content="<schema></schema>", digest="yyz", version=models.SchemaVersion.next_version_for(name)) newver.save() first = models.Schema.get_by_name(name, 1) second = models.Schema.get_by_name(name, 2) self.assertEquals(first.version, 1) self.assertEquals(first.status, RECORD.IS_CURRENT) self.assertEquals(second.version, 2) self.assertEquals(second.status, RECORD.AVAILABLE) second.delete() self.assertEquals(second.status, RECORD.DELETED) self.assertEquals(first.status, RECORD.IS_CURRENT) first = models.Schema.get_by_name(name, 1) second = models.Schema.get_by_name(name, 2, True) self.assertEquals(second.status, RECORD.DELETED) self.assertEquals(first.status, RECORD.IS_CURRENT) second.undelete() self.assertEquals(second.status, RECORD.AVAILABLE) second = models.Schema.get_by_name(name, 2, True) self.assertEquals(second.status, RECORD.AVAILABLE) first.delete() self.assertEquals(first.status, RECORD.DELETED) first = models.Schema.get_by_name(name, 1, True) second = models.Schema.get_by_name(name, 2, True) self.assertEquals(first.status, RECORD.DELETED) self.assertEquals(second.status, RECORD.IS_CURRENT)
def test_get_all_current(self): name = "goober" loc = "goober.xsd" content = "<schema />" self.test_load_schema() sc = models.SchemaCommon.objects.get(name=name) newver = models.SchemaVersion( name=name, common=sc, location=loc, status=RECORD.AVAILABLE, content="<schema></schema>", digest="yyz", version=models.SchemaVersion.next_version_for(name)) newver.save() curs = models.SchemaVersion.get_all_current() self.assertEquals(len(curs), 1) self.assertEquals(curs[0].name, name) self.assertEquals(curs[0].version, 1)
def test_load_template(self): nm = "experiments" ns = "urn:experiments" #pdb.set_trace() schema = models.SchemaCommon(namespace=ns, name="goober", current=1) schema.save() schemaVer = models.SchemaVersion( name="goober", common=schema, location="goober.xsd", content="<schema />", digest="xxx", version=models.SchemaVersion.next_version_for('goober')) schemaVer.save() #pdb.set_trace() tmpl = models.TemplateCommon(name=nm, root="{urn:experiments}lab", current=1) tmpl.save() tmplVer = models.TemplateVersion(name=nm, common=tmpl, schema=schemaVer, label="Title") tmplVer.save() ver = models.TemplateVersion.objects.\ filter(deleted=False).filter(name=nm) self.assertEquals(len(ver), 1) ver = ver[0] self.assertEquals(ver.name, nm) self.assertEquals(ver.common.name, ver.name) self.assertEquals(ver.common.current, ver.version) self.assertEquals(ver.common.root, "{urn:experiments}lab") self.assertEquals(ver.schema.common.namespace, "urn:experiments") self.assertEquals(ver.schema.location, "goober.xsd") self.assertEquals(ver.schema.content, "<schema />") self.assertEquals(ver.schema.digest, "xxx") self.assertEquals(ver.label, "Title")
def test_make_current(self): name = "goober" loc = "goober.xsd" content = "<schema />" self.test_load_schema() sc = models.SchemaCommon.objects.get(name=name) newver = models.SchemaVersion( name=name, common=sc, location=loc, status=RECORD.AVAILABLE, content="<schema></schema>", digest="yyz", version=models.SchemaVersion.next_version_for(name)) newver.save() first = models.Schema.get_by_name(name) self.assertEquals(first.version, 1) self.assertEquals(first.status, RECORD.IS_CURRENT) second = models.Schema.get_by_name(name, 2) self.assertEquals(second.version, 2) self.assertEquals(second.status, RECORD.AVAILABLE) second.make_current() self.assertEquals(second.version, 2) self.assertEquals(second.status, RECORD.IS_CURRENT) second = models.Schema.get_by_name(name, 2) self.assertEquals(second.version, 2) self.assertEquals(second.status, RECORD.IS_CURRENT) first = models.Schema.get_by_name(name, 1) self.assertEquals(first.version, 1) self.assertEquals(first.status, RECORD.AVAILABLE) first._wrapped.status = RECORD.DELETED # first._wrapped.save() with self.assertRaises(RuntimeError): first.make_current()