def test_GetOrderHistory(self):
     reviews = [
         shopping.BuyerReview(1, 'This sucks-?', 'chris'),
         shopping.BuyerReview(2, 'This is Great.', 'brent_test'),
         shopping.BuyerReview(3, 'This is Great.', 'brent_test')
     ]
     tags = ['computer', 'laptop', 'mac']
     buyers = ['chris', 'brent', 'aaron']
     sampleHistory = [
         shopping.ShoppingItem(
             'name',
             4.99,
             5,
             reviews,
             tags,
             buyers,
         ),
         shopping.ShoppingItem(
             'name',
             5.99,
             1,
             reviews,
             tags,
             buyers,
         ),
         shopping.ShoppingItem(
             'name',
             5.99,
             1,
             reviews,
             tags,
             buyers,
         )
     ]
 def test_GetNumberSold(self):
     with self.assertRaises(Exception):
         shoppingItem = shopping.ShoppingItem('name', 5.00, 'a', [], [], [])
     with self.assertRaises(Exception):
         shoppingItem = shopping.ShoppingItem('name', 5.00, -5, [], [], [])
     with self.assertRaises(Exception):
         shoppingItem = shopping.ShoppingItem('name', 5.00, 1.5, [], [], [])
 def test_GetPrice(self):
     with self.assertRaises(Exception):
         shoppingItem = shopping.ShoppingItem('name', -5.99, 1, [], [], [])
     with self.assertRaises(Exception):
         shoppingItem = shopping.ShoppingItem('name', '6.02', 1, [], [], [])
     with self.assertRaises(Exception):
         shoppingItem = shopping.ShoppingItem('name', '$0.50', 1, [], [],
                                              [])
     with self.assertRaises(Exception):
         shoppingItem = shopping.ShoppingItem('name', 'a', 1, [], [], [])
    def test_GetUserId(self):
        reviews = [
            shopping.BuyerReview(1, 'This sucks-?', 'chris'),
            shopping.BuyerReview(2, 'This is Great.', 'brent_test'),
            shopping.BuyerReview(3, 'This is Great.', 'brent_test')
        ]
        tags = ['computer', 'laptop', 'mac']
        buyers = ['chris', 'brent', 'aaron']
        sampleHistory = [
            shopping.ShoppingItem(
                'name',
                4.99,
                5,
                reviews,
                tags,
                buyers,
            ),
            shopping.ShoppingItem(
                'name',
                5.99,
                1,
                reviews,
                tags,
                buyers,
            ),
            shopping.ShoppingItem(
                'name',
                5.99,
                1,
                reviews,
                tags,
                buyers,
            )
        ]
        shopperAccount = shopping.ShopperAccount('Chris', sampleHistory)

        with self.assertRaises(Exception):
            shopperAccount = shopping.ShopperAccount(35, sampleHistory)
        with self.assertRaises(Exception):
            shopperAccount = shopping.ShopperAccount('ggh32[]', sampleHistory)
        with self.assertRaises(Exception):
            shopperAccount = shopping.ShopperAccount('Chr', ['this', 'that'])
    def test_ShopperAccountInit(self):
        reviews = [
            shopping.BuyerReview(1, 'This sucks-?', 'chris'),
            shopping.BuyerReview(2, 'This is Great.', 'brent_test'),
            shopping.BuyerReview(3, 'This is Great.', 'brent_test')
        ]
        tags = ['computer', 'laptop', 'mac']
        buyers = ['chris', 'brent', 'aaron']
        sampleHistory = [
            shopping.ShoppingItem(
                'name',
                4.99,
                5,
                reviews,
                tags,
                buyers,
            ),
            shopping.ShoppingItem(
                'name',
                5.99,
                1,
                reviews,
                tags,
                buyers,
            ),
            shopping.ShoppingItem(
                'name',
                5.99,
                1,
                reviews,
                tags,
                buyers,
            )
        ]
        shopperAccount = shopping.ShopperAccount('Chris', sampleHistory)

        self.assertEqual(shopperAccount.getUserId(), 'Chris')
        self.assertEqual(shopperAccount.getOrderHistory(), sampleHistory)
    def test_ShoppingItemInit(self):
        reviews = [
            shopping.BuyerReview(1, 'This sucks-?', 'chris'),
            shopping.BuyerReview(2, 'This is Great.', 'brent_test'),
            shopping.BuyerReview(3, 'This is Great.', 'brent_test')
        ]
        tags = ['computer', 'laptop', 'mac']
        buyers = ['chris', 'brent', 'aaron']
        shoppingItem = shopping.ShoppingItem('name', 5.99, 1, reviews, tags,
                                             buyers)

        # AssertEqual checks two values, if not flags it as failing. Get Testing.
        self.assertEqual(shoppingItem.getName(), 'name')
        self.assertEqual(shoppingItem.getPrice(), 5.99)
        self.assertEqual(shoppingItem.getNumberSold(), 1)
        self.assertEqual(shoppingItem.getAverageRating(), 2)
        self.assertEqual(shoppingItem.getReviews(), reviews)
        self.assertEqual(shoppingItem.getTags(), tags)
        self.assertEqual(shoppingItem.getBuyers(), buyers)
    def test_SetPrice(self):
        reviews = [
            shopping.BuyerReview(1, 'This sucks-?', 'chris'),
            shopping.BuyerReview(2, 'This is Great.', 'brent_test'),
            shopping.BuyerReview(3, 'This is Great.', 'brent_test')
        ]
        tags = ['computer', 'laptop', 'mac']
        buyers = ['chris', 'brent', 'aaron']
        shoppingItem = shopping.ShoppingItem('name', 5.99, 1, reviews, tags,
                                             buyers)

        shoppingItem.setPrice(1.99)
        self.assertEqual(shoppingItem.getPrice(), 1.99)

        with self.assertRaises(Exception):
            testPrice = shoppingItem.setPrice("this one")
        with self.assertRaises(Exception):
            testPrice = shoppingItem.setPrice(-1000.00)
        with self.assertRaises(Exception):
            testPrice = shoppingItem.setPrice("this one")
    def test_AddReview(self):
        reviews = [
            shopping.BuyerReview(1, 'This sucks-?', 'chris'),
            shopping.BuyerReview(2, 'This is Great.', 'brent_test'),
            shopping.BuyerReview(3, 'This is Great.', 'brent_test')
        ]
        tags = ['computer', 'laptop', 'mac']
        buyers = ['chris', 'brent', 'aaron']
        shoppingItem = shopping.ShoppingItem('name', 5.99, 1, reviews, tags,
                                             buyers)

        addSample = shopping.BuyerReview(4, 'This is a new review', 'Mark')
        shoppingItem.addReview(addSample)
        self.assertEqual(shoppingItem.getReviews()[-1], addSample)

        with self.assertRaises(Exception):
            testReview = shoppingItem.addReview('great review')
        with self.assertRaises(Exception):
            testReview = shoppingItem.addReview(25)
        with self.assertRaises(Exception):
            testReview = shoppingItem.addReview(shoppingItem)
    def test_AddPurchase(self):
        reviews = [
            shopping.BuyerReview(1, 'This sucks-?', 'chris'),
            shopping.BuyerReview(2, 'This is Great.', 'brent_test'),
            shopping.BuyerReview(3, 'This is Great.', 'brent_test')
        ]
        tags = ['computer', 'laptop', 'mac']
        buyers = ['chris', 'brent', 'aaron']
        shoppingItem = shopping.ShoppingItem('name', 5.99, 1, reviews, tags,
                                             buyers)

        shoppingItem.addPurchase('Chris')
        self.assertEqual(shoppingItem.getBuyers()[-1], 'Chris')
        self.assertEqual(shoppingItem.getNumberSold(), 2)

        with self.assertRaises(Exception):
            testPurchase = shoppingItem.addPurchase(25)
        with self.assertRaises(Exception):
            testPurchase = shoppingItem.addPurchase(-5)
        with self.assertRaises(Exception):
            testPurchase = shoppingItem.addPurchase('??!_SDJM||')