def test_init_string(self): phone = PhoneData(brand="test", model="Megatron", price="500000 VND", vendor="unitTest") self.assertEqual(phone.getPrice(), 500000) self.assertEqual(phone.getName(), "test Megatron") phone2 = PhoneData(brand="test", model="Megatron XL", price="1000000 VND", vendor="unitTest", info={"url": "https:/testURL.com"}) self.assertEqual(phone2.getPrice(), 1000000) self.assertEqual(phone2.getName(), "test Megatron XL") self.assertEqual(phone2.getInfo()["url"], "https:/testURL.com") phone3 = PhoneData(brand="test 1", model="Decepticon", price="$SGD 300000", vendor="unitTest", info={"url": "https:/testURL.com"}) self.assertEqual(phone3.getPrice(), 300000) self.assertEqual(phone3.getName(), "test 1 Decepticon") self.assertEqual(phone3.getInfo()["currency"], "SGD") with self.assertRaises(PhoneDataInvalidException): phone4 = PhoneData(brand="test 1", model="Decepticon", price="$SGD abc 300000 ", vendor="unitTest", info={"url": "https:/testURL.com"})
def test_init_decimal(self): phone = PhoneData(brand="test", model="Megatron", price=500000, vendor="unitTest", info={"currency": "SGD"}) self.assertEqual(phone.getPrice(), 500000) self.assertEqual(phone.getName(), "test Megatron") phone2 = PhoneData(brand="test", model="Decepticon", price=300.123, vendor="unitTest", info={ "url": "https:/testURL.com", "currency": "VND" }) self.assertEqual(phone2.getPrice(), 300.123) self.assertEqual(phone2.getName(), "test Decepticon") self.assertEqual(phone2.getInfo()["url"], "https:/testURL.com") self.assertEqual(phone2.getInfo()["currency"], "VND") with self.assertRaises(PhoneDataInvalidException): phone3 = PhoneData(brand="test", model="Decepticon", price=-300.123, vendor="unitTest", info={ "url": "https:/testURL.com", "currency": "VND" })
def convertPhoneToDBData(phone: PhoneData): return { 'BRAND': phone.getBrand(), 'MODEL': phone.getDBModel(), 'NAME': phone.getName(), 'TYPE': 'Mobile', 'PRICE': phone.getPrice(), 'VENDOR': phone.getVendor(), 'INFO': phone.getInfo() }
def __init__(self, firstPhone: PhoneData): self.brand = firstPhone.getBrand() self.model = firstPhone.getModel() self.name = firstPhone.getName() self.minPrice = firstPhone.getPrice() self.phoneList = [firstPhone]