Skip to content
Snippets Groups Projects
Commit bf42c161 authored by pkupczyk's avatar pkupczyk
Browse files

SP-952 / BIS-548 : Novartis: API Access to attachements in dropboxes - fix flaky test

SVN: 30007
parent cbf55cfc
No related branches found
No related tags found
No related merge requests found
from java.lang import String from java.lang import String
from org.apache.commons.io import IOUtils from org.apache.commons.io import IOUtils
def listProjectAttachments(transaction, projectIdentifier):
project = transaction.getProject(projectIdentifier)
return transaction.listProjectAttachments(project);
def listExperimentAttachments(transaction, experimentIdentifier):
experiment = transaction.getExperiment(experimentIdentifier)
return transaction.listExperimentAttachments(experiment);
def listSampleAttachments(transaction, sampleIdentifier):
sample = transaction.getSample(sampleIdentifier)
return transaction.listSampleAttachments(sample);
def getProjectAttachmentContent(transaction, projectIdentifier, name, version):
project = transaction.getProject(projectIdentifier)
return transaction.getProjectAttachmentContent(project, name, version)
def getExperimentAttachmentContent(transaction, experimentIdentifier, name, version):
experiment = transaction.getExperiment(experimentIdentifier)
return transaction.getExperimentAttachmentContent(experiment, name, version)
def getSampleAttachmentContent(transaction, sampleIdentifier, name, version):
sample = transaction.getSample(sampleIdentifier)
return transaction.getSampleAttachmentContent(sample, name, version)
def assertAttachmentContentContains(actualContentStream, expectedContentString): def assertAttachmentContentContains(actualContentStream, expectedContentString):
if(expectedContentString == None and actualContentStream <> None): if(expectedContentString == None and actualContentStream <> None):
actualContentString = String(IOUtils.toByteArray(actualContentStream)); actualContentString = String(IOUtils.toByteArray(actualContentStream));
...@@ -55,72 +31,72 @@ def assertAttachment(attachment, fileName, title, description, version): ...@@ -55,72 +31,72 @@ def assertAttachment(attachment, fileName, title, description, version):
raise Exception('Attachment version should be: "' + str(version) + '" but was: "' + str(attachment.getVersion()) + '"') raise Exception('Attachment version should be: "' + str(version) + '" but was: "' + str(attachment.getVersion()) + '"')
def testProjectWithoutAttachments(transaction): def testProjectWithoutAttachments(transaction):
PROJECT_IDENTIFIER = "/CISD/DEFAULT"; project = transaction.getProject("/CISD/DEFAULT");
attachments = listProjectAttachments(transaction, PROJECT_IDENTIFIER) attachments = transaction.listProjectAttachments(project)
assertAttachmentCount(attachments, 0) assertAttachmentCount(attachments, 0)
content = getProjectAttachmentContent(transaction, PROJECT_IDENTIFIER, "not-existing-attachment", None); content = transaction.getProjectAttachmentContent(project, "not-existing-attachment", None);
assertAttachmentContentContains(content, None); assertAttachmentContentContains(content, None);
def testProjectWithAttachments(transaction): def testProjectWithAttachments(transaction):
PROJECT_IDENTIFIER = "/CISD/NEMO"; project = transaction.getProject("/CISD/NEMO");
attachments = listProjectAttachments(transaction, PROJECT_IDENTIFIER) attachments = transaction.listProjectAttachments(project)
assertAttachmentCount(attachments, 1) assertAttachmentCount(attachments, 1)
assertAttachment(attachments[0], "projectDescription.txt", "The Project", "All about it.", 1); assertAttachment(attachments[0], "projectDescription.txt", "The Project", "All about it.", 1);
content = getProjectAttachmentContent(transaction, PROJECT_IDENTIFIER, "projectDescription.txt", None); content = transaction.getProjectAttachmentContent(project, "projectDescription.txt", None);
assertAttachmentContentContains(content, "3VCP1"); assertAttachmentContentContains(content, "3VCP1");
content2 = getProjectAttachmentContent(transaction, PROJECT_IDENTIFIER, "not-existing-attachment", None); content2 = transaction.getProjectAttachmentContent(project, "not-existing-attachment", None);
assertAttachmentContentContains(content2, None); assertAttachmentContentContains(content2, None);
def testExperimentWithoutAttachments(transaction): def testExperimentWithoutAttachments(transaction):
EXPERIMENT_IDENTIFIER = "/CISD/NEMO/EXP10"; experiment = transaction.getExperiment("/CISD/NEMO/EXP10");
attachments = listExperimentAttachments(transaction, EXPERIMENT_IDENTIFIER) attachments = transaction.listExperimentAttachments(experiment)
assertAttachmentCount(attachments, 0) assertAttachmentCount(attachments, 0)
content = getExperimentAttachmentContent(transaction, EXPERIMENT_IDENTIFIER, "not-existing-attachment", 2); content = transaction.getExperimentAttachmentContent(experiment, "not-existing-attachment", 2);
assertAttachmentContentContains(content, None); assertAttachmentContentContains(content, None);
def testExperimentWithAttachments(transaction): def testExperimentWithAttachments(transaction):
EXPERIMENT_IDENTIFIER = "/CISD/NEMO/EXP1"; experiment = transaction.getExperiment("/CISD/NEMO/EXP1");
attachments = listExperimentAttachments(transaction, EXPERIMENT_IDENTIFIER) attachments = transaction.listExperimentAttachments(experiment)
assertAttachmentCount(attachments, 4) assertAttachmentCount(attachments, 4)
assertAttachment(attachments[0], "exampleExperiments.txt", None, None, 1) assertAttachment(attachments[0], "exampleExperiments.txt", None, None, 1)
assertAttachment(attachments[1], "exampleExperiments.txt", None, None, 2) assertAttachment(attachments[1], "exampleExperiments.txt", None, None, 2)
assertAttachment(attachments[2], "exampleExperiments.txt", None, None, 3) assertAttachment(attachments[2], "exampleExperiments.txt", None, None, 3)
assertAttachment(attachments[3], "exampleExperiments.txt", None, None, 4) assertAttachment(attachments[3], "exampleExperiments.txt", None, None, 4)
content = getExperimentAttachmentContent(transaction, EXPERIMENT_IDENTIFIER, "exampleExperiments.txt", 2); content = transaction.getExperimentAttachmentContent(experiment, "exampleExperiments.txt", 2);
assertAttachmentContentContains(content, "koko"); assertAttachmentContentContains(content, "koko");
content2 = getExperimentAttachmentContent(transaction, EXPERIMENT_IDENTIFIER, "not-existing-attachment", 2); content2 = transaction.getExperimentAttachmentContent(experiment, "not-existing-attachment", 2);
assertAttachmentContentContains(content2, None); assertAttachmentContentContains(content2, None);
def testSampleWithoutAttachments(transaction): def testSampleWithoutAttachments(transaction):
SAMPLE_IDENTIFIER = "/CISD/3VCP5"; sample = transaction.getSample("/CISD/3VCP5");
attachments = listSampleAttachments(transaction, SAMPLE_IDENTIFIER) attachments = transaction.listSampleAttachments(sample)
assertAttachmentCount(attachments, 0) assertAttachmentCount(attachments, 0)
content = getSampleAttachmentContent(transaction, SAMPLE_IDENTIFIER, "not-existing-attachment", None); content = transaction.getSampleAttachmentContent(sample, "not-existing-attachment", None);
assertAttachmentContentContains(content, None); assertAttachmentContentContains(content, None);
def testSampleWithAttachments(transaction): def testSampleWithAttachments(transaction):
SAMPLE_IDENTIFIER = "/CISD/3VCP6"; sample = transaction.getSample("/CISD/3VCP6");
attachments = listSampleAttachments(transaction, SAMPLE_IDENTIFIER) attachments = transaction.listSampleAttachments(sample)
assertAttachmentCount(attachments, 1) assertAttachmentCount(attachments, 1)
assertAttachment(attachments[0], "sampleHistory.txt", None, None, 1) assertAttachment(attachments[0], "sampleHistory.txt", None, None, 1)
content = getSampleAttachmentContent(transaction, SAMPLE_IDENTIFIER, "sampleHistory.txt", None); content = transaction.getSampleAttachmentContent(sample, "sampleHistory.txt", None);
assertAttachmentContentContains(content, "kot") assertAttachmentContentContains(content, "kot")
content2 = getSampleAttachmentContent(transaction, SAMPLE_IDENTIFIER, "not-existing-attachment", None); content2 = transaction.getSampleAttachmentContent(sample, "not-existing-attachment", None);
assertAttachmentContentContains(content2, None); assertAttachmentContentContains(content2, None);
def process(transaction): def process(transaction):
......
...@@ -109,4 +109,10 @@ public class AttachmentsDropboxTest extends SystemTestCase ...@@ -109,4 +109,10 @@ public class AttachmentsDropboxTest extends SystemTestCase
return new File(rootDir, "incoming-attachments-test"); return new File(rootDir, "incoming-attachments-test");
} }
@Override
protected int dataSetImportWaitDurationInSeconds()
{
return 120;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment