Exemplo n.º 1
0
 def test_validator_missing_quantity(self):
     ticket = Ticket(username=USERNAME, user_id=USER_ID).to_dict()
     ticket['category'] = 1
     ticket['date'] = 508
     ticket['price'] = 1
     ticket['status'] = 1
     validator = ItemValidator(ticket)
     result = validator.check_ticket()
     self.assertFalse(result.get('status'))
Exemplo n.º 2
0
 def test_validator_success(self):
     ticket = Ticket(username=USERNAME, user_id=USER_ID).to_dict()
     ticket['category'] = 1
     ticket['date'] = 508
     ticket['price'] = 1
     ticket['quantity'] = 2
     ticket['status'] = 1
     validator = ItemValidator(ticket)
     result = validator.check_ticket()
     print(result)
     self.assertTrue(result.get('status'))
Exemplo n.º 3
0
 def reset_cache(self, user_id, username):
     if self._task == 'search_ticket':
         content = Query(user_id=user_id, username=username).to_dict()
         self.set_cache(user_id, content)
         return content
     elif self._task == 'post_ticket':
         content = Ticket(user_id=user_id, username=username).to_dict()
         self.set_cache(user_id, content)
         return content
     elif self._task == 'update_ticket':
         ticket_id = self.get_cache(user_id=user_id,
                                    username=username).get('id')
         # ticket = request.send_search_ticket_by_ticket_id(ticket_id=ticket_id).get('info')
         self.set_cache(user_id=user_id, content=ticket)
         return ticket
     else:
         logger.warning('Reset cache not be implement. But should be work.')
Exemplo n.º 4
0
 def test_init_ticket(self):
     ticket = Ticket(user_id=USER_ID, username=USERNAME).to_dict()
     helper = helpers.Helper('test')
     result = helper.flatten(ticket)
     expect = dict(category='',
                   date='',
                   price='',
                   quantity='',
                   section='',
                   row='',
                   seat='',
                   status='待交易',
                   remarks='',
                   user_id=int(USER_ID),
                   username=str(USERNAME),
                   wish_date='',
                   wish_price='',
                   wish_quantity='')
     self.assertDictEqual(result, expect)
Exemplo n.º 5
0
 def test_validator_error_message(self):
     ticket = Ticket(username=USERNAME, user_id=USER_ID).to_dict()
     validator = ItemValidator(ticket)
     result = validator.check_ticket()
     expected = '門票類別未填喔\n門票狀態未填喔\n日期未填喔\n價錢未填喔\n數量未填喔'
     self.assertEqual(expected, result['info'])