|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
5 | | - "id": "86f6f880", |
| 5 | + "id": "c32b393f", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | | - "# 🚀 Progetto finale: Gestione di un inventario avanzato\n", |
| 8 | + "# 🚀 11 - Progetto finale: Gestione di un inventario avanzato\n", |
9 | 9 | "\n", |
10 | 10 | "---\n", |
11 | 11 | "## Introduzione al progetto\n", |
|
26 | 26 | }, |
27 | 27 | { |
28 | 28 | "cell_type": "markdown", |
29 | | - "id": "129f6294", |
| 29 | + "id": "0a7aa72a", |
30 | 30 | "metadata": {}, |
31 | 31 | "source": [ |
32 | 32 | "---\n", |
|
51 | 51 | }, |
52 | 52 | { |
53 | 53 | "cell_type": "markdown", |
54 | | - "id": "beb7e015", |
| 54 | + "id": "87f28809", |
55 | 55 | "metadata": {}, |
56 | 56 | "source": [ |
57 | 57 | "---\n", |
|
90 | 90 | }, |
91 | 91 | { |
92 | 92 | "cell_type": "markdown", |
93 | | - "id": "d4995c19", |
| 93 | + "id": "cd7ffc7e", |
94 | 94 | "metadata": {}, |
95 | 95 | "source": [ |
96 | 96 | "---\n", |
|
101 | 101 | }, |
102 | 102 | { |
103 | 103 | "cell_type": "markdown", |
104 | | - "id": "8e547474", |
| 104 | + "id": "43881c13", |
105 | 105 | "metadata": {}, |
106 | 106 | "source": [ |
107 | 107 | "### `models.py`\n", |
|
112 | 112 | { |
113 | 113 | "cell_type": "code", |
114 | 114 | "execution_count": null, |
115 | | - "id": "9d8fe588", |
| 115 | + "id": "2e788715", |
116 | 116 | "metadata": {}, |
117 | 117 | "outputs": [], |
118 | 118 | "source": [ |
|
193 | 193 | }, |
194 | 194 | { |
195 | 195 | "cell_type": "markdown", |
196 | | - "id": "3525552b", |
| 196 | + "id": "d1e197e5", |
197 | 197 | "metadata": {}, |
198 | 198 | "source": [ |
199 | 199 | "### `inventory_manager.py`\n", |
|
204 | 204 | { |
205 | 205 | "cell_type": "code", |
206 | 206 | "execution_count": null, |
207 | | - "id": "4f1cd8e5", |
| 207 | + "id": "e4285097", |
208 | 208 | "metadata": {}, |
209 | 209 | "outputs": [], |
210 | 210 | "source": [ |
|
287 | 287 | }, |
288 | 288 | { |
289 | 289 | "cell_type": "markdown", |
290 | | - "id": "89d3b2a2", |
| 290 | + "id": "73031b16", |
291 | 291 | "metadata": {}, |
292 | 292 | "source": [ |
293 | 293 | "### `main.py`\n", |
|
298 | 298 | { |
299 | 299 | "cell_type": "code", |
300 | 300 | "execution_count": null, |
301 | | - "id": "a011eed3", |
| 301 | + "id": "72655d91", |
302 | 302 | "metadata": {}, |
303 | 303 | "outputs": [], |
304 | 304 | "source": [ |
|
372 | 372 | }, |
373 | 373 | { |
374 | 374 | "cell_type": "markdown", |
375 | | - "id": "364078a1", |
| 375 | + "id": "eca4ed35", |
376 | 376 | "metadata": {}, |
377 | 377 | "source": [ |
378 | 378 | "---\n", |
|
419 | 419 | }, |
420 | 420 | { |
421 | 421 | "cell_type": "markdown", |
422 | | - "id": "4afe141f", |
| 422 | + "id": "917ce1ad", |
423 | 423 | "metadata": {}, |
424 | 424 | "source": [ |
425 | 425 | "---\n", |
|
465 | 465 | { |
466 | 466 | "cell_type": "code", |
467 | 467 | "execution_count": null, |
468 | | - "id": "59985144", |
| 468 | + "id": "d7ecbb8e", |
469 | 469 | "metadata": {}, |
470 | 470 | "outputs": [], |
471 | 471 | "source": [ |
472 | | - "# tests/test_inventory.py\n", |
473 | | - "\n", |
| 472 | + "# test_inventory.py\n", |
474 | 473 | "import unittest\n", |
475 | 474 | "import os\n", |
476 | | - "import json\n", |
477 | 475 | "from inventory_manager import GestoreInventario\n", |
478 | 476 | "from models import Prodotto, ProdottoAlimentare, ProdottoElettronico\n", |
479 | 477 | "\n", |
480 | 478 | "class TestGestoreInventario(unittest.TestCase):\n", |
481 | 479 | "\n", |
482 | 480 | " def setUp(self):\n", |
483 | 481 | " # Viene eseguito prima di ogni test. \n", |
484 | | - " # Rimuove il file inventario per garantire un ambiente pulito.\n", |
| 482 | + " # Assicura un ambiente di test pulito eliminando il file di salvataggio.\n", |
485 | 483 | " self.gestore = GestoreInventario()\n", |
486 | 484 | " if os.path.exists(self.gestore.NOME_FILE):\n", |
487 | 485 | " os.remove(self.gestore.NOME_FILE)\n", |
488 | | - " self.gestore = GestoreInventario() # Crea una nuova istanza pulita\n", |
| 486 | + " # Inizializza un nuovo gestore che inizierà con un inventario vuoto\n", |
| 487 | + " self.gestore = GestoreInventario()\n", |
| 488 | + " self.prodotto_test = Prodotto(\"Test Prodotto\", 10.0, 5)\n", |
489 | 489 | "\n", |
490 | 490 | " def tearDown(self):\n", |
491 | 491 | " # Viene eseguito dopo ogni test. \n", |
492 | | - " # Rimuove il file inventario per pulire l'ambiente.\n", |
| 492 | + " # Pulisce l'ambiente eliminando il file di salvataggio creato.\n", |
493 | 493 | " if os.path.exists(self.gestore.NOME_FILE):\n", |
494 | 494 | " os.remove(self.gestore.NOME_FILE)\n", |
495 | 495 | "\n", |
496 | | - " def test_aggiungi_prodotto(self):\n", |
497 | | - " prodotto1 = Prodotto(\"Pane\", 2.50, 10)\n", |
498 | | - " self.assertTrue(self.gestore.aggiungi_prodotto(prodotto1))\n", |
| 496 | + " def test_aggiungi_prodotto_successo(self):\n", |
| 497 | + " self.assertTrue(self.gestore.aggiungi_prodotto(self.prodotto_test))\n", |
499 | 498 | " self.assertEqual(len(self.gestore.inventario), 1)\n", |
500 | | - " self.assertIn(\"Pane\", self.gestore.inventario)\n", |
| 499 | + " self.assertIn(\"Test Prodotto\", self.gestore.inventario)\n", |
501 | 500 | "\n", |
502 | 501 | " def test_aggiungi_prodotto_esistente(self):\n", |
503 | | - " prodotto1 = Prodotto(\"Pane\", 2.50, 10)\n", |
504 | | - " self.gestore.aggiungi_prodotto(prodotto1)\n", |
505 | | - " prodotto2 = Prodotto(\"Pane\", 3.00, 5) # Stesso nome\n", |
506 | | - " self.assertFalse(self.gestore.aggiungi_prodotto(prodotto2))\n", |
507 | | - " self.assertEqual(self.gestore.inventario['Pane'].quantita, 10)\n", |
| 502 | + " self.gestore.aggiungi_prodotto(self.prodotto_test)\n", |
| 503 | + " prodotto_duplicato = Prodotto(\"Test Prodotto\", 12.0, 3)\n", |
| 504 | + " self.assertFalse(self.gestore.aggiungi_prodotto(prodotto_duplicato))\n", |
| 505 | + " self.assertEqual(self.gestore.inventario['Test Prodotto'].quantita, 5)\n", |
508 | 506 | "\n", |
509 | 507 | " def test_vendi_prodotto_successo(self):\n", |
510 | | - " prodotto = Prodotto(\"Latte\", 1.20, 20)\n", |
511 | | - " self.gestore.aggiungi_prodotto(prodotto)\n", |
512 | | - " self.assertTrue(self.gestore.vendi_prodotto(\"Latte\", 5))\n", |
513 | | - " self.assertEqual(self.gestore.inventario['Latte'].quantita, 15)\n", |
| 508 | + " self.gestore.aggiungi_prodotto(self.prodotto_test)\n", |
| 509 | + " self.assertTrue(self.gestore.vendi_prodotto(\"Test Prodotto\", 3))\n", |
| 510 | + " self.assertEqual(self.gestore.inventario['Test Prodotto'].quantita, 2)\n", |
514 | 511 | "\n", |
515 | 512 | " def test_vendi_prodotto_quantita_insufficiente(self):\n", |
516 | | - " prodotto = Prodotto(\"Latte\", 1.20, 20)\n", |
517 | | - " self.gestore.aggiungi_prodotto(prodotto)\n", |
518 | | - " self.assertFalse(self.gestore.vendi_prodotto(\"Latte\", 25))\n", |
519 | | - " self.assertEqual(self.gestore.inventario['Latte'].quantita, 20)\n", |
| 513 | + " self.gestore.aggiungi_prodotto(self.prodotto_test)\n", |
| 514 | + " self.assertFalse(self.gestore.vendi_prodotto(\"Test Prodotto\", 10))\n", |
| 515 | + " self.assertEqual(self.gestore.inventario['Test Prodotto'].quantita, 5)\n", |
520 | 516 | "\n", |
521 | 517 | " def test_vendi_prodotto_non_esistente(self):\n", |
522 | | - " self.assertFalse(self.gestore.vendi_prodotto(\"Acqua\", 1))\n", |
| 518 | + " self.assertFalse(self.gestore.vendi_prodotto(\"Prodotto Inesistente\", 1))\n", |
523 | 519 | "\n", |
524 | | - " def test_salva_carica_inventario(self):\n", |
525 | | - " prodotto_ali = ProdottoAlimentare(\"Pasta\", 1.0, 50, \"2026-01-01\")\n", |
526 | | - " prodotto_ele = ProdottoElettronico(\"TV\", 800.0, 3, 3)\n", |
| 520 | + " def test_salva_e_carica_inventario(self):\n", |
| 521 | + " prodotto_ali = ProdottoAlimentare(\"Latte\", 1.50, 10, \"30-12-2025\")\n", |
| 522 | + " prodotto_ele = ProdottoElettronico(\"Laptop\", 1200.0, 2, 2)\n", |
527 | 523 | " self.gestore.aggiungi_prodotto(prodotto_ali)\n", |
528 | 524 | " self.gestore.aggiungi_prodotto(prodotto_ele)\n", |
529 | 525 | " self.gestore.salva_inventario()\n", |
530 | 526 | "\n", |
531 | | - " # Crea un nuovo gestore per simulare il caricamento da zero\n", |
| 527 | + " # Crea una nuova istanza di GestoreInventario per simulare un nuovo avvio del programma\n", |
532 | 528 | " nuovo_gestore = GestoreInventario()\n", |
533 | 529 | "\n", |
534 | | - " # Verifica che i prodotti siano stati caricati correttamente\n", |
535 | | - " self.assertIn(\"Pasta\", nuovo_gestore.inventario)\n", |
536 | | - " self.assertIsInstance(nuovo_gestore.inventario['Pasta'], ProdottoAlimentare)\n", |
537 | | - " self.assertEqual(nuovo_gestore.inventario['Pasta'].quantita, 50)\n", |
538 | | - " self.assertEqual(nuovo_gestore.inventario['TV'].get_prezzo(), 800.0)\n", |
| 530 | + " # Verifica che l'inventario sia stato caricato correttamente\n", |
| 531 | + " self.assertIn(\"Latte\", nuovo_gestore.inventario)\n", |
| 532 | + " self.assertIn(\"Laptop\", nuovo_gestore.inventario)\n", |
| 533 | + " self.assertEqual(nuovo_gestore.inventario['Latte'].quantita, 10)\n", |
| 534 | + " self.assertEqual(nuovo_gestore.inventario['Laptop'].get_prezzo(), 1200.0)\n", |
| 535 | + " self.assertIsInstance(nuovo_gestore.inventario['Latte'], ProdottoAlimentare)\n", |
| 536 | + " self.assertIsInstance(nuovo_gestore.inventario['Laptop'], ProdottoElettronico)\n", |
539 | 537 | "\n", |
540 | 538 | "if __name__ == '__main__':\n", |
541 | | - " unittest.main()\n", |
542 | | - "```" |
| 539 | + " unittest.main()\n" |
543 | 540 | ] |
544 | 541 | } |
545 | 542 | ], |
|
0 commit comments