Skip to content

Commit

Permalink
Merge pull request #34 from IGNF/issue_33
Browse files Browse the repository at this point in the history
Reprise des tests pour suppression de la dépendance aux déploiements GpU
  • Loading branch information
mborne committed Dec 9, 2022
2 parents a236f70 + 8815a9d commit 32a2156
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 29 deletions.
40 changes: 33 additions & 7 deletions src/DataFixtures/ValidationsFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ class ValidationsFixtures extends Fixture
const FILENAME_SUP_PM3 = "130010853_PM3_60_20180516.zip";
const FILENAME_INVALID_REGEX = "130010853_PM3_60_20180516-invalid-regex.zip";

/**
* A validation where args are provided
*/
const VALIDATION_WITH_ARGS = 'validation_with_args';
/**
* A validation with no args
*/
const VALIDATION_NO_ARGS = 'validation_no_args';
/**
* A validation that has already been archived
* (no file, archived)
*/
const VALIDATION_ARCHIVED = 'validation_archived';

/**
* a validation with bad args
* (the model url argument is wrong and will raise a Java runtime exception which will mark the Symfony process as failed)
*/
const VALIDATION_WITH_BAD_ARGS = 'validation_with_bad_args';

/**
* A validation whose zip archive is empty
*/
const VALIDATION_INVALID_REGEX = 'validation_invalid_regex';


/**
* @var ValidatorArgumentsService
*/
Expand Down Expand Up @@ -66,7 +92,7 @@ public function load(ObjectManager $em)
$validationNoArgs = new Validation();
$this->addSampleArchive($validationNoArgs, self::FILENAME_SUP_PM3);
$em->persist($validationNoArgs);
$this->addReference('validation_no_args', $validationNoArgs);
$this->addReference(self::VALIDATION_NO_ARGS, $validationNoArgs);

/*
* validation_archived - a validation that has already been archived
Expand All @@ -76,14 +102,14 @@ public function load(ObjectManager $em)
$valArchived->setDatasetName('130010853_PM3_60_20180516');
$valArchived->setStatus(Validation::STATUS_ARCHIVED);
$em->persist($valArchived);
$this->addReference('validation_archived', $valArchived);
$this->addReference(ValidationsFixtures::VALIDATION_ARCHIVED, $valArchived);

/*
* validation_with_args - a validation where args are provided
*/
$args = [
'srs' => 'EPSG:2154',
'model' => 'https://www.geoportail-urbanisme.gouv.fr/standard/cnig_SUP_PM3_2016.json',
'model' => 'https://ignf.github.io/validator/validator-plugin-cnig/src/test/resources/config/cnig_SUP_PM3_2016.json',
];
$args = $this->valArgsService->validate(\json_encode($args));

Expand All @@ -92,7 +118,7 @@ public function load(ObjectManager $em)
$valWithArgs->setStatus(Validation::STATUS_PENDING);
$valWithArgs->setArguments($args);
$em->persist($valWithArgs);
$this->addReference('validation_with_args', $valWithArgs);
$this->addReference(self::VALIDATION_WITH_ARGS, $valWithArgs);

/*
* validation_with_bad_args - a validation with bad args
Expand All @@ -109,14 +135,14 @@ public function load(ObjectManager $em)
$valWithBadArgs->setStatus(Validation::STATUS_PENDING);
$valWithBadArgs->setArguments($args);
$em->persist($valWithBadArgs);
$this->addReference('validation_with_bad_args', $valWithBadArgs);
$this->addReference(self::VALIDATION_WITH_BAD_ARGS, $valWithBadArgs);

/*
* validation_invalid_regex - a validation whose zip archive is empty
*/
$args = [
'srs' => 'EPSG:2154',
'model' => 'https://www.geoportail-urbanisme.gouv.fr/standard/cnig_SUP_PM3_2016.json',
'model' => 'https://ignf.github.io/validator/validator-plugin-cnig/src/test/resources/config/cnig_SUP_PM3_2016.json',
];
$args = $this->valArgsService->validate(\json_encode($args));

Expand All @@ -125,7 +151,7 @@ public function load(ObjectManager $em)
$valInvalidRegex->setStatus(Validation::STATUS_PENDING);
$valInvalidRegex->setArguments($args);
$em->persist($valInvalidRegex);
$this->addReference('validation_invalid_regex', $valInvalidRegex);
$this->addReference(self::VALIDATION_INVALID_REGEX, $valInvalidRegex);

$em->flush();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Command/Validations/ProcessOneCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testExecute()

$this->assertEquals(0, $statusCode);

$valWithArgs = $this->getReference('validation_with_args');
$valWithArgs = $this->getReference(ValidationsFixtures::VALIDATION_WITH_ARGS);
$validation = $repo->findOneByUid($valWithArgs->getUid());

$this->assertEquals('', $validation->getMessage());
Expand All @@ -82,7 +82,7 @@ public function testExecute()

$this->assertEquals(0, $statusCode);

$valWithBadArgs = $this->getReference('validation_with_bad_args');
$valWithBadArgs = $this->getReference(ValidationsFixtures::VALIDATION_WITH_BAD_ARGS);
$validation = $repo->findOneByUid($valWithBadArgs->getUid());

$this->assertNotEquals('', $validation->getMessage());
Expand All @@ -98,7 +98,7 @@ public function testExecute()

$this->assertEquals(0, $statusCode);

