Esempio n. 1
0
    def test_insert(self):

        self.user_add()
        self.user_add()
        self.user_add()

        self.assertEqual(self.session.query(User).get(1).position, 2)
        self.assertEqual(self.session.query(User).get(2).position, 1)
        self.assertEqual(self.session.query(User).get(3).position, 0)

        request = DummyRequest()
        request["position"] = ["0",]
        update(self.session, User, 1, request)

        self.assertEqual(self.session.query(User).get(1).position, 0)
        self.assertEqual(self.session.query(User).get(2).position, 2)
        self.assertEqual(self.session.query(User).get(3).position, 1)

        request = DummyRequest()
        request["position"] = ["4",]
        update(self.session, User, 1, request)

        self.assertEqual(self.session.query(User).get(1).position, 4)
        self.assertEqual(self.session.query(User).get(2).position, 2)
        self.assertEqual(self.session.query(User).get(3).position, 1)

        user = User(u'Vasya', u'Pupkin', u"123", '3')
        self.session.add(user)
        transaction.commit()

        self.assertEqual(self.session.query(User).get(1).position, 5)
        self.assertEqual(self.session.query(User).get(2).position, 2)
        self.assertEqual(self.session.query(User).get(3).position, 1)
        self.assertEqual(self.session.query(User).get(4).position, 3)
Esempio n. 2
0
def sa_paste(request):
    from sacrud.pyramid_ext import DBSession
    tname = request.matchdict['table']
    id = request.matchdict['id']
    target_id = request.matchdict['target_id']

    source_obj = action.read(DBSession, get_table(tname, request), id)['obj']
    action.update(DBSession, get_table(tname, request), target_id,
                  {"position": [source_obj.position]})

    return HTTPFound(location=request.route_url('sa_list', table=tname))
Esempio n. 3
0
def sa_update(request):
    from sacrud.pyramid_ext import DBSession
    tname = request.matchdict['table']
    id = request.matchdict['id']
    if 'form.submitted' in request.params:
        action.update(DBSession, get_table(tname, request), id,
                request.params.dict_of_lists())
        return HTTPFound(location=request.route_url('sa_list', table=tname))
    resp = action.update(DBSession, get_table(tname, request), id)
    rel = get_relationship(tname, request)
    return {'sa_crud': resp, 'rel': rel,
            'breadcrumbs': breadcrumbs(tname, 'sa_update', id=id)}
Esempio n. 4
0
    def test_update(self):

        user = User(u'Vasya', u'Pupkin', u"123")
        self.session.add(user)
        transaction.commit()

        user = self.session.query(User).get(1)
        profile = Profile(user=user, salary="25.7")

        self.session.add(profile)
        transaction.commit()

        user = User(u'Vasya', u'Pupkin', u"123")
        self.session.add(user)
        transaction.commit()
        user = self.session.query(User).get(2)

        profile = self.session.query(Profile).get(1)
        request = DummyRequest()
        request['phone'] = [
            "213123123",
        ]
        request['cv'] = [
            "Vasya Pupkin was born in Moscow",
        ]
        request['married'] = [
            "true",
        ]
        request["salary"] = [
            "23.0",
        ]
        request["user_id"] = [
            "2",
        ]

        upload = MockCGIFieldStorage()
        upload.file = StringIO('foo')
        upload.filename = 'foo.html'
        request["photo"] = [
            upload,
        ]

        update(self.session, Profile, 1, request)
        profile = self.session.query(Profile).get(1)

        self.assertEqual(profile.phone, "213123123")
        self.assertEqual(profile.cv, "Vasya Pupkin was born in Moscow")
        self.assertEqual(profile.married, True)
        self.assertEqual(profile.user.id, 2)
        self.assertEqual(profile.salary, float(23))
Esempio n. 5
0
    def test_insert(self):

        self.user_add()
        self.user_add()
        self.user_add()

        self.assertEqual(self.session.query(User).get(1).position, 2)
        self.assertEqual(self.session.query(User).get(2).position, 1)
        self.assertEqual(self.session.query(User).get(3).position, 0)

        request = DummyRequest()
        request["position"] = [
            "0",
        ]
        update(self.session, User, 1, request)

        self.assertEqual(self.session.query(User).get(1).position, 0)
        self.assertEqual(self.session.query(User).get(2).position, 2)
        self.assertEqual(self.session.query(User).get(3).position, 1)

        request = DummyRequest()
        request["position"] = [
            "4",
        ]
        update(self.session, User, 1, request)

        self.assertEqual(self.session.query(User).get(1).position, 4)
        self.assertEqual(self.session.query(User).get(2).position, 2)
        self.assertEqual(self.session.query(User).get(3).position, 1)

        user = User(u'Vasya', u'Pupkin', u"123", '3')
        self.session.add(user)
        transaction.commit()

        self.assertEqual(self.session.query(User).get(1).position, 5)
        self.assertEqual(self.session.query(User).get(2).position, 2)
        self.assertEqual(self.session.query(User).get(3).position, 1)
        self.assertEqual(self.session.query(User).get(4).position, 3)
Esempio n. 6
0
    def test_update(self):

        user = User(u'Vasya', u'Pupkin', u"123")
        self.session.add(user)
        transaction.commit()

        user = self.session.query(User).get(1)
        profile = Profile(user=user, salary="25.7")

        self.session.add(profile)
        transaction.commit()

        user = User(u'Vasya', u'Pupkin', u"123")
        self.session.add(user)
        transaction.commit()
        user = self.session.query(User).get(2)

        profile = self.session.query(Profile).get(1)
        request = DummyRequest()
        request['phone'] = ["213123123", ]
        request['cv'] = ["Vasya Pupkin was born in Moscow", ]
        request['married'] = ["true", ]
        request["salary"] = ["23.0", ]
        request["user_id"] = ["2", ]

        upload = MockCGIFieldStorage()
        upload.file = StringIO('foo')
        upload.filename = 'foo.html'
        request["photo"] = [upload, ]

        update(self.session, Profile, 1, request)
        profile = self.session.query(Profile).get(1)

        self.assertEqual(profile.phone, "213123123")
        self.assertEqual(profile.cv, "Vasya Pupkin was born in Moscow")
        self.assertEqual(profile.married, True)
        self.assertEqual(profile.user.id, 2)
        self.assertEqual(profile.salary, float(23))