Skip to content

Commit 61c1757

Browse files
committed
chore(test): tests global
1 parent 6eb4759 commit 61c1757

15 files changed

Lines changed: 541 additions & 563 deletions

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ DATA_DIR=%kernel.project_dir%/var/data
2323
#---------------------------------------------
2424
# GPF Entrepot
2525
#---------------------------------------------
26-
API_URL=https://validtri.mut-dev.ign.fr/api/validations/
26+
API_URL=https://validtri.mut-dev.ign.fr/api/validation/
2727

2828
#---------------------------------------------
2929
# docker defaults

docs/specs/validator-api.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tags:
1717
description: "Une demande de validation de documents"
1818

1919
paths:
20-
/api/validations/:
20+
/api/validation/:
2121
post:
2222
tags:
2323
- validation
@@ -47,7 +47,7 @@ paths:
4747
schema:
4848
$ref: "#/components/schemas/Error"
4949

50-
/api/validations/{uid}:
50+
/api/validation/{uid}:
5151
get:
5252
tags:
5353
- validation
@@ -159,7 +159,7 @@ paths:
159159

160160

161161

162-
/api/validations/{uid}/results.csv:
162+
/api/validation/{uid}/results.csv:
163163
get:
164164
tags:
165165
- validation
@@ -194,7 +194,7 @@ paths:
194194
$ref: "#/components/schemas/Error"
195195

196196

197-
/api/validations/{uid}/files/source:
197+
/api/validation/{uid}/files/source:
198198
get:
199199
tags:
200200
- validation
@@ -228,7 +228,7 @@ paths:
228228
schema:
229229
$ref: "#/components/schemas/Error"
230230

231-
/api/validations/{uid}/files/normalized:
231+
/api/validation/{uid}/files/normalized:
232232
get:
233233
tags:
234234
- validation

docs/user-guide.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Exemple de requête :
66

77
```bash
88
curl --request POST \
9-
--url ${base_url}/api/validations/ \
9+
--url ${base_url}/api/validation/ \
1010
--header 'Content-Type: multipart/form-data' \
1111
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
1212
--form dataset=@92022_PLU_20200415.zip;type=application/x-zip-compressed
@@ -20,7 +20,7 @@ Exemple de requête :
2020

2121
```bash
2222
curl --request PATCH \
23-
--url ${base_url}/api/validations/k392kn8syily29qjj18959hs \
23+
--url ${base_url}/api/validation/k392kn8syily29qjj18959hs \
2424
--header 'Content-Type: application/json' \
2525
--data '{
2626
"srs": "EPSG:2154",
@@ -36,7 +36,7 @@ Exemple de requête :
3636

3737
```bash
3838
curl --request GET \
39-
--url ${base_url}/api/validations/k392kn8syily29qjj18959hs
39+
--url ${base_url}/api/validation/k392kn8syily29qjj18959hs
4040
```
4141

4242
### États possibles d'une validation :
@@ -57,7 +57,7 @@ Exemple de requête :
5757

5858
```bash
5959
curl --request GET \
60-
--url ${base_url}/api/validations/k392kn8syily29qjj18959hs/files/normalized
60+
--url ${base_url}/api/validation/k392kn8syily29qjj18959hs/files/normalized
6161
```
6262

6363
Le résultat de cette requête est un fichier compressé (zip) nommé {nom_dataset}-normalized.zip et contenant les données normalisées par le validateur.
@@ -66,7 +66,7 @@ Il est également possible de récupérer les fichiers originaux de la validatio
6666

6767
```bash
6868
curl --request GET \
69-
--url ${base_url}/api/validations/k392kn8syily29qjj18959hs/files/source
69+
--url ${base_url}/api/validation/k392kn8syily29qjj18959hs/files/source
7070
```
7171

7272

@@ -76,7 +76,7 @@ Exemple de requête :
7676

7777
```bash
7878
curl --request DELETE \
79-
--url ${base_url}/api/validations/k392kn8syily29qjj18959hs
79+
--url ${base_url}/api/validation/k392kn8syily29qjj18959hs
8080
```
8181

8282
Si la suppression se déroule correctement, le statut de réponse sera 204 sans contenu.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {},
1111
"devDependencies": {
12-
"@ignf/validator-client": "git+https://github.com/IGNF/validator-api-client.git#v0.5.3",
12+
"@ignf/validator-client": "git+https://github.com/IGNF/validator-api-client.git#v0.5.5",
1313
"copy-webpack-plugin": "^9.0.1",
1414
"webpack": "^5.44.0",
1515
"webpack-cli": "^4.7.2",

src/DataFixtures/ValidationsFixtures.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Entity\Validation;
66
use App\Service\ValidatorArgumentsService;
77
use App\Storage\ValidationsStorage;
8+
use App\Validation\ValidationFactory;
89
use Doctrine\Bundle\FixturesBundle\Fixture;
910
use Doctrine\Persistence\ObjectManager;
1011
use RuntimeException;
@@ -73,7 +74,8 @@ private function addSampleArchive(Validation $validation, $filename)
7374
throw new RuntimeException('Sample file not found : ' . $originalPath);
7475
}
7576

