简体   繁体   中英

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 profile 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM