diff --git a/backend/tests/blank_gun.jpg b/backend/tests/blank_gun.jpg new file mode 100755 index 00000000..936f38fc Binary files /dev/null and b/backend/tests/blank_gun.jpg differ diff --git a/backend/tests/low_quality.jpg b/backend/tests/low_quality.jpg new file mode 100644 index 00000000..6682df31 Binary files /dev/null and b/backend/tests/low_quality.jpg differ diff --git a/backend/tests/no_text.jpg b/backend/tests/no_text.jpg new file mode 100644 index 00000000..d11abd33 Binary files /dev/null and b/backend/tests/no_text.jpg differ diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 11b25701..89dcf6c3 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -186,3 +186,41 @@ def test_403(self): response = client.post("/api/expert-contact") response.data = response.json() assert response.status_code == 403 + + +class TestBlankGunUpload: + def test_blank_gun(self): + with open("./tests/blank_gun.jpg", "rb") as f: + response = client.post( + "/api/identification-blank-gun", + files={"image": f}, + ) + response.data = response.json() + assert response.status_code == 200 + assert response.data["alarm_model"] == "Alarm_model" + assert response.data["missing_text"] == False + assert response.data["low_quality"] == False + + def test_bad_quality(self): + with open("./tests/low_quality.jpg", "rb") as f: + response = client.post( + "/api/identification-blank-gun", + files={"image": f}, + ) + response.data = response.json() + assert response.status_code == 200 + assert response.data["alarm_model"] == None + assert response.data["missing_text"] == False + assert response.data["low_quality"] == True + + def test_missing_text(self): + with open("./tests/no_text.jpg", "rb") as f: + response = client.post( + "/api/identification-blank-gun", + files={"image": f}, + ) + response.data = response.json() + assert response.status_code == 200 + assert response.data["alarm_model"] == None + assert response.data["missing_text"] == True + assert response.data["low_quality"] == False \ No newline at end of file diff --git a/frontend/cypress/e2e/blank-gun-detection.cy.js b/frontend/cypress/e2e/blank-gun-detection.cy.js new file mode 100644 index 00000000..8fd9608a --- /dev/null +++ b/frontend/cypress/e2e/blank-gun-detection.cy.js @@ -0,0 +1,54 @@ +describe("Blank Gun Detection", () => { + it("should identificate real blank gun", () => { + cy.Identification(); + + cy.getByDataTestid("select-file").as("fileInput"); + cy.intercept("POST", "/api/upload").as("upload"); + cy.get("@fileInput").selectFile("./cypress/images/blank-gun.jpg", { + force: true, + }); + cy.wait("@upload").then(({ response }) => { + expect(response.statusCode).to.eq(200); + }); + cy.getByDataTestid("next-step").click(); + cy.IdentificationPistoletSemiAuto(); + cy.wait(5000); + cy.url().should("contain", "/guide-identification/resultat-final"); + cy.getByDataTestid("arm-category").should("contain", "Catégorie C"); + }); + + it("should identificate firearm with missing text", () => { + cy.Identification(); + + cy.getByDataTestid("select-file").as("fileInput"); + cy.intercept("POST", "/api/upload").as("upload"); + cy.get("@fileInput").selectFile("./cypress/images/no-text.jpg", { + force: true, + }); + cy.wait("@upload").then(({ response }) => { + expect(response.statusCode).to.eq(200); + }); + cy.getByDataTestid("next-step").click(); + cy.IdentificationBlankGunMissingText(); + cy.url().should("contain", "/guide-identification/resultat-final"); + cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); + }); + + it("should identificate firearm with low quality", () => { + cy.Identification(); + + cy.getByDataTestid("select-file").as("fileInput"); + cy.intercept("POST", "/api/upload").as("upload"); + cy.get("@fileInput").selectFile("./cypress/images/low-quality.jpg", { + force: true, + }); + cy.wait("@upload").then(({ response }) => { + expect(response.statusCode).to.eq(200); + }); + cy.getByDataTestid("next-step").click(); + cy.IdentificationBlankGunLowQuality(); + cy.url().should("contain", "/guide-identification/resultat-final"); + cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); + }); + }); + \ No newline at end of file diff --git a/frontend/cypress/e2e/firearm-confidence.cy.js b/frontend/cypress/e2e/firearm-confidence.cy.js index f84e8222..f882016c 100644 --- a/frontend/cypress/e2e/firearm-confidence.cy.js +++ b/frontend/cypress/e2e/firearm-confidence.cy.js @@ -12,6 +12,7 @@ describe("Firearm Confidence", () => { }); cy.getByDataTestid("next-step").click(); cy.IdentificationPistoletSemiAuto(); + cy.wait(5000); cy.url().should("contain", "/guide-identification/resultat-final"); cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); }); diff --git a/frontend/cypress/e2e/firearm-identification.cy.js b/frontend/cypress/e2e/firearm-identification.cy.js index 1b2ecc93..838ca590 100644 --- a/frontend/cypress/e2e/firearm-identification.cy.js +++ b/frontend/cypress/e2e/firearm-identification.cy.js @@ -11,6 +11,7 @@ describe("Firearm Identification", () => { }); cy.getByDataTestid("next-step").click(); cy.IdentificationPistoletSemiAuto(); + cy.wait(5000); cy.url().should("contain", "/guide-identification/resultat-final"); cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); cy.getByDataTestid("return-to-home-end").click(); diff --git a/frontend/cypress/e2e/firearm-securing.cy.js b/frontend/cypress/e2e/firearm-securing.cy.js index bf3888ba..fb5538af 100644 --- a/frontend/cypress/e2e/firearm-securing.cy.js +++ b/frontend/cypress/e2e/firearm-securing.cy.js @@ -26,6 +26,7 @@ describe("Securing Firearm and Identification", () => { cy.contains("p", "Basegun a identifié votre arme"); cy.getByDataTestid("next-step").click(); cy.IdentificationPistoletSemiAuto(); + cy.wait(5000); cy.url().should("contain", "/guide-identification/resultat-final"); cy.getByDataTestid("arm-category").should("contain", "Catégorie B"); cy.getByDataTestid("return-to-home-end").click(); diff --git a/frontend/cypress/images/blank-gun.jpg b/frontend/cypress/images/blank-gun.jpg new file mode 100755 index 00000000..936f38fc Binary files /dev/null and b/frontend/cypress/images/blank-gun.jpg differ diff --git a/frontend/cypress/images/low-quality.jpg b/frontend/cypress/images/low-quality.jpg new file mode 100644 index 00000000..6682df31 Binary files /dev/null and b/frontend/cypress/images/low-quality.jpg differ diff --git a/frontend/cypress/images/no-text.jpg b/frontend/cypress/images/no-text.jpg new file mode 100644 index 00000000..d11abd33 Binary files /dev/null and b/frontend/cypress/images/no-text.jpg differ diff --git a/frontend/cypress/support/commands.js b/frontend/cypress/support/commands.js index 5cb05b48..93522f93 100644 --- a/frontend/cypress/support/commands.js +++ b/frontend/cypress/support/commands.js @@ -109,11 +109,11 @@ Cypress.Commands.add("IdentificationPistoletSemiAuto", () => { cy.contains("Cartouches").first().click(); cy.getByDataTestid("next-step").should("not.have.attr", "disabled"); cy.getByDataTestid("next-step").click(); - cy.url().should("contain", "/guide-identification/armes-alarme"); - cy.getByDataTestid("instruction-armeAlarme").should("contain", "Votre arme"); - cy.getByDataTestid("next-step").click(); - cy.getByDataTestid("aucune-correspondance").click(); - cy.getByDataTestid("next-step").click(); + cy.url().should("contain", "/guide-identification/qualite-image"); + cy.getByDataTestid("title-page").should( + "contain", + "Identification d'une arme d'alarme", + ); }); Cypress.Commands.add("IdentificationRevolver", () => { @@ -133,11 +133,9 @@ Cypress.Commands.add("IdentificationRevolver", () => { cy.contains("Balles").first().click(); cy.getByDataTestid("next-step").should("not.have.attr", "disabled"); cy.getByDataTestid("next-step").click(); - cy.url().should("contain", "/guide-identification/armes-alarme"); - cy.getByDataTestid("instruction-armeAlarme").should("contain", "Votre arme"); - cy.getByDataTestid("next-step").click(); - cy.getByDataTestid("aucune-correspondance").click(); - cy.getByDataTestid("next-step").click(); + cy.url().should("contain", "/guide-identification/qualite-image"); + cy.getByDataTestid("title-page").should("contain", "Marquages non détéctés"); + cy.get('.fr-col-12 > [data-testid="next-step"]').click(); }); Cypress.Commands.add("arrierePlatRevolver", () => { @@ -198,3 +196,41 @@ Cypress.Commands.add("pasDeGuide", () => { cy.getByDataTestid("go-to-identification").click(); cy.url().should("contain", "/guide-identification/resultat-typologie"); }); + +Cypress.Commands.add("IdentificationBlankGunMissingText", () => { + cy.url().should( + "contain", + "guide-identification/informations-complementaires", + ); + cy.getByDataTestid("next-step").click(); + cy.url().should("contain", "/guide-identification/munition-type"); + cy.getByDataTestid("next-step").should("have.attr", "disabled"); + cy.contains("Cartouches").first().click(); + cy.getByDataTestid("next-step").should("not.have.attr", "disabled"); + cy.getByDataTestid("next-step").click(); + cy.url().should("contain", "/guide-identification/qualite-image"); + cy.getByDataTestid("title-page").should( + "contain", + "Marquages non détéctés", + ); + cy.get('.fr-col-12 > [data-testid="next-step"]').click(); +}); + +Cypress.Commands.add("IdentificationBlankGunLowQuality", () => { + cy.url().should( + "contain", + "guide-identification/informations-complementaires", + ); + cy.getByDataTestid("next-step").click(); + cy.url().should("contain", "/guide-identification/munition-type"); + cy.getByDataTestid("next-step").should("have.attr", "disabled"); + cy.contains("Cartouches").first().click(); + cy.getByDataTestid("next-step").should("not.have.attr", "disabled"); + cy.getByDataTestid("next-step").click(); + cy.url().should("contain", "/guide-identification/qualite-image"); + cy.getByDataTestid("title-page").should( + "contain", + "Qualité d'image insuffisante", + ); + cy.get('.fr-col-12 > [data-testid="next-step"]').click(); +}); diff --git a/frontend/src/views/GuideIdentificationFirearm/GuideIdentificationFirearm.vue b/frontend/src/views/GuideIdentificationFirearm/GuideIdentificationFirearm.vue index 6fa6c421..aee1610b 100644 --- a/frontend/src/views/GuideIdentificationFirearm/GuideIdentificationFirearm.vue +++ b/frontend/src/views/GuideIdentificationFirearm/GuideIdentificationFirearm.vue @@ -292,6 +292,7 @@ watch(alarmModel, (newVal) => { {