Example #1
0
 def handle(self, *args, **options):
     CustomWeChatView.update_menu()
     act_btns = CustomWeChatView.get_book_btn().get('sub_button', list())
     self.logger.info('Updated %d activities', len(act_btns))
     self.logger.info('=' * 32)
     for idx, act in enumerate(act_btns):
         self.logger.info('%d. %s (%s)', idx, act.get('name', ''),
                          act.get('key', ''))
Example #2
0
 def handle(self, *args, **options):
     CustomWeChatView.update_menu(Activity.objects.filter(
         status=Activity.STATUS_PUBLISHED, book_end__gt=timezone.now()
     ).order_by('book_end'))
     act_btns = CustomWeChatView.get_book_btn().get('sub_button', list())
     self.logger.info('Updated %d activities', len(act_btns))
     self.logger.info('=' * 32)
     for idx, act in enumerate(act_btns):
         self.logger.info('%d. %s (%s)', idx, act.get('name', ''), act.get('key', ''))
Example #3
0
    def test(self):
        c = Client()

        c.post('/api/a/login',
               {
                   'username': '******',
                   'password': '******'
               })

        addMenuUrl = '/api/a/activity/menu'
        id = Activity.objects.get(name='ycdfwzy').id
        c.post(addMenuUrl, {'idarr': id})

        button = CustomWeChatView.get_book_btn()['sub_button']
        self.assertEqual(len(button), 1)    # check add menu

        self.postClickMsg['EventKey'] = CustomWeChatView.event_keys['book_header']+str(id)
        response = c.post(self.Url,
                          trans_dict_to_xml(self.postClickMsg),
                          content_type='text/xml')
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'text.xml')
        self.assertEqual(Activity.objects.get(name = 'ycdfwzy').remain_tickets, 49)
        tkt = Ticket.objects.get(student_id = self.stuid)
        self.assertNotEqual(tkt, None)
        self.assertEqual(tkt.status, Ticket.STATUS_VALID)

        response = c.post(self.Url,
                          trans_dict_to_xml(self.postTextMsg),
                          content_type='text/xml')
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'text.xml')
        self.assertContains(response, '你已经抢到票了,请不要重复抢票!')

        #remain = 0
        response = c.post(self.Url,
                          trans_dict_to_xml(getDict(self.userid, '抢票 act_remain0')),
                          content_type = 'text/xml')
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'text.xml')
        self.assertContains(response, '抱歉,没票啦!')

        #deleted
        response = c.post(self.Url,
                          trans_dict_to_xml(getDict(self.userid, '抢票 act_deleted')),
                          content_type = 'text/xml')
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'text.xml')
        self.assertContains(response, '未找到该活动')

        #saved
        response = c.post(self.Url,
                          trans_dict_to_xml(getDict(self.userid, '抢票 act_saved')),
                          content_type='text/xml')
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'text.xml')
        self.assertContains(response, '未找到该活动!')

        #act not exsist
        response = c.post(self.Url,
                          trans_dict_to_xml(getDict(self.userid, '抢票 act_absent')),
                          content_type='text/xml')
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'text.xml')
        self.assertContains(response, '未找到该活动!')

        #overdue
        response = c.post(self.Url,
                          trans_dict_to_xml(getDict(self.userid, '抢票 act_overdue')),
                          content_type='text/xml')
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'text.xml')
        self.assertContains(response, '抢票已结束!')

        #haven't start
        response = c.post(self.Url,
                          trans_dict_to_xml(getDict(self.userid, '抢票 act_nstart')),
                          content_type='text/xml')
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'text.xml')
        self.assertContains(response, '抢票未开始!')