Exemplo n.º 1
0
class RemindViewTestCase(TestCase):
    def setUp(self):
        self.r = Remind(time=timezone.now(), owner_id='miao', event='吃饭', desc='吃饭饭')
        self.r.save()

    def test_anonymous_delete(self):
        resp = self.client.delete(reverse('remind-detail', args=(self.r.pk.hex,)), HTTP_X_REFERER='abc.com/#def')
        # self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.status_code, 401)
        self.assertIn('//open.weixin.qq.com/connect/oauth2/authorize', resp.get('WWW-Authenticate', ''))
        self.assertIn('state=abc.com%2F%23def', resp.get('WWW-Authenticate', ''))

    def test_unauthorized_delete(self):
        u = WechatUser(openid='123', nickname='456')
        u.save()
        self.client.force_login(u)
        resp = self.client.delete(reverse('remind-detail', args=(self.r.pk.hex,)))
        self.assertEqual(resp.status_code, 403)

    def test_participant_delete(self):
        WechatUser(openid='miao', nickname='miaomiaomiao').save()
        self.r.add_participant('123')
        u = WechatUser(openid='123', nickname='456')
        u.save()
        self.client.force_login(u)
        resp = self.client.delete(reverse('remind-detail', args=(self.r.pk.hex,)))
        self.assertEqual(resp.status_code, 204)
        # self.assertEqual(resp.url, reverse('remind_list'))

    def test_delete(self):
        u = WechatUser(openid='miao', nickname='456')
        u.save()
        self.client.force_login(u)
        resp = self.client.delete(reverse('remind-detail', args=(self.r.pk.hex,)))
        self.assertEqual(resp.status_code, 204)
Exemplo n.º 2
0
    def test_add_add_participant(self):
        r = Remind(time=timezone.now(), owner_id='miao', event='吃饭', desc='吃饭饭')
        r.save()
        r.add_participant('abc')
        r.add_participant('abc')

        self.assertEqual(r.participants, ['abc'])
Exemplo n.º 3
0
    def test_add_add_participant(self):
        r = Remind(time=timezone.now(),
                   owner_id='miao',
                   event='吃饭',
                   desc='吃饭饭')
        r.save()
        r.add_participant('abc')
        r.add_participant('abc')

        self.assertEqual(r.participants, ['abc'])
Exemplo n.º 4
0
    def test_add_add_participant(self):
        WechatUser(openid='abc', nickname='abcabc', subscribe=True).save()
        r = Remind(time=timezone.now(),
                   owner_id='miao',
                   event='吃饭',
                   desc='吃饭饭')
        r.save()
        r.add_participant('abc')
        r.add_participant('abc')

        self.assertEqual(r.participants, ['abc'])