Challenge 1
Configure the lookup mock to return a known product mapping, then check the lookup interaction and calculated total.
import unittest
from unittest.mock import Mock
def double_price(product_id, lookup):
return lookup(product_id)["price"] * 2
class TestDoublePrice(unittest.TestCase):
def test_known_price(self):
lookup = Mock(={"price": 6})
result = double_price("sku-3", lookup)
lookup.assert_called_once_with("sku-3")
self.assertEqual(result, 12)
if __name__ == "__main__":
unittest.main(argv=["exercise"], exit=False)
Press Ctrl⌘Enter to check your answer