コード例 #1
0
    def form_valid(self, form, request):
        text = form.cleaned_data.get('text')

        # Get elements of Form and save the response.
        response = Response(files=request.FILES.get('files', None))

        if response.files:
            response.file_name = response.files.name

        response.user_from = self.object.user_to
        response.user_to = self.object.user_from
        response.text = text
        response.dat = date.today()

        if (response.user_from is request.user):
            response.as_read = True
        else:
            # Nothing to do.
            pass

        response.save()

        self.object.messages.add(response)

        return super(MessageDetailView, self).form_valid(form)
コード例 #2
0
    def setUp(self):

        self.user = User.objects.create(name='User Test',
                                        email='*****@*****.**',
                                        sex='M',
                                        phone='1111111111',
                                        is_active=True)

        self.user2 = User.objects.create(name='User2 Test',
                                         email='*****@*****.**',
                                         sex='M',
                                         phone='1111111111',
                                         is_active=True)

        self.view = MessageDetailView()
        self.view_class = MessageDetailView
        self.factory = RequestFactory()
        self.client = Client()
        # Create Message.

        self.response = Response()
        self.response.user_from = self.user
        self.response.user_to = self.user2
        self.response.save()

        # Create Message.
        self.message = Message()
        self.message.text = "meu texto"
        self.message.subject = "Assunto"
        self.message.user_from = self.user
        self.message.user_to = self.user
        self.message.pk = 1
        self.message.messages.add(self.response)
        self.message.save()
コード例 #3
0
    def setUp(self):

        # Create Patient.
        self.patient = Patient.objects.create(name='Paciente',
                                              phone='1111111111',
                                              email='*****@*****.**')
        self.patient.save()

        self.professional = HealthProfessional.objects.create(name='Heatlh',
                                                              crm='12345',
                                                              email='*****@*****.**',
                                                              sex='M',
                                                              is_active=True)
        self.professional.save()

        self.view = ListPatientFiles()
        self.factory = RequestFactory()

        # Create Message.
        self.response = Response()
        self.response.text = "meu texto"
        self.response.subject = "Assunto"
        self.response.user_from = self.patient
        self.response.user_to = self.professional
        self.response.files = "files"
        self.response.save()
コード例 #4
0
    def setUp(self):

        self.health_professional = HealthProfessional.objects.create(name='User Test',
                                                                     email='*****@*****.**',
                                                                     sex='M',
                                                                     phone='1111111111',
                                                                     is_active=True)
        self.patient = Patient.objects.create(name='User Test',
                                              email='*****@*****.**',
                                              sex='M',
                                              phone='1111111111',
                                              is_active=True)

        self.view = SentMessageDetailView()
        self.view_class = SentMessageDetailView
        self.factory = RequestFactory()
        self.client = Client()

        self.response = Response()
        self.response.user_from = self.health_professional
        self.response.user_to = self.patient
        self.response.save()

        # Create Message.
        self.message = Message()
        self.message.text = "meu texto"
        self.message.subject = "Assunto"
        self.message.user_from = self.health_professional
        self.message.user_to = self.patient
        self.message.pk = 1
        self.message.messages.add(self.response)
        self.message.save()
コード例 #5
0
class TestPatient(TestCase):

    def setUp(self):

        # Create Patient.
        self.patient = Patient.objects.create(name='Paciente',
                                              phone='1111111111',
                                              email='*****@*****.**')
        self.patient.save()

        self.professional = HealthProfessional.objects.create(name='Heatlh',
                                                              crm='12345',
                                                              email='*****@*****.**',
                                                              sex='M',
                                                              is_active=True)
        self.professional.save()

        self.view = ListPatientFiles()
        self.factory = RequestFactory()

        # Create Message.
        self.response = Response()
        self.response.text = "meu texto"
        self.response.subject = "Assunto"
        self.response.user_from = self.patient
        self.response.user_to = self.professional
        self.response.files = "files"
        self.response.save()

    def test_chat_query_true(self):
        request = self.factory.get('/')
        request.user = self.patient

        self.view.request = request

        query = self.view.get_queryset()

        self.assertTrue(query)

    def test_chat_query_false(self):
        request = self.factory.get('/')
        request.user = self.professional

        self.view.request = request

        query = self.view.get_queryset()
        print(query)

        self.assertFalse(query)

    def test_list_prescription(self):
        request = self.factory.get('/')
        request.user = self.patient

        response = ListPatientFiles.as_view()(request)
        self.assertEqual(response.status_code, 200)
コード例 #6
0
 def test_add_photo(self):
     newResponse = Response()
     newResponse.files = self.get_image_file()
     newResponse.file_name = newResponse.files.name
     newResponse.user_from = self.user
     newResponse.user_to = self.user
     newResponse.text = 'asdad'
     newResponse.save()
     self.assertEqual(Response.objects.count(), 1)
