Ejemplo n.º 1
0
    def testFilterProxy(self):
        BProxy = createProxy(B)

        proxy = BProxy(ProxyFilter(ProxyWrapper(B()), 'methodB'))

        self.assertTrue(isinstance(proxy, B))

        assert isinstance(proxy, B)
        self.assertRaises(AttributeError, proxy.methodA)
        self.assertTrue(proxy.methodB() == 'B.methodB')
Ejemplo n.º 2
0
    def testFilterProxy(self):
        BProxy = createProxy(B)

        proxy = BProxy(ProxyFilter(ProxyWrapper(B()), 'methodB'))

        self.assertTrue(isinstance(proxy, B))

        assert isinstance(proxy, B)
        self.assertRaises(AttributeError, proxy.methodA)
        self.assertTrue(proxy.methodB() == 'B.methodB')
Ejemplo n.º 3
0
    def testProxyRegister(self):
        BProxy = createProxy(B)

        proxy = BProxy(ProxyWrapper(B()))
        registerProxyHandler(ProxyWrapper(A()), proxy.methodA)

        self.assertTrue(isinstance(proxy, B))

        assert isinstance(proxy, B)
        self.assertTrue(proxy.methodA() == 'A.methodA')
        self.assertTrue(proxy.methodB() == 'B.methodB')
Ejemplo n.º 4
0
    def testProxyRegister(self):
        BProxy = createProxy(B)

        proxy = BProxy(ProxyWrapper(B()))
        registerProxyHandler(ProxyWrapper(A()), proxy.methodA)

        self.assertTrue(isinstance(proxy, B))

        assert isinstance(proxy, B)
        self.assertTrue(proxy.methodA() == 'A.methodA')
        self.assertTrue(proxy.methodB() == 'B.methodB')
Ejemplo n.º 5
0
    def testWrapperProxy(self):
        BProxy = createProxy(B)

        self.assertTrue(BProxy is createProxy(B))

        a_proxy = BProxy(ProxyWrapper(A()))
        b_proxy = BProxy(ProxyWrapper(B()))

        self.assertTrue(isinstance(a_proxy, B))
        self.assertTrue(isinstance(b_proxy, B))

        assert isinstance(a_proxy, B)
        self.assertTrue(a_proxy.methodA is a_proxy.methodA)
        self.assertTrue(a_proxy.methodA() == 'A.methodA')
        self.assertRaises(AttributeError, a_proxy.methodB)

        assert isinstance(b_proxy, B)
        self.assertTrue(b_proxy.methodA is b_proxy.methodA)
        self.assertFalse(a_proxy.methodA is b_proxy.methodA)
        self.assertTrue(b_proxy.methodA() == 'B.methodA')
        self.assertTrue(b_proxy.methodB() == 'B.methodB')
Ejemplo n.º 6
0
    def testWrapperProxy(self):
        BProxy = createProxy(B)

        self.assertTrue(BProxy is createProxy(B))

        a_proxy = BProxy(ProxyWrapper(A()))
        b_proxy = BProxy(ProxyWrapper(B()))

        self.assertTrue(isinstance(a_proxy, B))
        self.assertTrue(isinstance(b_proxy, B))

        assert isinstance(a_proxy, B)
        self.assertTrue(a_proxy.methodA is a_proxy.methodA)
        self.assertTrue(a_proxy.methodA() == 'A.methodA')
        self.assertRaises(AttributeError, a_proxy.methodB)

        assert isinstance(b_proxy, B)
        self.assertTrue(b_proxy.methodA is b_proxy.methodA)
        self.assertFalse(a_proxy.methodA is b_proxy.methodA)
        self.assertTrue(b_proxy.methodA() == 'B.methodA')
        self.assertTrue(b_proxy.methodB() == 'B.methodB')
Ejemplo n.º 7
0
    def testBindLock(self):
        AProxy = createProxy(A)

        proxy = AProxy(ProxyWrapper(A()))

        assert isinstance(proxy, A)

        lock = Lock()
        bindLock(proxy.methodLocked, lock)

        proxy.methodLocked(self, lock)
        self.assertTrue(lock.count == 0)

        self.assertRaises(KeyError, proxy.methodLocked, self, lock, exc=True)
        self.assertTrue(lock.count == 0)

        proxy.methodNotLocked(self, lock)
        self.assertTrue(lock.count == 0)

        clearBindings(proxy.methodLocked)
        proxy.methodLocked(self, lock, count=0)
        self.assertTrue(lock.count == 0)