76-
$validationDirectory = $this->validationsStorage->getDirectory($validation);
77+
$this->validationsStorage->init($validation);
78+
$validationDirectory = $this->validationsStorage->getPath();
7779
$fs = new Filesystem();
7880
$validation->setDatasetName(str_replace('.zip', '', $filename));
7981
$fs->copy(
@@ -90,15 +92,17 @@ public function load(ObjectManager $em): void
9092
* validation_no_args - a validation with no args
9193
*/
9294
$validationNoArgs = new Validation();
95+
$validationNoArgs->setUid(ValidationFactory::generateUid());
9396
$this->addSampleArchive($validationNoArgs, self::FILENAME_SUP_PM3);
9497
$em->persist($validationNoArgs);
95-
$this->addReference(self::VALIDATION_NO_ARGS, $validationNoArgs);
98+
$this->addReference( self::VALIDATION_NO_ARGS, $validationNoArgs);
9699

97100
/*
98101
* validation_archived - a validation that has already been archived
99102
* (no file, archived)
100103
*/
101104
$valArchived = new Validation();
105+
$valArchived->setUid(ValidationFactory::generateUid());
102106
$valArchived->setDatasetName('130010853_PM3_60_20180516');
103107
$valArchived->setStatus(Validation::STATUS_ARCHIVED);
104108
$em->persist($valArchived);
@@ -110,12 +114,14 @@ public function load(ObjectManager $em): void
110114
$args = [
111115
'srs' => 'EPSG:2154',
112116
'model' => 'https://ignf.github.io/validator/validator-plugin-cnig/src/test/resources/config/cnig_SUP_PM3_2016.json',
117+
'keepData' => false
113118
];
114119
$args = $this->valArgsService->validate(\json_encode($args));
115120

116121
$valWithArgs = new Validation();
122+
$valWithArgs->setUid(ValidationFactory::generateUid());
117123
$this->addSampleArchive($valWithArgs, self::FILENAME_SUP_PM3);
118-
$valWithArgs->setStatus(Validation::STATUS_PENDING);
124+
$valWithArgs->setStatus(Validation::STATUS_WAITING_ARGS);
119125
$valWithArgs->setArguments($args);
120126
$em->persist($valWithArgs);
121127
$this->addReference(self::VALIDATION_WITH_ARGS, $valWithArgs);
@@ -127,12 +133,15 @@ public function load(ObjectManager $em): void
127133
$args = [
128134
'srs' => 'EPSG:2154',
129135
'model' => 'https://www.geoportail-urbanisme.gouv.fr/standard/cnig_SUP_PM3_2016-test.json',
136+
'keepData' => false
130137
];
131138
$args = $this->valArgsService->validate(\json_encode($args));
132139

133140
$valWithBadArgs = new Validation();
141+
$valWithBadArgs->setUid(ValidationFactory::generateUid());
142+
134143
$this->addSampleArchive($valWithBadArgs, self::FILENAME_SUP_PM3);
135-
$valWithBadArgs->setStatus(Validation::STATUS_PENDING);
144+
$valWithBadArgs->setStatus(Validation::STATUS_WAITING_ARGS);
136145
$valWithBadArgs->setArguments($args);
137146
$em->persist($valWithBadArgs);
138147
$this->addReference(self::VALIDATION_WITH_BAD_ARGS, $valWithBadArgs);
@@ -143,12 +152,15 @@ public function load(ObjectManager $em): void
143152
$args = [
144153
'srs' => 'EPSG:2154',
145154
'model' => 'https://ignf.github.io/validator/validator-plugin-cnig/src/test/resources/config/cnig_SUP_PM3_2016.json',
155+
'keepData' => false
146156
];
147157
$args = $this->valArgsService->validate(\json_encode($args));
148158

149159
$valInvalidRegex = new Validation();
160+
$valInvalidRegex->setUid(ValidationFactory::generateUid());
161+
150162
$this->addSampleArchive($valInvalidRegex, self::FILENAME_INVALID_REGEX);
151-
$valInvalidRegex->setStatus(Validation::STATUS_PENDING);
163+
$valInvalidRegex->setStatus(Validation::STATUS_WAITING_ARGS);
152164
$valInvalidRegex->setArguments($args);
153165
$em->persist($valInvalidRegex);
154166
$this->addReference(self::VALIDATION_INVALID_REGEX, $valInvalidRegex);

src/Entity/.gitignore

Whitespace-only changes.

src/Entity/Validation.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,21 @@ class Validation
9494
/**
9595
* Model to use for validation
9696
*
97-
* @ORM\Column(type="text", nullable=false)
97+
* @ORM\Column(type="text", nullable=true)
9898
*/
9999
private $model;
100100

101101
/**
102102
* SRS to use for validation
103103
*
104-
* @ORM\Column(type="text", nullable=false)
104+
* @ORM\Column(type="text", nullable=true)
105105
*/
106106
private $srs;
107107

108108
/**
109109
* Whether to keep validation data
110110
*
111-
* @ORM\Column(type="boolean", nullable=false)
111+
* @ORM\Column(type="boolean", nullable=true)
112112
*/
113113
private $keepData;
114114

@@ -122,14 +122,14 @@ class Validation
122122
/**
123123
* Date of creation
124124
*
125-
* @ORM\Column(type="datetime", nullable=false)
125+
* @ORM\Column(type="datetime", nullable=true)
126126
*/
127127
private $dateCreation;
128128

129129
/**
130130
* Status
131131
*
132-
* @ORM\Column(type="string", length=16, nullable=false, options={"default":"waiting_for_args"}, columnDefinition="character varying(16) CHECK (status IN ('waiting_for_args','uploadable','patchable','waiting_valid','validated','error','aborted','archived'))")
132+
* @ORM\Column(type="string", length=16, nullable=true, options={"default":"waiting_for_args"}, columnDefinition="character varying(16) CHECK (status IN ('waiting_for_args','uploadable','patchable','waiting_valid','validated','error','aborted','archived'))")
133133
*/
134134
private $status;
135135

@@ -172,7 +172,7 @@ class Validation
172172
/**
173173
* Whether the validation is currently being processed
174174
*
175-
* @ORM\Column(type="boolean", nullable=false)
175+
* @ORM\Column(type="boolean", nullable=true)
176176
*/
177177
private bool $processing;
178178

src/Service/ValidatorArgumentsService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ public function __construct($projectDir)
2323
* @return array
2424
* @throws ApiException
2525
*/
26-
public function validate(string $args)
26+
public function validate(?string $args)
2727
{
28+
if ($args === null){
29+
throw new ApiException("No arguments provided", Response::HTTP_BAD_REQUEST);
30+
}
31+
2832
$args = json_decode($args);
2933

3034
$validator = new Validator();

src/Validation/ValidationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function saveFile($file, Validation $validation)
7777
$this->storage->write($file, true);
7878
}
7979

80-
private function generateUid($length = 24)
80+
public static function generateUid($length = 24)
8181
{
8282
$randomUid = "";
8383

src/Validation/ValidationManager.php

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -44,51 +44,6 @@ public function __construct(
4444
$this->client = $client;
4545
}
4646

47-
/**
48-
* Archive a given validation removing all local files.
49-
*
50-
* @param Validation $validation
51-
* @return void
52-
*/
53-
public function archive(Validation $validation)
54-
{
55-
$this->logger->info('Validation[{uid}] : archive removing all files...', [
56-
'uid' => $validation->getUid(),
57-
]);
58-
$validationDirectory = $this->storage->getDirectory($validation);
59-
$fs = new Filesystem();
60-
if ($fs->exists($validationDirectory)) {
61-
$this->logger->debug('Validation[{uid}] : remove validation directory ...', [
62-
'uid' => $validation->getUid(),
63-
'validationDirectory' => $validationDirectory,
64-
]);
65-
$fs->remove($validationDirectory);
66-
}
67-
68-
// Delete from storage
69-
$this->logger->info('Validation[{uid}] : remove upload files', [
70-
'uid' => $validation->getUid(),
71-
]);
72-
$uploadDirectory = $this->storage->getUploadDirectory($validation);
73-
if ($this->storage->getStorage()->directoryExists($uploadDirectory)) {
74-
$this->storage->getStorage()->deleteDirectory($uploadDirectory);
75-
}
76-
$this->logger->info('Validation[{uid}] : remove output files', [
77-
'uid' => $validation->getUid(),
78-
]);
79-
$outputDirectory = $this->storage->getOutputDirectory($validation);
80-
if ($this->storage->getStorage()->directoryExists($outputDirectory)) {
81-
$this->storage->getStorage()->deleteDirectory($outputDirectory);
82-
}
83-
$this->logger->info('Validation[{uid}] : archive removing all files : completed', [
84-
'uid' => $validation->getUid(),
85-
'status' => Validation::STATUS_ARCHIVED,
86-
]);
87-
$validation->setStatus(Validation::STATUS_ARCHIVED);
88-
$this->em->persist($validation);
89-
$this->em->flush();
90-
}
91-
9247
/**
9348
* Process next pending validation.
9449
*
@@ -338,13 +293,16 @@ private function cleanUp(Validation $validation)
338293
'uid' => $validation->getUid(),
339294
]);
340295

341-
342-
343296
$this->storage->cleanLocal();
344297

345298
// clean gpf
346299
}
347300

301+
public function archive(Validation $validation): void
302+
{
303+
$this->cleanUp($validation);
304+
}
305+
348306
/**
349307
* @return ValidationRepository
350308
*/

0 commit comments

Comments
 (0)