Esempio n. 1
0
 def faz_jogada(ctx, id, username, password, jogada, cidade, cor):
     try:
         session = Session.objects.get(session_hash=id)
         session_state = SessionState.objects.get(session=session)
         city = City.objects.get(name=cidade)
         city_state = CityState.objects.get(session=session_state,
                                            city=city)
         res = ''
         user = authenticate(username=username, password=password)
         if user is not None:
             player_state = PlayerState.objects.get(session=session_state,
                                                    user=user.id)
             http_request = HttpRequest()
             http_request.user = user
             http_request.method = "POST"
             if jogada == 'move':
                 http_request.POST = QueryDict.fromkeys(['city'],
                                                        value=city.id)
                 request = Request(http_request)
                 request.user = user
                 response = update_player_state(request, player_state.id,
                                                session.session_hash)
                 res = "Aceite" if response.status_code == 200 else "Não aceite"
             elif jogada == 'treat':
                 key = []
                 value = 0
                 if cor == "Black":
                     key.append('black_cubes')
                     value = city_state.black_cubes - 1
                 elif cor == "Yellow":
                     key.append("yellow_cubes")
                     value = city_state.yellow_cubes - 1
                 elif cor == "Red":
                     key.append("red_cubes")
                     value = city_state.red_cubes - 1
                 else:
                     key.append("blue_cubes")
                     value = city_state.blue_cubes - 1
                 http_request.POST = QueryDict.fromkeys(key, value=value)
                 request = Request(http_request)
                 request.user = user
                 response = update_city_state(request, city_state.id,
                                              session.session_hash)
                 res = "Aceite" if response.status_code == 200 else "Não aceite"
             else:
                 http_request.POST = QueryDict.fromkeys(
                     ['research_station'], value=True)
                 request = Request(http_request)
                 request.user = user
                 response = update_city_state(request, city_state.id,
                                              session.session_hash)
                 res = "Aceite" if response.status_code == 200 else "Não aceite"
             return res
         else:
             raise InvalidCredentialsError('User')
     except ObjectDoesNotExist:
         raise ResourceNotFoundError('Session')
Esempio n. 2
0
def lti_launch(request):
    """Django view for the lti post request.

    Verifies the given LTI parameters based on our secret, if a user can be found based on the verified parameters
    a redirection link is send with corresponding JW access and refresh token to allow for a user login. If no user
    can be found on our end, but the LTI parameters were verified nonetheless, we are dealing with a new user and
    redirect with additional parameters that will allow for the creation of a new user.

    If the parameters are not validated a redirection is send with the parameter state set to BAD_AUTH.
    """
    secret = settings.LTI_SECRET
    key = settings.LTI_KEY

    try:
        lti.OAuthRequestValidater.check_signature(key, secret, request)
    except (oauth2.Error, ValueError):
        return redirect(
            lti.create_lti_query_link(
                QueryDict.fromkeys(['state'], LTI_STATES.BAD_AUTH.value)))

    params = request.POST.dict()

    user = lti.get_user_lti(params)
    user = handle_test_student(user, params)

    params['exp'] = datetime.datetime.utcnow() + datetime.timedelta(minutes=15)
    lti_params = encode_lti_params(params)

    try:
        if user is None:
            query = QueryDict(mutable=True)
            query['state'] = LTI_STATES.NO_USER.value
            query['lti_params'] = lti_params
            query['username'] = params['custom_username']
            query['full_name'] = params.get('custom_user_full_name', None)
        else:
            refresh = TokenObtainPairSerializer.get_token(user)
            query = QueryDict.fromkeys(['lti_params'],
                                       lti_params,
                                       mutable=True)
            query['jwt_access'] = str(refresh.access_token)
            query['jwt_refresh'] = str(refresh)
            query['state'] = LTI_STATES.LOGGED_IN.value
    except KeyError as err:
        query = QueryDict.fromkeys(['state'],
                                   LTI_STATES.KEY_ERR.value,
                                   mutable=True)
        query[
            'description'] = 'The request is missing the following parameter: {0}.'.format(
                err)

    return redirect(lti.create_lti_query_link(query))
Esempio n. 3
0
 def test_fromkeys_with_nondefault_encoding(self):
     key_utf16 = b"\xff\xfe\x8e\x02\xdd\x01\x9e\x02"
     value_utf16 = b"\xff\xfe\xdd\x01n\x00l\x00P\x02\x8c\x02"
     q = QueryDict.fromkeys([key_utf16], value=value_utf16, encoding="utf-16")
     expected = QueryDict("", mutable=True)
     expected["ʎǝʞ"] = "ǝnlɐʌ"
     self.assertEqual(q, expected)
Esempio n. 4
0
 def test_fromkeys_with_nondefault_encoding(self):
     key_utf16 = b'\xff\xfe\x8e\x02\xdd\x01\x9e\x02'
     value_utf16 = b'\xff\xfe\xdd\x01n\x00l\x00P\x02\x8c\x02'
     q = QueryDict.fromkeys([key_utf16], value=value_utf16, encoding='utf-16')
     expected = QueryDict('', mutable=True)
     expected['ʎǝʞ'] = 'ǝnlɐʌ'
     self.assertEqual(q, expected)
