예제 #1
0
파일: test_block.py 프로젝트: CMGS/ymir
    def test_check_block(self):
        site = get_site_by_token(self.token)
        ip = '192.168.1.11'
        block(site, ip)

        self.assertTrue(check_block(site.id, ip))
        rds.delete(config.BLOCK_PREFIX.format(sid = site.id, ip = ip))
        self.assertTrue(check_block(site.id, ip))
        self.assertFalse(check_block(site.id, '192.168.1.12'))
예제 #2
0
파일: test_comment.py 프로젝트: CMGS/ymir
    def test_create_comment_403(self):
        site = get_site_by_token(self.token)
        ip = '192.168.9.1'
        block(site, ip)
        data = {'tid':1, 'fid':1, 'uid':1, 'ip':ip, 'content':'Hello World'}
        response = self.send_request(
            path = self.path, method = 'PUT', \
            data = json.dumps(data), \
        )

        self.assertIsInstance(response, list)
        self.assertEqual(falcon.HTTP_403, self.mock.status)
예제 #3
0
파일: test_block.py 프로젝트: CMGS/ymir
    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)
예제 #4
0
파일: test_block.py 프로젝트: CMGS/ymir
    def test_delete_block_500(self):
        site = get_site_by_token(self.token)
        nblock = block(site, '192.168.1.1')
        from handlers import site
        self.patch(site, 'delete_block', fake_func)

        self.send_request(
            path = self.path, method = 'DELETE', \
            data = json.dumps({'id': nblock.id, 'token': self.token}), \
        )
        self.assertEqual(falcon.HTTP_500, self.mock.status)
예제 #5
0
파일: site.py 프로젝트: CMGS/ymir
    def on_put(self, req, resp):
        token, ip, _ = self.parse_params(req)
        site = self.get_site(token)

        try:
            bip = block(site, ip)
        except Exception:
            logger.exception('create')
            raise falcon.HTTPInternalServerError(config.HTTP_500, 'create block failed')

        resp.status = falcon.HTTP_201
        resp.stream = ijson.dump({'id': bip.id})
예제 #6
0
파일: test_block.py 프로젝트: CMGS/ymir
    def test_delete_block(self):
        site = get_site_by_token(self.token)
        after = site.blocks
        nblock = block(site, '192.168.1.1')

        response = self.send_request(
            path = self.path, method = 'DELETE', \
            data = json.dumps({'id': nblock.id, 'token': self.token}), \
        )

        site = get_site_by_token(self.token)
        self.assertEqual(after, site.blocks)
        self.assertEqual(falcon.HTTP_200, self.mock.status)
        self.assertFalse(response)