Exemple #1
0
    def check(self, response):
        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_200, self.mock.status)
        result = json.loads(''.join(response))
        self.assertTrue(result)
        self.assertIsInstance(result, list)

        self.check_comment(result)
        return result
Exemple #2
0
    def test_get_block(self):
        response = self.send_request(
            path = self.path, method='GET', \
            data = json.dumps({'page': 1, 'token': self.token, 'num': 1}), \
        )

        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_200, self.mock.status)
        data = json.loads(''.join(response))
        self.assertIsInstance(data, list)
Exemple #3
0
    def test_get_no_comments(self):
        data = {'tid':100, 'page':1, 'num':1, 'expand':0}
        response = self.send_request(
            path = self.path, method = 'GET', \
            data = json.dumps(data), \
        )

        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_200, self.mock.status)
        self.assertFalse(json.loads(''.join(response)))
Exemple #4
0
    def test_get_sys_info(self):
        response = self.send_request(
            path = '/sys', method = 'GET', \
        )

        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_200, self.mock.status)

        data = json.loads(''.join(response))
        self.assertIsInstance(data, dict)
        self.assertEqual(data['store'], config.STORE)
Exemple #5
0
    def test_refresh_cache_and_get_new_block(self):
        site = get_site_by_token(self.token)
        ip = '192.168.1.10'
        block(site, ip)
        response = self.send_request(
            path = self.path, method='GET', \
            data = json.dumps({'page': 1, 'token': self.token, 'num': 1}), \
        )

        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_200, self.mock.status)
        data = json.loads(''.join(response))
        self.assertIsInstance(data, list)
        self.assertTrue(data[0]['ip'] == ip)
Exemple #6
0
    def test_get_block_from_cache(self):
        from handlers import site
        self.patch(site, 'get_blocks', wrap(site.get_blocks))

        response = self.send_request(
            path = self.path, method='GET', \
            data = json.dumps({'page': 1, 'token': self.token, 'num': 1}), \
        )

        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_200, self.mock.status)
        data = json.loads(''.join(response))
        self.assertIsInstance(data, list)
        self.assertEqual(data[0]['ctime'], 'True')
Exemple #7
0
    def test_create_site(self):
        response = self.send_request(
            path = '/site', data = json.dumps({'name': 'test'})
        )

        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_201, self.mock.status)
        data = json.loads(''.join(response))
        self.assertIsInstance(data, dict)
        token = data.get('token')
        self.assertTrue(token)
        self.assertIsInstance(token, (str, unicode))
        self.assertEqual(len(token), 32)

        self._test_bad_request('/site', 'PUT')
Exemple #8
0
    def test_get_up_counts(self):
        r = range(17, 19)
        for i in r:
            k = config.COMMENT_UP_PREFIX.format(sid = self.site.id, cid = i)
            rds.incr(k)

        response = self.send_request(
            path = self.path, method = 'GET', data = json.dumps({'cids': r})
        )

        self.assertEqual(falcon.HTTP_200, self.mock.status)
        self.assertTrue(is_iter(response))
        data = json.loads(''.join(response))
        self.assertIsInstance(data, dict)
        for i in r:
            self.assertTrue(data.get(str(i)))
            self.assertEqual(int(data[str(i)]), 1)
Exemple #9
0
    def test_create_block(self):
        site = get_site_by_token(self.token)
        after = site.blocks + 1
        response = self.send_request(
            path = self.path, method = 'PUT', \
            data = json.dumps({'ip': '192.168.1.1', 'token': self.token}), \
        )

        site = get_site_by_token(self.token)
        self.assertTrue(site.blocks, after)
        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_201, self.mock.status)
        data = json.loads(''.join(response))
        self.assertIsInstance(data, dict)
        id = data.get('id')
        self.assertTrue(id)
        self.assertIsInstance(id, int)
Exemple #10
0
    def test_create_comment(self):
        site = get_site_by_token(self.token)
        after = site.comments + 1
        data = {'tid':1, 'fid':1, 'uid':1, 'ip':'192.168.8.1', 'content':'Hello World'}
        response = self.send_request(
            path = self.path, method = 'PUT', \
            data = json.dumps(data), \
        )

        site = get_site_by_token(self.token)
        self.assertEqual(site.comments, after)
        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_201, self.mock.status)
        data = json.loads(''.join(response))
        self.assertIsInstance(data, dict)
        id = data.get('id')
        self.assertTrue(id)
        self.assertIsInstance(id, int)
Exemple #11
0
    def test_get_comment_no_expand(self):
        site = get_site_by_token(self.token)
        ncomment_1 = create(site, 10, 0, 1, '192.168.10.1', 'hello')

        data = {'tid':10, 'page':1, 'num':1, 'expand':0}
        response = self.send_request(
            path = self.path, method = 'GET', \
            data = json.dumps(data), \
        )

        self.assertTrue(is_iter(response))
        self.assertEqual(falcon.HTTP_200, self.mock.status)
        result = json.loads(''.join(response))
        self.assertTrue(result)

        data = result[0][0]
        self.assertEqual(data['ip'], ncomment_1.ip)
        self.assertEqual(data['content'], ncomment_1.content)
        self.assertEqual(data['id'], ncomment_1.id)