def setUp(self): self.auction_event = Auction_event() self.user = User(Name("Patrick", "", "Wu"), Card("1234567890123456", "123", 2099, 12), Addr("Room A, Rd B", "London", "UK", "WC1E 6BT")) self.item1 = Item("iPhone XS Max Space Grey", "A2104 256G", 6000) self.item2 = Item("Google Pixel 3 XL", "G013C 64G", 5000)
def main(): auction = Auction(Item("iPhone XS Max", "iPhone A2104 256G", 6000)) user = User(Name("Patrick", "", "Wu"), Card("1234567890", "123", 2099, 12), Addr("Room A, Road B", "London", "UK", "WC1E 6BT")) auction.start() user.bid(auction, 6010) user.bid(auction, 6020) auction.stop()
def users_handler(): if request.method == 'GET': return jsonify(users) else: first_name = request.form.get('first_name') middle_name = request.form.get('middle_name') last_name = request.form.get('last_name') card_number = request.form.get('card_number') cvc = request.form.get('cvc') expiry_year = request.form.get('expiry_year') expiry_month = request.form.get('expiry_month') addr_detail = request.form.get('addr_detail') city = request.form.get('city') postal = request.form.get('postal') new_user = User(Name(first_name, middle_name, last_name), Card(card_number, cvc, expiry_year, expiry_month), Addr(addr_detail, city, postal)) users.append(new_user) return jsonify(new_user.id)
def setUp(self): self.auction = Auction(Item("iPhone XS Max", "iPhone A2104 256G", 6000)) self.user = User(Name("Patrick", "", "Wu"), Card("1234567890123456", "000", 2099, 12), Addr("Room A, Road B", "London", "UK", "WC1E 6BT"))
def testValidCard(self): self.card = Card("1234567890123456", "123", 2099, 7) self.assertEqual(self.card.number, "1234567890123456") self.assertEqual(self.card.cvc, "123") self.assertEqual(self.card.expiry_year, 2099) self.assertEqual(self.card.expiry_month, 7)
def testInvalidCard(self): with self.assertRaises(Exception) as context: self.card = Card("1234567890123456", "123", 2008, 9) self.assertTrue("Card invalid" in str(context.exception))
def testUnparsableDate(self): with self.assertRaises(Exception) as context: self.card = Card("1234567890123456", "123", "aabb", "cd") self.assertTrue("Couldn't parse input expiry year or month" in str( context.exception))
def testWrongCVC(self): with self.assertRaises(Exception) as context: self.card = Card("1234567890123456", "aab", 2020, 11) self.assertTrue( "Card CVC should 3 digits long" in str(context.exception))
def testWrongCardNumber(self): with self.assertRaises(Exception) as context: self.card = Card("1234", "123", 2020, 11) self.assertTrue( "Card number should be 16 digits long" in str(context.exception))