$valInvalidRegex = $this->getReference('validation_invalid_regex');
$valInvalidRegex = $this->getReference(ValidationsFixtures::VALIDATION_INVALID_REGEX);
$validation = $repo->findOneByUid($valInvalidRegex->getUid());

$this->assertEquals('Zip archive pre-validation failed', $validation->getMessage());
Expand Down
22 changes: 11 additions & 11 deletions tests/Controller/Api/ValidationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function tearDown(): void
*/
public function testGetValidation()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);

$this->client->request(
'GET',
Expand Down Expand Up @@ -227,7 +227,7 @@ public function testUploadDatasetNoFile()
*/
public function testDeleteValidation()
{
$validation = $this->getReference('validation_archived');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_ARCHIVED);

$this->client->request(
'DELETE',
Expand Down Expand Up @@ -257,7 +257,7 @@ public function testDeleteValidation()
*/
public function testUpdateArguments()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);

$data = [
'srs' => 'EPSG:2154',
Expand Down Expand Up @@ -324,7 +324,7 @@ public function testUpdateArgumentsValNotFound()
*/
public function testUpdateArgumentsInvalidJson()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);
$data = '{model = url}';

$this->client->request(
Expand All @@ -348,7 +348,7 @@ public function testUpdateArgumentsInvalidJson()
*/
public function testUpdateArgumentsNoArguments()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);
$data = [];

$this->client->request(
Expand All @@ -372,7 +372,7 @@ public function testUpdateArgumentsNoArguments()
*/
public function testUpdateArgumentsMissingReqArguments()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);
$data = [
'srs' => 'EPSG:2154',
];
Expand Down Expand Up @@ -401,7 +401,7 @@ public function testUpdateArgumentsMissingReqArguments()
*/
public function testUpdateArgumentsUnknownParameters()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);

$data = [
'srs' => 'EPSG:2154',
Expand Down Expand Up @@ -430,7 +430,7 @@ public function testUpdateArgumentsUnknownParameters()
*/
public function testUpdateArgumentsInvalidBoolean()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);

$data = [
'srs' => 'EPSG:2154',
Expand Down Expand Up @@ -459,7 +459,7 @@ public function testUpdateArgumentsInvalidBoolean()
*/
public function testUpdateArgumentsUnknownProjection()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);

$data = [
'srs' => 'EPSG:9999',
Expand Down Expand Up @@ -487,7 +487,7 @@ public function testUpdateArgumentsUnknownProjection()
*/
public function testUpdateArgumentsInvalidModelUrl()
{
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);

$data = [
'srs' => 'EPSG:2154',
Expand Down Expand Up @@ -515,7 +515,7 @@ public function testUpdateArgumentsInvalidModelUrl()
*/
public function testUpdateArgumentsValArchived()
{
$validation = $this->getReference('validation_archived');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_ARCHIVED);

$data = [
'srs' => 'EPSG:2154',
Expand Down
10 changes: 5 additions & 5 deletions tests/Controller/Api/ValidationNormDataDownloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function tearDown(): void
public function testDownloadNoData()
{
// validation not yet executed, no args
$validation = $this->getReference('validation_no_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_NO_ARGS);

$this->client->request(
'GET',
Expand All @@ -65,7 +65,7 @@ public function testDownloadNoData()
$this->assertEquals("Validation hasn't been executed yet", $json['message']);

// validation not yet executed, has args, execution pending
$validation = $this->getReference('validation_with_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_WITH_ARGS);

$this->client->request(
'GET',
Expand All @@ -79,7 +79,7 @@ public function testDownloadNoData()
$this->assertEquals("Validation hasn't been executed yet", $json['message']);

// validation archived
$validation = $this->getReference('validation_archived');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_ARCHIVED);

$this->client->request(
'GET',
Expand Down Expand Up @@ -131,7 +131,7 @@ public function testDownload()
$this->assertEquals(0, $statusCode);

// this one has failed
$validation2 = $this->getReference('validation_with_bad_args');
$validation2 = $this->getReference(ValidationsFixtures::VALIDATION_WITH_BAD_ARGS);

$this->client->request(
'GET',
Expand All @@ -145,7 +145,7 @@ public function testDownload()
$this->assertEquals('Validation failed, no normalized data', $json['message']);

// this one has succeeded
$validation = $this->getReference('validation_with_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_WITH_ARGS);

$this->client->request(
'GET',
Expand Down
6 changes: 3 additions & 3 deletions tests/Controller/Api/ValidationSourceDataDownloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function tearDown(): void
public function testDownloadNoData()
{
// validation archived
$validation = $this->getReference('validation_archived');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_ARCHIVED);

$this->client->request(
'GET',
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testDownload()
$this->assertEquals(0, $statusCode);

// this one has failed
$validation2 = $this->getReference('validation_with_bad_args');
$validation2 = $this->getReference(ValidationsFixtures::VALIDATION_WITH_BAD_ARGS);

$this->client->request(
'GET',
Expand All @@ -136,7 +136,7 @@ public function testDownload()
$this->assertEquals('zip', $file->getExtension());

// this one has succeeded
$validation = $this->getReference('validation_with_args');
$validation = $this->getReference(ValidationsFixtures::VALIDATION_WITH_ARGS);

$this->client->request(
'GET',
Expand Down
Binary file added tests/data/cnig-pcrs-lyon-01-3946.zip
Binary file not shown.

0 comments on commit 32a2156

Please sign in to comment.