Ejemplo n.º 8
0
    def testBindLock(self):
        AProxy = createProxy(A)

        proxy = AProxy(ProxyWrapper(A()))

        assert isinstance(proxy, A)

        lock = Lock()
        bindLock(proxy.methodLocked, lock)

        proxy.methodLocked(self, lock)
        self.assertTrue(lock.count == 0)

        self.assertRaises(KeyError, proxy.methodLocked, self, lock, exc=True)
        self.assertTrue(lock.count == 0)

        proxy.methodNotLocked(self, lock)
        self.assertTrue(lock.count == 0)

        clearBindings(proxy.methodLocked)
        proxy.methodLocked(self, lock, count=0)
        self.assertTrue(lock.count == 0)
Ejemplo n.º 9
0
def userService() -> IUserService:
    b = UserService()
    proxy = createProxy(IUserService)(ProxyWrapper(b))
    bindSession(proxy, alchemySessionCreator())
    return proxy
Ejemplo n.º 10
0
    def test(self):
        articleTypeService = createProxy(IArticleTypeService)(ProxyWrapper(ArticleTypeServiceAlchemy()))
        assert isinstance(articleTypeService, IArticleTypeService)

        bindValidations(articleTypeService, mappingsOf(meta))
        bindSession(articleTypeService, self.sessionCreate)

        setKeepAlive(True)

        at = ArticleType()
        at.Name = "Test Type 1"
        articleTypeService.insert(at)
        self.assertEqual(at.Id, 1)

        at.Id = 20
        # Validate auto id.
        self.assertRaisesRegex(InputError, "(ArticleType.Id='No value expected')", articleTypeService.insert, at)

        del at.Id
        at.Name = "Test Type 2"
        articleTypeService.insert(at)
        self.assertEqual(at.Id, 2)

        endSessions(commit)

        at = ArticleType()
        at.Name = "Test Type 1"
        # Validate unique id.
        self.assertRaisesRegex(
            InputError, "(ArticleType.Name='Already an entry with this value')", articleTypeService.insert, at
        )

        at = ArticleType()
        at.Name = "Test Type 3"
        articleTypeService.insert(at)
        self.assertEqual(at.Id, 3)

        endSessions(commit)

        at = articleTypeService.getById(2)
        at.Name = "Invalid"
        endSessions(commit)
        at = articleTypeService.getById(2)
        self.assertEqual(at.Name, "Test Type 2")

        endSessions(commit)

        at = articleTypeService.getById(2)
        at.Name = "Invalid"
        articleTypeService.update(at)
        endSessions(commit)
        at = articleTypeService.getById(2)
        self.assertEqual(at.Name, "Invalid")

        articleTypeService.delete(at.Id)
        self.assertRaisesRegex(InputError, "(ArticleType.Id='Unknown id')", articleTypeService.getById, at.Id)

        articleService = createProxy(IArticleService)(ProxyWrapper(ArticleServiceAlchemy()))
        assert isinstance(articleService, IArticleService)

        bindValidations(articleService, mappingsOf(meta))
        bindSession(articleService, self.sessionCreate)

        a = Article()
        a.Name = "Article 1"
        a.Type = 1
        articleService.insert(a)
        self.assertEqual(a.Id, 1)

        a = Article()
        a.Name = "Article 2"
        a.Type = 12
        # Invalid foreign key
        self.assertRaisesRegex(InputError, "(Article.Type='Unknown foreign id')", articleService.insert, a)

        endSessions(commit)

        a = articleService.getById(1)
        self.assertEqual(a.Id, 1)
        self.assertEqual(a.Name, "Article 1")
        self.assertEqual(a.Type, 1)
        at = articleTypeService.getById(a.Type)
        self.assertEqual(at.Id, 1)
        self.assertEqual(at.Name, "Test Type 1")

        endSessions(commit)

        q = QArticleType()
        q.name.orderDesc()
        self.assertEqual([e.Id for e in articleTypeService.getAll(q=q)], [3, 1])
        q = QArticleType()
        q.name.orderAsc()
        self.assertEqual([e.Id for e in articleTypeService.getAll(q=q)], [1, 3])
        q = QArticleType(name="%1")
        self.assertEqual([e.Id for e in articleTypeService.getAll(q=q)], [1])
Ejemplo n.º 11
0
def userService() -> IUserService:
    b = UserService()
    proxy = createProxy(IUserService)(ProxyWrapper(b))
    bindSession(proxy, alchemySessionCreator())
    return proxy