예제 #1
0
 def test_can_get_token(self):
     request = self.factory.get("/viewer/react/")
     request.user = self.user
     token_one = get_token(request)
     self.assertTrue(type(token_one) == str)
     self.assertNotEqual(token_one, "")
     request.user = AnonymousUser()
     token_two = get_token(request)
     self.assertNotEqual(token_two, "")
     self.assertTrue(type(token_two) == str)
예제 #2
0
파일: views.py 프로젝트: liuyang1123/ST
    def create(self, request):
        decoded_token = decode_token(request.META)
        token = get_token(request.META)
        serializer = EventSerializer(data=request.data)

        if serializer.is_valid():
            client = CalendarDBClient()

            event_id = client.add_event(token, serializer.data)

            st = SchedulingTask(task_type='schedule',
                                status='pending',
                                event_id=event_id,
                                start_time=None,
                                tentative_time=None,
                                initiator_id=decoded_token['user_id'],
                                result='needs_action')
            re = st.save()[0]
            re_s = EventSerializer(re.to_dict())

            return Response(re_s.data, status=status.HTTP_201_CREATED)
        return Response(
            {
                'data': serializer.errors,
                'message': 'Event could not be created with the given data.'
            },
            status=status.HTTP_400_BAD_REQUEST)