7

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?

Juliusz Gonera
  • 4,658
  • 5
  • 32
  • 35

1 Answers1

0
UserData.test_user.company.ref('id')
or
UserData.test_user.ref('company_id')
estin
  • 3,051
  • 1
  • 24
  • 31
  • `company_id` is the primary key column in the `company` table, not a foreign key in the `user` table (which is `user_company_id`). Don't blame me for the naming convention, I didn't design this database, I just work with it ;) – Juliusz Gonera Jan 21 '11 at 18:09
  • By default in yours DataSet`s primary key would be 'id' http://farmdev.com/projects/fixture/api/fixture.dataset.html#fixture.dataset.DataSetMeta – estin Jan 22 '11 at 08:40
  • I tried that, it doesn't change anything. I keep getting "". I even tried adding `class Meta: primary_key = ['company_id']` to the dataset and it changes nothing in both variants. – Juliusz Gonera Jan 22 '11 at 10:25
  • 1
    For accessing `id` your must appirate with fixture created by yours DataSets (not direct DataSets). See this working example http://pastebin.com/zUVUDnkr – estin Jan 22 '11 at 13:49
  • 1
    Thank you! Using the data object like this: `self.data = dbfixture.data(UserData); self.data.UserData.test_user.company.company_id` works like a charm. I don't know why the official docs don't highlight this (most examples use DataSets directly). – Juliusz Gonera Jan 22 '11 at 15:41