获取固定装置中的主键(id)(Python,SQLAlchemy)
我正在使用 fixture 来测试 Pylons 应用程序,但我偶然发现了一个问题。
假设我有这样的数据集:
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
现在的问题是,当我在功能测试中使用这些数据时(如 http://farmdev.com/projects/fixture/using-fixture-with-pylons.html),我无法获取 id (主键)公司。
在我的应用程序中,用户登录后应重定向到公司资料页面,这就是我需要公司 ID 的原因。测试看起来或多或少像这样:
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
第一个请求登录用户,第二个请求检查登录后她是否可以访问公司资料页面。
这样我得到:
AttributeError:类 test_company 有 没有属性“company_id”
我也尝试过:
UserData.test_user.company.ref('company_id')
但结果是:
这对我来说似乎很奇怪......为什么它没有加载?
有什么办法可以找出主键吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)