Esempio n. 1
0
 def testJoinOnlyOnce(self):
     commitCalled = []
     class MockResourceManager(object):
         def commit(self, id):
             commitCalled.append(id)
     tx = Transaction('name')
     resource = MockResourceManager()
     tx.join(resource)
     tx.join(resource)
     list(tx.commit())
     self.assertEquals(1, len(commitCalled))
     self.assertEquals(tx.getId(), commitCalled[0])
Esempio n. 2
0
 def testSingularValueFields(self):
     __callstack_var_tx__ = Transaction('name')
     __callstack_var_tx__.locals['id'] = 'identifier'
     observer = CallTrace('observer', emptyGeneratorMethods=['add'])
     fxf = Fields2SolrDoc('name', 'partname', singularValueFields=['once'])
     fxf.addObserver(observer)
     fxf.begin(name='name')
     fxf.addField('once', 'one')
     fxf.addField('once', 'two')
     fxf.addField('twice', 'one')
     fxf.addField('twice', 'two')
     list(compose(fxf.commit(__callstack_var_tx__.getId())))
     method = observer.calledMethods[0]
     self.assertEquals({'__id__': ['identifier'], 'once':['one'], 'twice': ['one', 'two']}, todict(method.kwargs['data']))
Esempio n. 3
0
    def testJoinOnlyOnce(self):
        commitCalled = []

        class MockResourceManager(object):
            def commit(self, id):
                commitCalled.append(id)

        tx = Transaction('name')
        resource = MockResourceManager()
        tx.join(resource)
        tx.join(resource)
        list(tx.commit())
        self.assertEqual(1, len(commitCalled))
        self.assertEqual(tx.getId(), commitCalled[0])
Esempio n. 4
0
 def testSingularValueFields(self):
     __callstack_var_tx__ = Transaction('name')
     __callstack_var_tx__.locals['id'] = 'identifier'
     observer = CallTrace('observer', emptyGeneratorMethods=['add'])
     fxf = Fields2SolrDoc('name', 'partname', singularValueFields=['once'])
     fxf.addObserver(observer)
     fxf.begin(name='name')
     fxf.addField('once', 'one')
     fxf.addField('once', 'two')
     fxf.addField('twice', 'one')
     fxf.addField('twice', 'two')
     list(compose(fxf.commit(__callstack_var_tx__.getId())))
     method = observer.calledMethods[0]
     self.assertEquals(
         {
             '__id__': ['identifier'],
             'once': ['one'],
             'twice': ['one', 'two']
         }, todict(method.kwargs['data']))
    def testEmptyNamespace(self):
        ctx = CallTrace('CTX')
        tx = Transaction('TX')
        tx.locals = {'id': 'identifier'}
        tx.name = "tsName"
        fxf = Fields2XmlFields("tsName", "fields-partname")
        fxf.ctx = ctx 
        fxf.ctx.tx = tx
        observer = CallTrace(methods={'add': add})
        fxf.addObserver(observer)
        
        fxf.begin(name='tsName')
        fxf.addField("key.sub", "value")
        list(compose(fxf.commit(tx.getId())))

        self.assertEquals(['add'], [m.name for m in observer.calledMethods])
        self.assertEqualsWS("""<fields>
                <field name="key.sub">value</field>
            </fields>""", observer.calledMethods[0].kwargs['data']) 
    def testEmptyNamespace(self):
        ctx = CallTrace('CTX')
        tx = Transaction('TX')
        tx.locals = {'id': 'identifier'}
        tx.name = "tsName"
        fxf = Fields2XmlFields("tsName", "fields-partname")
        fxf.ctx = ctx 
        fxf.ctx.tx = tx
        observer = CallTrace(methods={'add': add})
        fxf.addObserver(observer)
        
        fxf.begin(name='tsName')
        fxf.addField("key.sub", "value")
        list(compose(fxf.commit(tx.getId())))

        self.assertEqual(['add'], [m.name for m in observer.calledMethods])
        self.assertEqualsWS("""<fields>
                <field name="key.sub">value</field>
            </fields>""", observer.calledMethods[0].kwargs['data'])