示例#1
0
    def testBackpack(self):
        from db.models import User, Item, DiscuzMember
        from server.item import backpack, constants

        s = current_session()

        backpack.use(1, 'foo')

        with assert_raises(exceptions.ItemNotFound):
            backpack.use(1, 'foo')

        with assert_raises(exceptions.ItemNotFound):
            backpack.use(1, 'bar')

        backpack.add(1, 'foo')
        backpack.use(1, 'foo')

        backpack.add(1, 'bar')

        with assert_raises(exceptions.ItemNotUsable):
            backpack.use(1, 'bar')

        s.rollback()
        id = s.query(Item).filter(Item.owner_id == 1, Item.sku == 'bar').first().id
        backpack.drop(1, id)

        for i in xrange(constants.BACKPACK_SIZE):
            backpack.add(1, 'foo')

        with assert_raises(exceptions.BackpackFull):
            backpack.add(1, 'foo')

        eq_(len(backpack.list(1)), constants.BACKPACK_SIZE)

        s.rollback()
        id = s.query(Item).filter(Item.owner_id == 1).first().id

        backpack.drop(1, id)
        eq_(len(backpack.list(1)), constants.BACKPACK_SIZE - 1)

        with assert_raises(exceptions.ItemNotFound):
            backpack.drop(1, id)

        s.rollback()
        u = s.query(User).filter(User.id == 1).first()
        u.ppoint = 0

        dz_member = s.query(DiscuzMember).filter(DiscuzMember.uid == 1).first()
        dz_member.member_count.jiecao = 0
        s.commit()

        backpack.add(1, 'jiecao:1234')
        backpack.use(1, 'jiecao:1234')
        backpack.add(1, 'ppoint:1234')
        backpack.use(1, 'ppoint:1234')

        u = s.query(User).filter(User.id == 1).first()
        eq_(u.ppoint, 1234)
        dz_member = s.query(DiscuzMember).filter(DiscuzMember.uid == 1).first()
        eq_(dz_member.member_count.jiecao, 1234)
示例#2
0
 def backpack(self, user):
     user.write(['backpack', backpack.list(user.account.userid)])
    def testBackpack(self):
        from db.models import User, Item, DiscuzMember
        from server.item import backpack, constants

        s = current_session()

        backpack.use(1, 'foo')

        with assert_raises(exceptions.ItemNotFound):
            backpack.use(1, 'foo')

        with assert_raises(exceptions.ItemNotFound):
            backpack.use(1, 'bar')

        backpack.add(1, 'foo')
        backpack.use(1, 'foo')

        backpack.add(1, 'bar')

        with assert_raises(exceptions.ItemNotUsable):
            backpack.use(1, 'bar')

        s.rollback()
        id = s.query(Item).filter(Item.owner_id == 1,
                                  Item.sku == 'bar').first().id
        backpack.drop(1, id)

        for i in xrange(constants.BACKPACK_SIZE):
            backpack.add(1, 'foo')

        with assert_raises(exceptions.BackpackFull):
            backpack.add(1, 'foo')

        eq_(len(backpack.list(1)), constants.BACKPACK_SIZE)

        s.rollback()
        id = s.query(Item).filter(Item.owner_id == 1).first().id

        backpack.drop(1, id)
        eq_(len(backpack.list(1)), constants.BACKPACK_SIZE - 1)

        with assert_raises(exceptions.ItemNotFound):
            backpack.drop(1, id)

        s.rollback()
        u = s.query(User).filter(User.id == 1).first()
        u.ppoint = 0
        if not options.freeplay:
            dz_member = s.query(DiscuzMember).filter(
                DiscuzMember.uid == 1).first()
            dz_member.member_count.jiecao = 0
        else:
            u.jiecao = 0
        s.commit()

        backpack.add(1, 'jiecao:1234')
        backpack.use(1, 'jiecao:1234')
        backpack.add(1, 'ppoint:1234')
        backpack.use(1, 'ppoint:1234')

        u = s.query(User).filter(User.id == 1).first()
        eq_(u.ppoint, 1234)
        if not options.freeplay:
            dz_member = s.query(DiscuzMember).filter(
                DiscuzMember.uid == 1).first()
            eq_(dz_member.member_count.jiecao, 1234)