Skip to content

Commit

Permalink
[API] Adding files in the docker container for API integration tests (a…
Browse files Browse the repository at this point in the history
…ces#7070)

Add stub files for raisinbread to use for testing of the API.
  • Loading branch information
spell00 authored and AlexandraLivadas committed Jun 29, 2021
1 parent d34e9a6 commit 342e05a
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 8 deletions.
9 changes: 9 additions & 0 deletions modules/api/test/TestPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
The API should be tested by following the API specs and making sure every command works.
This document is a preliminary test plan that should be superseded by a proper automated test suite.

## Using the integration tests
The API's integration test suite can be used to test all endpoints automatically. These tests are passed at every Travis checks.

### Using dockerized tests
To run the dockerized tests:
1- Make sure the Docker containers have been created. Otherwise, follow the instructions in `test/QuickSetup.md`.
2- Run `docker-compose run -T --rm integration-tests vendor/bin/phpunit --configuration test/phpunit.xml --testsuite LorisModuleIntegrationTests`

## Using curl:
`curl` can be used to test any endpoint manually.
### Login
This is done sending a POST request to /login
```bash
Expand Down
27 changes: 26 additions & 1 deletion raisinbread/test/api/LorisApiDicomsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,31 @@ public function testGetCandidatesCandidVisitDicoms(): void
*/
public function testGetCandidatesCandidVisitDicomsTarname(): void
{
$this->markTestSkipped('Missing data in docker image');
$resource = fopen($this->tarfileTest, 'w');
$stream = GuzzleHttp\Psr7\stream_for($resource);
try {
$response_stream = $this->client->request(
'GET',
"candidates/$this->candidTest/$this->visitTest/dicoms/" .
"$this->tarfileTest",
[
'headers' => $this->headers,
'save_to' => $stream
]
);
} catch (Exception $e) {
$this->markTestIncomplete(
"Endpoint not found: " .
"candidates/$this->candidTest/$this->visitTest/dicoms/" .
"$this->frecordTest"
);
}

$this->assertEquals(200, $response_stream->getStatusCode());
// Verify the endpoint has a body
$body = $response_stream->getBody();
$this->assertNotEmpty($body);

$this->assertFileIsReadable($this->tarfileTest);
}
}
159 changes: 155 additions & 4 deletions raisinbread/test/api/LorisApiImagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,53 @@ public function testGetCandidatesCandidVisitImages(): void
*/
public function testGetCandidatesCandidVisitImagesFilename(): void
{
$this->markTestSkipped('Missing data in docker image');
$resource = fopen($this->imagefileTest, 'w');
$stream = GuzzleHttp\Psr7\stream_for($resource);
$response = $this->client->request(
'GET',
"candidates/$this->candidTest/$this->visitTest/images/" .
"$this->imagefileTest",
[
'headers' => $this->headers,
'http_errors' => false,
'save_to' => $stream
]
);
if ($response->getStatusCode() === 404) {
$this->markTestIncomplete(
"Endpoint not found: " .
"candidates/$this->candidTest/$this->visitTest/images/" .
"$this->imagefileTest"
);
}
$this->assertEquals(200, $response->getStatusCode());
// Verify the endpoint has a body
$body = $response->getBody();
$this->assertNotEmpty($body);

$this->assertFileIsReadable($this->imagefileTest);

$response = $this->client->request(
'GET',
"candidates/$this->candidTest/$this->visitTest/images/" .
"$this->imagefileTest",
[
'headers' => $this->headers,
'http_errors' => false,
]
);
$this->assertEquals(200, $response->getStatusCode());
// Verify the endpoint has a body
$body = $response->getBody();
$this->assertNotEmpty($body);

$imagesArray = json_decode(
(string)utf8_encode(
$response->getBody()->getContents()
),
true
);
$this->assertEquals(null, $imagesArray);
}

/**
Expand Down Expand Up @@ -268,7 +314,88 @@ public function testPutCandidatesCandidVisitImagesFilenameQc(): void
*/
public function testGetCandidatesCandidVisitImagesFilenameFormatBbrowser(): void
{
$this->markTestSkipped('Missing data in docker image');
$response = $this->client->request(
'GET',
"candidates/$this->candidTest/$this->visitTest/images/" .
"$this->imagefileTest/format/brainbrowser",
[
'headers' => $this->headers,
'http_errors' => false,
]
);
if ($response->getStatusCode() === 404) {
$this->markTestIncomplete(
"Endpoint not found: " .
"candidates/$this->candidTest/$this->visitTest/images/" .
"$this->imagefileTest/format/brainbrowser"
);
}
$this->assertEquals(200, $response->getStatusCode());
// Verify the endpoint has a body
$body = $response->getBody();
$this->assertNotEmpty($body);

$imagesArray = json_decode(
(string) utf8_encode(
$response->getBody()->getContents()
),
true
);

$this->assertSame(gettype($imagesArray), 'array');
$this->assertSame(gettype($imagesArray['xspace']), 'array');
$this->assertSame(
gettype($imagesArray['xspace']['space_length']),
'string'
);
$this->assertSame(
gettype($imagesArray['xspace']['start']),
'string'
);
$this->assertSame(
gettype($imagesArray['xspace']['step']),
'string'
);
$this->assertSame(
gettype($imagesArray['yspace']['space_length']),
'string'
);
$this->assertSame(
gettype($imagesArray['yspace']['start']),
'string'
);
$this->assertSame(
gettype($imagesArray['yspace']['step']),
'string'
);
$this->assertSame(
gettype($imagesArray['zspace']['space_length']),
'string'
);
$this->assertSame(
gettype($imagesArray['zspace']['start']),
'string'
);
$this->assertSame(
gettype($imagesArray['zspace']['step']),
'string'
);

$this->assertArrayHasKey('order', $imagesArray);
$this->assertArrayHasKey('xspace', $imagesArray);
$this->assertArrayHasKey('space_length', $imagesArray['xspace']);
$this->assertArrayHasKey('start', $imagesArray['xspace']);
$this->assertArrayHasKey('step', $imagesArray['xspace']);

$this->assertArrayHasKey('yspace', $imagesArray);
$this->assertArrayHasKey('space_length', $imagesArray['yspace']);
$this->assertArrayHasKey('start', $imagesArray['yspace']);
$this->assertArrayHasKey('step', $imagesArray['yspace']);

$this->assertArrayHasKey('zspace', $imagesArray);
$this->assertArrayHasKey('space_length', $imagesArray['zspace']);
$this->assertArrayHasKey('start', $imagesArray['zspace']);
$this->assertArrayHasKey('step', $imagesArray['zspace']);
}

/**
Expand All @@ -279,7 +406,7 @@ public function testGetCandidatesCandidVisitImagesFilenameFormatBbrowser(): void
*/
public function testGetCandidatesCandidVisitImagesFilenameFormatRaw(): void
{
$this->markTestSkipped('Missing data in docker image');
$this->markTestSkipped('minctoraw not installed');
}

/**
Expand All @@ -291,7 +418,31 @@ public function testGetCandidatesCandidVisitImagesFilenameFormatRaw(): void
public function testGetCandidatesCandidVisitImagesFilenameFormatThumbnail():
void
{
$this->markTestSkipped('Missing data in docker image');
$resource = fopen($this->imagefileTest, 'w');
$stream = GuzzleHttp\Psr7\stream_for($resource);
$response_stream = $this->client->request(
'GET',
"candidates/$this->candidTest/$this->visitTest/images/" .
"$this->imagefileTest/format/thumbnail",
[
'headers' => $this->headers,
'http_errors' => false,
'save_to' => $stream
]
);
if ($response_stream->getStatusCode() === 404) {
$this->markTestIncomplete(
"Endpoint not found: " .
"candidates/$this->candidTest/$this->visitTest/images/" .
"$this->imagefileTest/format/thumbnail"
);
}
$this->assertEquals(200, $response_stream->getStatusCode());
// Verify the endpoint has a body
$body = $response_stream->getBody();
$this->assertNotEmpty($body);

$this->assertFileIsReadable($this->imagefileTest);
}

/**
Expand Down
28 changes: 25 additions & 3 deletions raisinbread/test/api/LorisApiRecordingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
class LorisApiRecordingsTest extends LorisApiAuthenticatedTest
{
protected $frecordTest = "sub-OTT174_ses-V1_task-faceO_eeg.edf";
protected $frecordTestFile = "bids_imports/Face13_BIDSVersion_1.1.0/" .
"sub-OTT174/ses-V1/eeg/sub-OTT174_ses-V1_task-faceO_eeg.edf";
protected $candidTest = "300174";
protected $visitTest = "V1";

Expand Down Expand Up @@ -95,7 +93,31 @@ public function testGetCandidatesCandidVisitRecordings(): void
*/
public function testGetCandidatesCandidVisitRecordingsEdffile(): void
{
$this->markTestSkipped('Missing data in docker image');
$resource = fopen($this->frecordTest, 'w');
$stream = GuzzleHttp\Psr7\stream_for($resource);
try {
$response = $this->client->request(
'GET',
"candidates/$this->candidTest/$this->visitTest/recordings/" .
"$this->frecordTest",
[
'headers' => $this->headers,
'save_to' => $stream
]
);
} catch (Exception $e) {
$this->markTestIncomplete(
"Endpoint not found: " .
"candidates/$this->candidTest/$this->visitTest/recordings/" .
"$this->frecordTest"
);
}
$this->assertEquals(200, $response->getStatusCode());
// Verify the endpoint has a body
$body = $response->getBody();
$this->assertNotEmpty($body);

$this->assertFileIsReadable($this->frecordTest);
}

/**
Expand Down
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 342e05a

Please sign in to comment.