You are on page 1of 10

Testing initialization

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@###!" )

Testing Save product in the memory


def save_products(self):
""" Method to save products"""
self.products_list.append(self)

test case for save products


def test_save_products(self):
"""Method to check if new_products have been saved"""
self.new_products.save_products()
self.assertEqual(len(Products.products_list),1)

Test if we are able to save multiple products


def test_save_multiple_products(self):
"""Method to check save multiples products to products list"""
self.new_products.save_products()
new_second_products = Products("Bread","445566", "kkr$$!")
new_second_products.save_products()
self.assertEqual(len(Products.products_list),2)

def tearDown(self):
"""Method to clear products list after each test case"""
Products.products_list = []

teardown method to clear product list …..


Testing if we can delete a product after adding it on the list.
def delete_product(self):
"""Method to delete product"""
Products.products_list.remove(self)

Test case for delete function


def test_delete_product(self):
"""Method to test delete product"""
self.new_products.save_products()
new_second_products = Products("Bread","445566", "kkr$$!")
new_second_products.save_products()
Products.delete_product(new_second_products)
self.assertEqual(len(Products.products_list),1)

Testing if we can find a product by name on the stored list of items.


@classmethod
def find_product_by_name(cls, product_name):
""""Method that takes account name and returns the name and password
Args:
product_name
return:
product_name and password
"""
for product in cls.products_list:
if product.product_name == product_name:
return product

Test case for find product by name.


def test_find_product_by_name(self):
"""Test if we can find products"""
self.new_products.save_products()
new_test_product = Products("Milk","456789", "bb&&kk!")
new_test_product.save_products()
product_found = Products.find_product_by_name("Milk")
self.assertEqual(product_found.product_name, new_test_product.product_name)
Method to confirm if a product exists in the product 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

Test case for the product exists method.

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)

Method to display all the products


@classmethod
def display_products(cls):
"""
method that returns products list
"""
return cls.products_list
Test case for method display products

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.

We select view the product to see if it has been added successfully;


select option 1.
We can select to continue y/n but we are able to view all the added products.
The functionally is that suppose you have a product by mistake, then we are able to remove it by
selecting option number 3.

We confirm if we have added an item by the use a search method.

User can log out using option 5.


MAINTENANCE

You might also like