开发者

Getting the primary key (id) in fixture (Python, SQLAlchemy)

I'm using fixture to test a Pylons app, but I stumbled upon a problem.

Let's say I have such data set:

class CompanyData(DataSet):

    class test_company:
        company_full_name = u'Firma Tęst'
        company_short_name = u'TęstCo'

class UserData(DataSet):

    class test_user:
        user_login = 'testuser'
        user_password = 'test'
        company = CompanyData.test_company

Now, the problem is, that when I use this data in a functional test (like described at http://farmdev.com/projects/fixture/using-fixture-with-pylons.html), I can't obtain the id (primary key) of the company.

In my application the user after logging in should be redirected to the company pro开发者_StackOverflow社区file page and that's why I need the company's id. The test looks more or less like this:

self.app.post(url(controller='main', action='login'), params={
    'login': UserData.test_user.user_login,
    'password': UserData.test_user.user_password
})

response = self.app.get(url(
    controller='events', action='index',
    company_id=UserData.test_user.company.company_id, # This doesn't work
    view='active'))
assert ... in response

The first request logs in the user and the second one checks if after logging in she can access the company profile page.

This way I get:

AttributeError: class test_company has no attribute 'company_id'

I also tried:

UserData.test_user.company.ref('company_id')

But it results in:

<Ref.RefValue for CompanyData.test_company.company_id (not yet loaded)>

which seems weird to me... Why isn't it loaded?

Is there any way of finding out what is the primary key?


UserData.test_user.company.ref('id')
or
UserData.test_user.ref('company_id')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