Esempio n. 5
0
 def test_fromkeys_with_nondefault_encoding(self):
     key_utf16 = b'\xff\xfe\x8e\x02\xdd\x01\x9e\x02'
     value_utf16 = b'\xff\xfe\xdd\x01n\x00l\x00P\x02\x8c\x02'
     q = QueryDict.fromkeys([key_utf16], value=value_utf16, encoding='utf-16')
     expected = QueryDict('', mutable=True)
     expected['ʎǝʞ'] = 'ǝnlɐʌ'
     self.assertEqual(q, expected)
Esempio n. 6
0
 def test_fromkeys_with_nondefault_encoding(self):
     key_utf16 = b"\xff\xfe\x8e\x02\xdd\x01\x9e\x02"
     value_utf16 = b"\xff\xfe\xdd\x01n\x00l\x00P\x02\x8c\x02"
     q = QueryDict.fromkeys([key_utf16],
                            value=value_utf16,
                            encoding="utf-16")
     expected = QueryDict("", mutable=True)
     expected["ʎǝʞ"] = "ǝnlɐʌ"
     self.assertEqual(q, expected)
Esempio n. 7
0
def divide_api(request, *args, **kwargs):
    answer = {
        "A": 1234,
        "B": 4567,
    }
    if isNum(answer['A']) == True and isNum(answer['B']) == True:
        answer = QueryDict.fromkeys(['answer'],
                                    value=answer['A'] / answer['B'])
    else:
        answer = JsonResponse(ERROR)
        answer.status_code = 403
        return answer
    answer_as_json = json.dumps(answer)
    response = HttpResponse(answer_as_json)
    response['Content-Type'] = 'application/json'
    return response
Esempio n. 8
0
 def test_fromkeys_is_immutable_by_default(self):
     # Match behavior of __init__() which is also immutable by default.
     q = QueryDict.fromkeys(['key1', 'key2', 'key3'])
     with self.assertRaisesMessage(AttributeError,
                                   'This QueryDict instance is immutable'):
         q['key4'] = 'nope'
Esempio n. 9
0
 def test_querydict_fromkeys(self):
     self.assertEqual(QueryDict.fromkeys(["key1", "key2", "key3"]),
                      QueryDict("key1&key2&key3"))
Esempio n. 10
0
 def test_fromkeys_with_nonempty_value(self):
     self.assertEqual(
         QueryDict.fromkeys(['key1', 'key2', 'key3'], value='val'),
         QueryDict('key1=val&key2=val&key3=val'))
Esempio n. 11
0
 def test_fromkeys_is_immutable_by_default(self):
     # Match behavior of __init__() which is also immutable by default.
     q = QueryDict.fromkeys(['key1', 'key2', 'key3'])
     with self.assertRaisesMessage(AttributeError, 'This QueryDict instance is immutable'):
         q['key4'] = 'nope'
Esempio n. 12
0
 def test_duplicates_in_fromkeys_iterable(self):
     self.assertEqual(QueryDict.fromkeys('xyzzy'), QueryDict('x&y&z&z&y'))
Esempio n. 13
0
 def test_fromkeys_empty_iterable(self):
     self.assertEqual(QueryDict.fromkeys([]), QueryDict(''))
Esempio n. 14
0
 def test_querydict_fromkeys(self):
     self.assertEqual(QueryDict.fromkeys(['key1', 'key2', 'key3']), QueryDict('key1&key2&key3'))
Esempio n. 15
0
 def test_querydict_fromkeys(self):
     self.assertEqual(QueryDict.fromkeys(["key1", "key2", "key3"]), QueryDict("key1&key2&key3"))
Esempio n. 16
0
 def test_fromkeys_with_nonempty_value(self):
     self.assertEqual(
         QueryDict.fromkeys(["key1", "key2", "key3"], value="val"), QueryDict("key1=val&key2=val&key3=val")
     )
Esempio n. 17
0
 def test_duplicates_in_fromkeys_iterable(self):
     q = QueryDict.fromkeys('xyzzy')
     expected = QueryDict('x&y&z&z&y')
     self.assertEqual(q, expected)
Esempio n. 18
0
from mpemail.models.email import Email
from pandas import ExcelWriter

from django.http import HttpRequest, QueryDict