コード例 #7
0
class TestCount(TestCase):
    def setUp(self):

        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******')
        self.factory = RequestFactory()

        self.response = Response()
        self.response.as_read = False
        self.response.user_to = self.user
        self.response.user_from = self.user
        self.response.text = "a"
        self.response.id = 1
        self.response.save()

        # Create Message.
        self.message = Message()
        self.message.id = 1
        self.message.text = "meu texto"
        self.message.subject = "Assunto"
        self.message.user_from = self.user
        self.message.user_to = self.user
        self.message.messages.add(self.response)
        self.message.save()

    def test_get(self):

        request = self.factory.post('/chat/count_message/ajax',
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        request.user = self.user
        response = CountMessagesView.as_view()(request)

        self.assertEquals(response.status_code, 200)

    def test_get_invalid(self):
        request = self.factory.post('/chat/count_message/ajax')

        request.user = self.user
        response = CountMessagesView.as_view()(request)

        self.assertNotEquals(response, 200)
コード例 #8
0
    def form_valid(self, form, request):
        text = form.cleaned_data.get('text')

        response = Response(files=request.FILES.get('files', None))

        if response.files:
            response.file_name = response.files.name

        response.user_from = self.object.user_from
        response.user_to = self.object.user_to
        response.text = text
        response.dat = date.today()
        response.save()

        self.object.messages.add(response)

        return super(SentMessageDetailView, self).form_valid(form)
コード例 #9
0
    def setUp(self):

        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******')
        self.factory = RequestFactory()

        self.response = Response()
        self.response.as_read = False
        self.response.user_to = self.user
        self.response.user_from = self.user
        self.response.text = "a"
        self.response.id = 1
        self.response.save()

        # Create Message.
        self.message = Message()
        self.message.id = 1
        self.message.text = "meu texto"
        self.message.subject = "Assunto"
        self.message.user_from = self.user
        self.message.user_to = self.user
        self.message.messages.add(self.response)
        self.message.save()
コード例 #10
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST, request.FILES)
        pk = self.request.user.pk
        form.get_pk(pk)

        # Validanting form.
        if form.is_valid():

            text = form.cleaned_data.get('text')
            subject = form.cleaned_data.get('subject')
            user_to_email = form.cleaned_data.get('user_to')
            user_from = request.user
            user_to = User.objects.get(email=user_to_email)

            # Create a Message
            message = Message()
            message.subject = subject
            message.user_to = user_to
            message.user_from = user_from
            message.date = date.today()

            response = Response(files=request.FILES.get('files', None))

            if response.files:
                response.file_name = response.files.name

            response.user_from = user_from
            response.user_to = user_to
            response.text = text
            response.dat = date.today()
            response.save()
            message.save()

            message.messages.add(response)

            return redirect(
                '/dashboard_health_professional/health_professional')

        return render(request, self.template_name, {'form': form})
コード例 #11
0
class TestViewMessage(TestCase):
    def setUp(self):

        self.user = User.objects.create(name='User Test',
                                        email='*****@*****.**',
                                        sex='M',
                                        phone='1111111111',
                                        is_active=True)

        self.user2 = User.objects.create(name='User2 Test',
                                         email='*****@*****.**',
                                         sex='M',
                                         phone='1111111111',
                                         is_active=True)

        self.view = MessageDetailView()
        self.view_class = MessageDetailView
        self.factory = RequestFactory()
        self.client = Client()
        # Create Message.

        self.response = Response()
        self.response.user_from = self.user
        self.response.user_to = self.user2
        self.response.save()

        # Create Message.
        self.message = Message()
        self.message.text = "meu texto"
        self.message.subject = "Assunto"
        self.message.user_from = self.user
        self.message.user_to = self.user
        self.message.pk = 1
        self.message.messages.add(self.response)
        self.message.save()

    def test_chat_queryset_true(self):
        request = self.view_class.as_view()
        request.user = self.user

        self.view.request = request
        query = self.view.get_queryset()
        self.assertTrue(query.exists())

    def test_chat_get_context_true(self):
        request = self.factory.get('/')
        request.user = self.user
        self.view.request = request
        self.view.object = self.message
        self.assertEqual(type(self.view.get_context_data()), type(dict()))

    def test_chat_post_true(self):
        request = self.factory.post(
            '/', {
                'text': 'isso e um texto',
                'user_to': '*****@*****.**',
                'user_from': '*****@*****.**'
            })
        request.user = self.user
        self.view.request = request
        self.view.object = self.message

        response = self.view_class.as_view()(request, pk=1)
        self.assertEqual(response.status_code, 302)

    def test_chat_get(self):
        request = self.factory.get('/')

        request.user = self.user
        self.view.request = request
        self.view.object = self.message

        response = MessageDetailView.as_view()(request, pk=1)
        self.assertEqual(response.status_code, 200)

    def test_chat_post_false(self):
        request = self.factory.post('/', {
            'user_to': '*****@*****.**',
            'user_from': '*****@*****.**'
        })
        request.user = self.user
        self.view.request = request
        self.view.object = self.message

        response = self.view_class.as_view()(request, pk=1)
        self.assertEqual(response.status_code, 200)