I’m trying to write a unittest for an assignment and am puzzled at… I’m trying to write a unittest for an assignment and am puzzled at what to do and am stuck. Here’s the prompt for the assignment:You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer and Store. All data members of each class should be marked as private (a leading underscore in the name). Since they’re private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention (“get_” or “set_” followed by the name of the data member).Here are the method descriptions for the three classes:Product:A Product object represents a product with an ID code, title, description, price and quantity available.init method – Takes as parameters five values with which to initialize the Product: it’s ID, title, description, price, and quantity_available. You can assume unique IDs will be used.get methods for each of the data members, named get_product_id, get_title, get_description, get_price, and get_quantity_availabledecrease_quantity – Decreases the quantity available by oneCustomer:A Customer object represents a customer with a name and account ID. Customers must be members of the Store to make a purchase. Premium members get free shipping.init method – Takes as parameters three values with which to initialize the Customer: their name, ID, and whether the customer is a premium_member (that last one is a Boolean value).A customer’s cart is a collection of Product ID codes – you can choose what type of collection (e.g. list, dictionary, etc.). Since the cart is private, you’ll also need to create a get method for itget methods named get_name and get_customer_idis_premium_member – Returns whether the customer is a premium member (True or False)add_product_to_cart – Takes a product ID code and adds it to the Customer’s cartempty_cart – Empties the Customer’s cartStore:A Store object represents a store, which has some number of products in its inventory and some number of customers as members.A Store’s inventory is a collection of Products that are part of the Store – you can choose what type of collection (e.g. list, dictionary, etc.)A Store’s membership is a collection of Customers that are members of the Store – you can choose what type of collection (e.g. list, dictionary, etc.)init method – Does whatever initialization is needed for your Storeadd_product – Takes a Product object and adds it to the inventoryadd_member – Takes a Customer object and adds it to the membershiplookup_product_from_id – Takes a Product ID and returns the Product with the matching ID. If no matching ID is found in the inventory, it returns the special value Nonelookup_member_from_id – Takes a Customer ID and returns the Customer with the matching ID. If no matching ID is found in the membership, it returns the special value Noneproduct_search – Takes a search string and returns a sorted (in lexicographic order) list of ID codes for every product in the inventory whose title or description contains the search string. The search should be case-insensitive, i.e. a search for “wood” should match Products that have “Wood” in their title or description, and a search for “Wood” should match Products that have “wood” in their title or description (such as “woodchuck”). The list of ID codes should not contain duplicates. You may assume that the search string will consist of a single word. If the search string is not found, return an empty list.add_product_to_member_cart – Takes a Product ID and a Customer ID (in that order). If the product isn’t found in the inventory, return “product ID not found”. If the product was found, but the member isn’t found in the membership, return “member ID not found”. If both are found and the product is still available, call the member’s add_product_to_cart method to add that product’s ID to the cart and then return “product added to cart”. If the product was not still available, return “product out of stock”. This function does not need to check how many of that product are available – just that there is at least one. It should not change how many are available – that happens during checkout. The same product can be added multiple times if the customer wants more than one of something.check_out_member – Takes a Customer ID. If the ID doesn’t match a member of the Store, raise an InvalidCheckoutError (you’ll need to define this exception class). Otherwise return the charge for the member’s cart. This will be the total cost of all the items in the cart, not including any items that are not in the inventory or are out of stock, plus the shipping cost. If a product is not out of stock, you should add its cost to the total and decrease the available quantity of that product by 1. Note that it is possible for an item to go out of stock during checkout. For example, if the customer has two of the same product in their cart, but the store only has one of that product left, the customer will be able to buy the one that’s available, but won’t be able to buy a second one, because it’s now out of stock. For premium members, the shipping cost is $0. For normal members, the shipping cost is 7% of the total cost of the items in the cart. When the charge for the member’s cart has been tabulated, the member’s cart should be emptied, and the charge amount returned. Don’t round any results.You must include a main function that runs if the file is run as a script, but not if the file is imported. The main function should try to check out a member. If an InvalidCheckoutError is raised, it should be caught with a try/except that prints an explanatory message for the user (otherwise the checkout should proceed normally).In addition to your file containing the code for the above classes, you must also submit a file named StoreTester.py that contains unit tests for your Store.py file. It must have at least five unit tests and use at least three different assert functions. This part (like the rest) must be your own work – do not copy someone else’s work. Make sure you understand the differences between unit tests vs asserts correctly.Here’s a very simple example of how your classes could be used:p1 = Product(“889”, “Rodent of unusual size”, “when a rodent of the usual size just won’t do”, 33.45, 8)c1 = Customer(“Yinsheng”, “QWF”, False)myStore = Store()myStore.add_product(p1)myStore.add_member(c1)myStore.add_product_to_member_cart(“889”, “QWF”)result = myStore.check_out_member(“QWF”)I need to have five different unit tests with three different assert functions and am getting errors every time I try to fix something. Here’s what I have:import unittestimport Storeclass TestStore(unittest.TestCase): p1 = Store.Product(“889”, “Rodent of unusual size”, “when a rodent of the usual size just won’t do”, 33.45, 8) c1 = Store.Customer(“Yinsheng”, “QWF”, False) myStore = Store.Store() myStore.add_product(p1) myStore.add_member(c1) myStore.add_product_to_member_cart(“889”, “QWF”) product_details = myStore.lookup_product_from_id(“889”) def test_1(self): self.assertEqual(self.myStore.product_search(“Rodent of unusual size”), [“889”]) def test_2(self): self.assertEqual(self.product_details.get_quantity_available(), 8) def test_3(self): self.assertEqual(self.myStore.check_out_member(“QWF”), 33.45) def test_4(self): self.assertEqual(self.product_details.get_quantity_available(), 7) def test_5(self): with self.assertRaises(self.myStore.check_out_member(“QQQ”)if __name__ == ‘__main__’: unittest.main()Also, this is my Store file:class Product: def __init__(self, ID_code, title, description, price, quantity_available): self._product_ID = ID_code self._title = title self._description = description self._price = price self._quantity_available = quantity_available def get_product_id(self): return self._product_ID def get_title(self): return self._title def get_description(self): return self._description def get_price(self): return self._price def get_quantity_available(self): return self._quantity_available def decrease_quantity(self): self._quantity_available = self._quantity_available – 1 return self._quantity_availableclass Customer: def __init__(self, name, ID, premium_member): self._name = name self._account_ID = ID self._premium_member = premium_member self._cart = list() def get_name(self): return self._name def get_customer_id(self): return self._account_ID def get_cart(self): return self._cart def is_premium_member(self): return self._premium_member def add_product_to_cart(self, product): self._cart.append(product) def empty_cart(self): self._cart.clear()class Store: def __init__(self): self._store_inventory = list() self._store_membership = list() def add_product(self, product): self._store_inventory.append(product) def add_member(self, member): self._store_membership.append(member) def lookup_product_from_id(self, product_id): for product in self._store_inventory: if product.get_product_id() == product_id: return product return None def lookup_member_from_id(self, customer_id): for member in self._store_membership: if member.get_customer_id() == customer_id: return member return None def product_search(self, search): list_of_ids = list() for product in self._store_inventory: if search.lower() in product.get_description().lower() or search.lower() in product.get_title().lower(): list_of_ids.append(product.get_product_id()) list_of_ids.sort() return list_of_ids def add_product_to_member_cart(self, product_id, member_id): product = self.lookup_product_from_id(product_id) customer = self.lookup_member_from_id(member_id) if product and customer: if not product.get_quantity_available: return “Product is out of stock.” customer.add_product_to_cart(product) return “Product added to cart.” elif not product: return “Product ID not found.” elif not customer: return “Member ID not found.” def check_out_member(self, customer_id): cust = self.lookup_member_from_id(customer_id) total_cost = 0 if cust: for product in self._store_inventory: if product.get_quantity_available(): product.decrease_quantity() total_cost += product.get_price() else: raise InvalidCheckoutError(“You can’t buy” + product.get_title() + “it’s not available.”) if cust.is_premium_member(): total_cost -= total_cost / 1.07 return total_cost else: raise InvalidCheckoutError(“Customer is not found.”)class InvalidCheckoutError(BaseException): passif __name__ == ‘__main__’: try: p1 = Product(“889”, “Rodent of unusual size”, “when a rodent of the usual size just won’t do”, 33.45, 8) c1 = Customer(“Yinsheng”, “QWF”, False) myStore = Store() myStore.add_product(p1) myStore.add_member(c1) myStore.add_product_to_member_cart(“889”, “QWF”) result = myStore.check_out_member(“QWF”) print(result) except InvalidCheckoutError as inv: print(inv.__str__())Computer ScienceEngineering & TechnologyPython Programming CS MISC
solved : I’m trying to write a unittest for an assignment and am puzz
How it works
- Paste your instructions in the instructions box. You can also attach an instructions file
- Select the writer category, deadline, education level and review the instructionsÂ
- Make a payment for the order to be assigned to a writer
- Â Download the paper after the writer uploads itÂ
Will the writer plagiarize my essay?
You will get a plagiarism-free paper and you can get an originality report upon request.
Is this service safe?
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
LET THE PROFESSIONALS WRITE YOUR PAPER!