def test_ticket_init(self): ticket = Ticket(USER_ID, USERNAME) self.assertDictEqual( ticket.to_dict(), dict( id=0, category=int(), date=int(), price_id=int(), quantity=int(), section='', row='', seat='', wish_dates=list(), wish_price_ids=list(), wish_quantities=list(), source_id=0, remarks='', status=1, username=USERNAME, user_id=USER_ID, created_at=ticket.created_at, updated_at=ticket.updated_at ) )
def test_drafting_ticket(self): ticket = Ticket(user_id=USER_ID, username=USERNAME) ticket.update_field('date', 503) self.helper.save_drafting_ticket(user_id=USER_ID, ticket=ticket) ticket_in_cache = self.helper.load_drafting_ticket(user_id=USER_ID) assert ticket_in_cache.user_id assert ticket_in_cache.user_id == ticket.user_id assert ticket_in_cache.username assert ticket_in_cache.username == ticket.username assert ticket_in_cache.to_dict() == ticket.to_dict() # Reset Ticket raw_ticket = Ticket(user_id=USER_ID, username=USERNAME) ticket_in_cache = self.helper.reset_drafting_ticket(user_id=USER_ID, username=USERNAME) assert ticket_in_cache.to_dict() == raw_ticket.to_dict() assert ticket_in_cache.username == raw_ticket.username
def test_validator_error_message(self): ticket = Ticket(username=USERNAME, user_id=USER_ID) expected = '門票類別未填喔\n日期未填喔\n價錢未填喔\n數量未填喔' result = ticket.validate() assert result['status'] is False assert result['info'] == expected validator = ItemValidator(ticket.to_dict()) result = validator.check_ticket() assert result['status'] is False assert result['info'] == expected
def test_validator_success(self): ticket = Ticket(username=USERNAME, user_id=USER_ID) ticket.category = 1 ticket.date = 508 ticket.price_id = 1 ticket.quantity = 2 ticket.status = 1 result = ticket.validate() assert result['status'] validator = ItemValidator(ticket.to_dict()) result = validator.check_ticket() assert result['status']
def test_validator_missing_quantity(self): ticket = Ticket(username=USERNAME, user_id=USER_ID) ticket.category = 1 ticket.date = 508 ticket.price_id = 1 ticket.status = 1 result = ticket.validate() assert result['status'] is False assert result['info'] == '數量未填喔' validator = ItemValidator(ticket.to_dict()) result = validator.check_ticket() assert result['status'] is False assert result['info'] == '數量未填喔'
def save_drafting_ticket(self, user_id: int, ticket: Ticket) -> bool: logger.info(ticket.to_str()) event_logger.info(ticket.to_str()) return self.redis.save(user_id=user_id, action='ticket', content=ticket.to_dict())
def update_ticket(self, ticket: Ticket) -> bool: return bool(self.raw_update(where=and_(self.table.c.id == ticket.id), row=ticket.to_dict()).rowcount)
def create_ticket(self, ticket: Ticket): ticket = ticket.to_dict() del ticket['id'] return bool(self.raw_insert(ticket).rowcount)