def test_get_parts_by_class(self): pack = Package() part = SamplePart(pack, '/pmx/samp.main') pack.add(part) parts = pack.get_parts_by_class(SamplePart) assert next(parts) is part with pytest.raises(StopIteration): next(parts)
def test_get_parts_by_content_type(self): pack = Package() part = SamplePart(pack, '/pmx/samp.main') pack.add(part) parts = pack.get_parts_by_content_type(part.content_type) assert next(parts) is part with pytest.raises(StopIteration): next(parts) ct = pack.content_types.find_for(part.name) parts = pack.get_parts_by_content_type(ct) assert next(parts) is part with pytest.raises(StopIteration): next(parts)
def test_create(self): self.pack = Package()
class TestBasicPackage(object): def test_create(self): self.pack = Package() def test_package_rels(self): self.test_create() assert self.pack.relationships assert self.pack['/_rels/.rels'] assert self.pack.relationships == self.pack['/_rels/.rels'] def test_content_types(self): self.test_package_rels() # the content types part is not addressable assert '[Content_Types].xml' not in self.pack assert self.pack.content_types def test_add_part(self): self.test_content_types() self.part = part = Part(self.pack, '/foo') self.pack[part.name] = part def test_relate_part(self): self.test_add_part() r = Relationship(self.pack, '/foo', 'http://polimetrix.com/part') self.pack.relationships.add(r) def test_related(self): self.test_relate_part() assert self.pack.related('http://polimetrix.com/part')[0] == self.part def test_add_override_false(self): self.test_create() p = SamplePart(self.pack, '/pmx/samp.vpart') self.pack.add(p, override=False) ct = self.pack.content_types.find_for('/pmx/samp.vpart') assert isinstance(ct, ContentType.Default) assert ct is not None assert ct.key == 'vpart' assert ct.name == p.content_type def test_add_no_override(self): self.test_create() p = SamplePart(self.pack, '/pmx/samp.main', content_type='app/pmxmain+xml') self.pack.add(p) ct = self.pack.content_types.find_for('/pmx/samp.main') assert isinstance(ct, ContentType.Override) assert ct is not None assert ct.key == p.name assert ct.name == p.content_type def test_get_parts_by_content_type(self): pack = Package() part = SamplePart(pack, '/pmx/samp.main') pack.add(part) parts = pack.get_parts_by_content_type(part.content_type) assert next(parts) is part with pytest.raises(StopIteration): next(parts) ct = pack.content_types.find_for(part.name) parts = pack.get_parts_by_content_type(ct) assert next(parts) is part with pytest.raises(StopIteration): next(parts) def test_get_parts_by_class(self): pack = Package() part = SamplePart(pack, '/pmx/samp.main') pack.add(part) parts = pack.get_parts_by_class(SamplePart) assert next(parts) is part with pytest.raises(StopIteration): next(parts)