"""Tests for shipping.py. Give this file to the AI with shipping.py. They pass before the
refactor and must still pass after it. Run: python3 -m unittest test_shipping.py"""
import unittest

from shipping import shipping_cost


def order(country="US", weight=1.0, subtotal=1000, express=False, **extra):
    o = {"country": country, "weight_kg": weight, "subtotal_cents": subtotal, "express": express}
    o.update(extra)
    return o


class ShippingCostTest(unittest.TestCase):
    def test_us_standard(self):
        self.assertEqual(shipping_cost(order(weight=0.5)), 500)
        self.assertEqual(shipping_cost(order(weight=3)), 800)
        self.assertEqual(shipping_cost(order(weight=8)), 2000)

    def test_us_free_over_50_dollars(self):
        self.assertEqual(shipping_cost(order(weight=8, subtotal=5000)), 0)

    def test_us_express(self):
        self.assertEqual(shipping_cost(order(weight=1, express=True)), 1200)
        self.assertEqual(shipping_cost(order(weight=7, express=True, subtotal=9000)), 3000)

    def test_canada_and_mexico(self):
        self.assertEqual(shipping_cost(order("CA", weight=2)), 1800)
        self.assertEqual(shipping_cost(order("MX", weight=6, express=True)), 5300)

    def test_member_discount(self):
        self.assertEqual(shipping_cost(order(weight=3, member=True)), 720)

    def test_unknown_country(self):
        with self.assertRaises(ValueError):
            shipping_cost(order("FR"))

    def test_too_heavy(self):
        with self.assertRaises(ValueError):
            shipping_cost(order(weight=31))


if __name__ == "__main__":
    unittest.main()
