Пример #1
0
    def test_basic_bundle_storage(self):
        prov_document = 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()
Пример #2
0
    def test_equality(self):
        prov_document = examples.flat_document()

        stored_document = self.api.document.create(prov_document, name="test_equality")

        self.assertFalse(stored_document == "document")

        stored_document.delete()
Пример #3
0
    def test_equality(self):
        prov_document = examples.flat_document()

        stored_document = self.api.document.create(prov_document,
                                                   name="test_equality")

        self.assertFalse(stored_document == "document")

        stored_document.delete()
Пример #4
0
    def test_basic_storage(self):
        prov_document = 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()
Пример #5
0
    def test_basic_storage(self):
        prov_document = 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()
Пример #6
0
    def test_non_existent_bundle(self):
        prov_document = 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()
Пример #7
0
    def test_non_existent_bundle(self):
        prov_document = 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()
Пример #8
0
    def test_abstract_exceptions(self):
        prov_document = 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)
Пример #9
0
    def test_immutable_exceptions(self):
        prov_document = 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()
Пример #10
0
    def test_abstract_exceptions(self):
        prov_document = 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)
Пример #11
0
    def test_document_props(self):
        prov_document = 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.assertFalse(stored_document.public)
        self.assertEqual(stored_document.name, "test_document_props")

        stored_document.delete()
Пример #12
0
    def test_bundle_iteration(self):
        prov_document = 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()
Пример #13
0
    def test_document_props(self):
        prov_document = 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.assertFalse(stored_document.public)
        self.assertEqual(stored_document.name, "test_document_props")

        stored_document.delete()
Пример #14
0
    def test_basic_bundle_retrieval(self):
        prov_document = 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()
Пример #15
0
    def test_basic_bundle_retrieval(self):
        prov_document = 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()
Пример #16
0
    def test_bundle_iteration(self):
        prov_document = 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()
Пример #17
0
    def test_diff_auth_access(self):
        prov_document = 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)
Пример #18
0
    def test_diff_auth_access(self):
        prov_document = 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)
Пример #19
0
    def test_immutable_exceptions(self):
        prov_document = 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()
Пример #20
0
    def test_basic_bundle_storage(self):
        prov_document = 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()
Пример #21
0
    def test_invalid_name(self):
        prov_document = examples.flat_document()

        with self.assertRaises(InvalidDataException):
            self.api.document.create(prov_document, name="")
Пример #22
0
    def test_invalid_name(self):
        prov_document = examples.flat_document()

        with self.assertRaises(InvalidDataException):
            self.api.document.create(prov_document, name="")