コード例 #1
0
def test_safe_del_key():
    ex_dict = {'key_{}'.format(x): 'val_{}'.format(x) for x in range(10)}
    clean_dict_1 = safe_del_key(ex_dict, 'key_1')
    assert 'key_1' not in clean_dict_1
    assert len(clean_dict_1) == 9
    clean_dict_2 = safe_del_key(ex_dict, ['key_2', 'key_3', 'key_4'])
    assert 'key_2' not in clean_dict_2
    assert 'key_3' not in clean_dict_2
    assert 'key_4' not in clean_dict_2
    clean_dict_3 = safe_del_key(clean_dict_2, ['key_2', 'key_3', 'key_4'])
    assert clean_dict_3 == clean_dict_2
    assert len(clean_dict_3) == 6
コード例 #2
0
 async def post(self, request, current_user):
     try:
         req = request.json
         if req['qtype'] == 'abcd':
             req['answers'] = jdumps(
                 [req['ans_a'], req['ans_b'], req['ans_c'], req['ans_d']])
             req = safe_del_key(req, ['ans_a', 'ans_b', 'ans_c', 'ans_d'])
         question = Question(**req)
         await question.create()
         return json({'success': True})
     except:
         logging.exception('err question.post')
         return json({}, status=500)
コード例 #3
0
ファイル: models.py プロジェクト: naimadM/aioquiz
 async def get_my_user_data(self):
     data = await self.to_dict()
     data = safe_del_key(data, self._banned_user_keys)
     return data
コード例 #4
0
ファイル: models.py プロジェクト: naimadM/aioquiz
 async def get_public_data(self):
     data = await self.to_dict()
     data = safe_del_key(data, self._public_keys)
     return data