Sam's Surf Shop help

Hi, I am trying to complete this project.
https://www.codecademy.com/courses/learn-intermediate-python-3/projects/int-python-sams-surf-shop
I am getting all knids of errors I can’t solve. I would appreciate any help out there.
My code so far

import surfshop
import unittest


class TestClass(unittest.TestCase):
  def setup(self,):
    self.cart = surfshop.ShoppingCart()
  
  def test_add1_surfboards(self,):
    message = self.cart.add_surfborads(1)
    self.assertEqual(message, 'Successfully added 1 surfboard to cart!')
  
  def test_add2_surboards(self,):
    message = self.cart.add_surfboards(2)
    self.assertEqual(message, 'Successfully added 2 surfboards to cart!')

  def testTooMany(self):
    self.assertRaises(surfshop.TooManyBoardsError, surfshop.ShoppingCart.add_surfboards, 5)

  @unittest.expectedFailure
  def testDiscount(self):
    self.assertTrue(surfshop.ShoppingCart.apply_locals_discount() is True)

unittest.main()

The Errors

ERROR: testTooMany (main.TestClass)

Traceback (most recent call last):
File “tests.py”, line 19, in testTooMany
self.assertRaises(surfshop.TooManyBoardsError, surfshop.ShoppingCart.add_surfboards, 5)
File “/usr/lib/python3.6/unittest/case.py”, line 733, in assertRaises
return context.handle(‘assertRaises’, args, kwargs)
File “/usr/lib/python3.6/unittest/case.py”, line 178, in handle
callable_obj(*args, **kwargs)
File “/home/ccuser/workspace/sams-surf-shop/surfshop.py”, line 16, in add_surfboards
if self.num_surfboards + quantity > 4:
AttributeError: ‘int’ object has no attribute ‘num_surfboards’

======================================================================
ERROR: test_add1_surfboards (main.TestClass)

Traceback (most recent call last):
File “tests.py”, line 11, in test_add1_surfboards
message = self.cart.add_surfborads(1)
AttributeError: ‘TestClass’ object has no attribute ‘cart’

======================================================================
ERROR: test_add2_surboards (main.TestClass)

Traceback (most recent call last):
File “tests.py”, line 15, in test_add2_surboards
message = self.cart.add_surfboards(2)
AttributeError: ‘TestClass’ object has no attribute ‘cart’


Ran 4 tests in 0.001s

FAILED (errors=3, expected failures=1)

I had setUp instead of setup
I also didn’t have the comma after the self parameter.

in the testTooMany or the equivalent,
I had self.cart.add_surfboards instead of surfshop.ShoppingCart.add_surfboards
because the object (instance of surfshop.ShoppingCart) I was using to do the test was self.cart
I also had a @unittest.skip before that function (when the project was complete).

1 Like

@janbazant1107978602 big thanks. That solved it. I was going cross eyed looking at my code.