Professional Documents
Culture Documents
import unittest
from user_products import Products
class TestProducts(unittest.TestCase):
"""Test class for Products behaviour"""
def setUp(self):
"""method to run before each test case"""
self.new_products = Products("Sugar", "112233", "q@###!")
def test_products_init(self):
"""Method to check if new_products have been initialized correctly"""
self.assertEqual(self.new_products.product_name, "Sugar")
self.assertEqual(self.new_products.product_code, "112233")
self.assertEqual(self.new_products.generated_code, "q@###!" )
def tearDown(self):
"""Method to clear products list after each test case"""
Products.products_list = []
@classmethod
def products_exist(cls, product_name):
"""
Method that checks if a product already exists
Args:
product_name: account name to search if it already exists
Returns:
Boolean: True or False
"""
for product in cls.products_list:
if product.product_name == product_name:
return True
return False
def test_products_exists(self):
"""
test it we can return a boolean if the products already exist
"""
self.new_products.save_products()
test_product =Products("Macaroni Cheese","223344", "!!@@kk56")
test_product.save_products()
product_exist = Products.products_exist("Macaroni Cheese")
self.assertTrue(product_exist)
def test_display_products(self):
"""test that we return all the contacts saved"""
self.assertEqual(Products.display_products(), Products.products_list)
IMPLEMENTATION
During implementation we use the run.py file to code everything following the methods that we
initiated on the testing phase.
This the first page that the users encounter where we have options of creating a user using cu, login
using lg, or exit the app using ex.
We select create a new user for the app so that they are able to add products using their own
accounts.
The user then proceeds to log in to the newly created account using the username and password
created.
The user successfully logs into the product loader account. We have several keys to select from 1 to
5. We then select number 2 Add a new product to the robot order.
The user the add a new product to the shopping list, we have option to enter a product code, and
also generate the identification code for specific product which is used by the robot system to pick
the specified product. The app then returns to the main menu.