def test_basic_bundle_storage(self): prov_document = own_examples.flat_document() stored_document = self.api.document.create( prov_document, name="test_basic_bundle_storage") stored_document.add_bundle(prov_document, identifier="ex:bundle-1") stored_document.bundles['ex:bundle-2'] = prov_document # should be a match even though we've added a bundle, this is a stale # instance self.assertEqual(stored_document.prov, prov_document) # when we refresh it, it should no longer match self.assertNotEqual(stored_document.refresh().prov, prov_document) self.assertEqual(stored_document.bundles['ex:bundle-2'].prov, prov_document) #self.assertEqual(self.api.document.read_meta(stored_document.id).name, "test_basic_bundle_storage") self.assertTrue( isinstance(stored_document.bundles['ex:bundle-2'].created_at, datetime.datetime)) stored_document.delete()
def test_equality(self): prov_document = own_examples.flat_document() stored_document = self.api.document.create(prov_document, name="test_equality") self.assertFalse(stored_document == "document") stored_document.delete()
def test_basic_storage(self): prov_document = own_examples.flat_document() stored_document = self.api.document.create(prov_document, name="test_basic_storage") self.assertEqual(stored_document.prov, prov_document) stored_document.delete()
def test_non_existent_bundle(self): prov_document = own_examples.flat_document() stored_document = self.api.document.create( prov_document, name="test_non_existent_bundle") with self.assertRaises(NotFoundException): stored_document.bundles['ex:not-there'] stored_document.delete()
def test_abstract_exceptions(self): prov_document = own_examples.flat_document() abstract_document = self.api.document with self.assertRaises(AbstractDocumentException): abstract_document.bundles self.assertRaises(AbstractDocumentException, abstract_document.delete) with self.assertRaises(AbstractDocumentException): abstract_document.add_bundle(prov_document, 'ex:bundle') self.assertRaises(AbstractDocumentException, abstract_document.read_meta) self.assertRaises(AbstractDocumentException, abstract_document.read_prov)
def test_document_props(self): prov_document = own_examples.flat_document() stored_document = self.api.document.create(prov_document, name="test_document_props") self.assertEqual(stored_document.views, 0) #self.assertEqual(stored_document.owner, self.api._username) self.assertTrue( isinstance(stored_document.created_at, datetime.datetime)) self.assertEqual(stored_document.prov, prov_document) self.assertTrue(stored_document.public) #self.assertEqual(stored_document.name, "test_document_props") stored_document.delete()
def test_basic_get(self): prov_document = own_examples.flat_document() prov_document.entity("ex:string", other_attributes={"ex:name": "test"}) prov_document.entity("ex:date", other_attributes={ "ex:date": strftime("%Y%m%dT%H%M%S%Z", gmtime()) }) prov_document.wasAssociatedWith('ex:string', 'ex:date') stored_document = self.api.document.create(prov_document, name="test_basic_storage") query_document = stored_document.refresh() self.assertEqual(query_document.prov, prov_document) stored_document.delete()
def test_basic_bundle_retrieval(self): prov_document = own_examples.flat_document() stored_document1 = self.api.document.create( prov_document, name="test_basic_bundle_retrieval") stored_document2 = self.api.document.create( prov_document, name="test_basic_bundle_retrieval") retrieved_document = self.api.document.set(stored_document1.id) self.assertEqual(stored_document1, retrieved_document) self.assertNotEqual(stored_document2, retrieved_document) stored_document1.delete() stored_document2.delete()
def test_bundle_iteration(self): prov_document = own_examples.flat_document() stored_document = self.api.document.create( prov_document, name="test_bundle_iteration") stored_document.add_bundle(prov_document, identifier="ex:bundle-1") stored_document.bundles['ex:bundle-2'] = prov_document self.assertEqual(len(stored_document.bundles), 0) self.assertEqual( {u'ex:bundle-1', u'ex:bundle-2'}, set([bundle.identifier for bundle in stored_document.bundles])) self.assertEqual(len(stored_document.bundles.refresh()), 2) stored_document.delete()
def test_diff_auth_access(self): prov_document = own_examples.flat_document() # Private stored_document = self.api.document.create(prov_document, name="test_basic_storage") public_api = Api() with self.assertRaises(ForbiddenException): public_api.document.get(stored_document.id) # Public stored_document = self.api.document.create(prov_document, name="test_basic_storage", public=True) document = public_api.document.get(stored_document.id) self.assertEqual(document.id, stored_document.id)
def test_immutable_exceptions(self): prov_document = own_examples.flat_document() stored_document = self.api.document.create( prov_document, name="test_immutable_exceptions") self.assertRaises(ImmutableDocumentException, stored_document.create, (stored_document, )) self.assertRaises(ImmutableDocumentException, stored_document.set, (1, )) self.assertRaises(ImmutableDocumentException, stored_document.get, (1, )) self.assertRaises(ImmutableDocumentException, stored_document.read_prov, (1, )) self.assertRaises(ImmutableDocumentException, stored_document.read_meta, (1, )) self.assertRaises(ImmutableDocumentException, stored_document.read, (1, )) stored_document.delete()
def test_invalid_name(self): prov_document = own_examples.flat_document() with self.assertRaises(InvalidDataException): self.api.document.create(prov_document, name="")