Sams Surfshop

Doing Sams Surfshop (https://www.codecademy.com/courses/learn-intermediate-python-3/projects/int-python-sams-surf-shop) and I am stuck on step 8. When I test the code, it is 2 errors instead of 1. I know where to look for the problem going by the errors but I am not sure how to fix them. Did I miss a step? Any advice would be appreciated thank you.
here is my code:

import unittest
import surfshop

class tests(unittest.TestCase):

 def setUp(self):
  self.cart = surfshop.ShoppingCart()

  
 def test_add1_surfboards(self):
  message = self.cart.add.surfboards(1)
  self.assertEqual(message, 'Successfully added 1 surfboard to cart!')


 def test_add2_surfboards(self):
  message = self.cart.add.surfboards(2)
  self.assertEqual(message, 'Successfully added 2 surfboards to cart!')

 def test_cart_limits(self):
   self.assertRaises(surfshop.TooManyBoardsError, self.cart.add_surfboards, 5)

 @unittest.expectedFailure
 def test_local_discounts(self):
   self.local_discounts
   self.assertTrue(cart.apply_locals_discount, cart.locals_discount())

unittest.main()

now here is the error:

EE.x
======================================================================
ERROR: test_add1_surfboards (__main__.tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 12, in test_add1_surfboards
    message = self.cart.add.surfboards(1)
AttributeError: 'ShoppingCart' object has no attribute 'add'

======================================================================
ERROR: test_add2_surfboards (__main__.tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests.py", line 17, in test_add2_surfboards
    message = self.cart.add.surfboards(2)
AttributeError: 'ShoppingCart' object has no attribute 'add'

----------------------------------------------------------------------
Ran 4 tests in 0.001s

FAILED (errors=2, expected failures=1)

Hiya!

On line 12 you are calling “self.cart.add.surfboards(1)” which seems to be suffering from a slight typo. The AttributeError is telling you that there is no such attribute ‘add’ in the ShoppingCart object, but you seem to be calling a method of this class.

Take a look at the methods in the surfshop.py file and compare the method with the call in your test.

Good luck learning :slight_smile:

Okay, I found the errors and my code looks like this:

# Write your code below:
import unittest
import surfshop

class tests(unittest.TestCase):

 def setUp(self):
  self.cart = surfshop.ShoppingCart()

  
 def test_add1_surfboards(self):
    message = self.cart.add_surfboards(1) self.assertEqual(message, 'Successfully added 1 surfboard to cart!')


 def test_add2_surfboards(self):
   message = self.cart.add_surfboards(2)
self.assertEqual(message,'Sucessfully added 2 surfboards to cart!')

 def test_cart_limits(self):
   self.assertRaises(surfshop.TooManyBoardsError, self.cart.add_surfboards, 5)

 @unittest.expectedFailure
 def test_local_discounts(self):
  self.local_discounts
  self.assertTrue(cart.apply_locals_discount, cart.locals_discount())

unittest.main()

and now it is throwing this error:

File "tests.py", line 12
    message = self.cart.add_surfboards(1) self.assertEqual(message, 'Successfully added 1 surfboard to cart!')
                                             ^
SyntaxError: invalid syntax

Now, from what I remember of syntax, it involves spelling or proper placement of punctuation. I know the problem is in line 12 but I am unsure where.

that should be 2 separate lines:

    message = self.cart.add_surfboards(1) 
    self.assertEqual(message, 'Successfully added 1 surfboard to cart!')
1 Like

its working now thanks