Strategy for resetting test data?

LabKey Support Forum
Strategy for resetting test data? slangley  2013-06-05 16:25
Status: Closed
 
I'm back at trying to solve this problem. I'm attempting to go with the C. solution I talked about in my previous post.

Using the container column seems like a useful idea if I was writing this module from scratch or doing major maintenance on it. But I hoping to just wrap up this test and then hopefully forget about the module. I'm told that if I can't, then we'll just do without a working unit test.

This module, peptide, is written in such a way that it depends on the auto-generated table sequence id, peptide_id:
  
    CREATE TABLE peptide.peptides (
        peptide_id SERIAL NOT NULL,

to define the primary key that is used all over the app. The test I wrote, naturally, assumes the test data to have fixed peptide id values assigned that I can use to identify, manipulate, and verify the Peptide objects.

The problem with deleting the rows of data test via the LabKey API's is that the the table sequence id is not reset to its previous value. So rerunning the test fails because the next set of test peptides get assigned different primary keys from the ones the test was designed to work with.

What I really want to be able to do is run this Postgres command on my database schema:

   'TRUNCATE TABLE peptide.peptides RESTART IDENTITY CASCADE;'

I assume there is not a way to run that command from inside the test - as a test seems to only have access to the client API's for data manipulation. (Is that right?)

Is my only choice to add a hidden API method to my module that will actually run the above Postgres command and to call it appropriately from my test?

Thanks.

Scott