request = HttpRequest()
from mpemail.rest.viewsets.email import EmailViewSet
request.method = 'post'
data = {
    'mids': ['0', '1', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1A', '1B', '1C', '1D', '1E', '1F', '1G']
}

keys = ['mids']
values = ['0', '1', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1A', '1B', '1C', '1D', '1E', '1F', '1G']

request.POST = QueryDict.fromkeys(keys, values)

import pdb; pdb.set_trace()
EmailViewSet.as_view({'post': 'order'})(request)

# columns_delivery = [
#     '보내는분 성명',
#     '보내는분 전화',
#     '보내는분 핸드폰',
#     '보내는분 우편번호',
#     '보내는분 주소',
#     '고객성명',
#     '우편번호',
#     '주소',
#     '전화번호',
#     '핸드폰번호',
Esempio n. 19
0
 def test_fromkeys_mutable_override(self):
     q = QueryDict.fromkeys(["key1", "key2", "key3"], mutable=True)
     q["key4"] = "yep"
     self.assertEqual(q, QueryDict("key1&key2&key3&key4=yep"))
Esempio n. 20
0
 def test_fromkeys_is_immutable_by_default(self):
     # Match behavior of __init__() which is also immutable by default.
     q = QueryDict.fromkeys(["key1", "key2", "key3"])
     with self.assertRaisesMessage(AttributeError,
                                   "This QueryDict instance is immutable"):
         q["key4"] = "nope"
Esempio n. 21
0
 def test_fromkeys_with_nonempty_value(self):
     self.assertEqual(
         QueryDict.fromkeys(["key1", "key2", "key3"], value="val"),
         QueryDict("key1=val&key2=val&key3=val"),
     )
Esempio n. 22
0
 def test_fromkeys_mutable_override(self):
     q = QueryDict.fromkeys(['key1', 'key2', 'key3'], mutable=True)
     q['key4'] = 'yep'
     self.assertEqual(q, QueryDict('key1&key2&key3&key4=yep'))
Esempio n. 23
0
 def test_fromkeys_empty_iterable(self):
     self.assertEqual(QueryDict.fromkeys([]), QueryDict(''))
Esempio n. 24
0
 def test_duplicates_in_fromkeys_iterable(self):
     self.assertEqual(QueryDict.fromkeys('xyzzy'), QueryDict('x&y&z&z&y'))
Esempio n. 25
0
 def test_querydict_fromkeys(self):
     actual = QueryDict.fromkeys(['key1', 'key2', 'key3'])
     expected = QueryDict('key1&key2&key3')
     self.assertEqual(actual, expected)
Esempio n. 26
0
 def test_fromkeys_noniterable(self):
     with self.assertRaises(TypeError):
         QueryDict.fromkeys(0)
Esempio n. 27
0
 def test_fromkeys_is_immutable_by_default(self):
     # To match behaviour of __init__, which is also immutable by default
     q = QueryDict.fromkeys(['key1', 'key2', 'key3'])
     expected_msg = 'This QueryDict instance is immutable'
     with self.assertRaisesRegex(AttributeError, expected_msg):
         q['key4'] = 'nope'
Esempio n. 28
0
 def test_fromkeys_with_nonempty_value(self):
     self.assertEqual(
         QueryDict.fromkeys(['key1', 'key2', 'key3'], value='val'),
         QueryDict('key1=val&key2=val&key3=val')
     )
Esempio n. 29
0
 def test_fromkeys_with_nonempty_value(self):
     actual = QueryDict.fromkeys(['key1', 'key2', 'key3'], value='val')
     expected = QueryDict('key1=val&key2=val&key3=val')
     self.assertEqual(actual, expected)
Esempio n. 30
0
 def test_fromkeys_mutable_override(self):
     q = QueryDict.fromkeys(['key1', 'key2', 'key3'], mutable=True)
     q['key4'] = 'yep'
     self.assertEqual(q, QueryDict('key1&key2&key3&key4=yep'))
Esempio n. 31
0
 def test_querydict_fromkeys(self):
     self.assertEqual(QueryDict.fromkeys(['key1', 'key2', 'key3']),
                      QueryDict('key1&key2&key3'))
Esempio n. 32
0
 def test_fromkeys_is_immutable_by_default(self):
     # Match behavior of __init__() which is also immutable by default.
     q = QueryDict.fromkeys(["key1", "key2", "key3"])
     with self.assertRaisesMessage(AttributeError, "This QueryDict instance is immutable"):
         q["key4"] = "nope"
Esempio n. 33
0
 def test_fromkeys_with_nondefault_encoding(self):
     value = b'\xff\xfe\xdd\x01n\x00l\x00P\x02\x8c\x02'
     key = b'\xff\xfe\x8e\x02\xdd\x01\x9e\x02'
     q = QueryDict.fromkeys([key], value=value, encoding='utf-16')
     expected = QueryDict('ʎǝʞ=ǝnlɐʌ')
     self.assertEqual(q, expected)
Esempio n. 34
0
 def test_fromkeys_noniterable(self):
     with self.assertRaises(TypeError):
         QueryDict.fromkeys(0)
Esempio n. 35
0
 def test_fromkeys_mutable_override(self):
     q = QueryDict.fromkeys(["key1", "key2", "key3"], mutable=True)
     q["key4"] = "yep"
     self.assertEqual(q, QueryDict("key1&key2&key3&key4=yep"))