예제 #1
0
    def test_resource_request_email(self):
        """
        Assert general expected behavior of resource_request_email
        """
        user = UserFactory(
            username="******",
            first_name="First",
            last_name="Last",
            email="*****@*****.**"
        )

        # Mock out a request
        request = mock.Mock()
        request.user = user
        request.POST = {}
        request.session = None

        with mock.patch('core.tasks.EmailMessage') as MockMessage, \
                override_settings(ATMO_SUPPORT=('Support', '*****@*****.**')):
            resource_request_email(
                request, user.username, "All the resources", "Did I stutter?"
            )
            kwargs = MockMessage.call_args[1]

            # Assert that Django's EmailMessage is called with the right
            # paramaters
            # Note: We are not testing the body of the email here
            MockMessage.assert_called_with(
                cc=None,
                to=['Support <*****@*****.**>'],
                subject='Atmosphere Resource Request - user0',
                from_email='First Last <*****@*****.**>',
                body=kwargs['body']
            )
 def submit_action(self, instance):
     """
     Submits a resource request email
     """
     requested_resource = instance.request
     reason_for_request = instance.description
     username = self.request.user.username
     email.resource_request_email(self.request, username,
                                  requested_resource,
                                  reason_for_request)
예제 #3
0
 def submit_action(self, instance, options={}):
     """
     Submits a resource request email
     """
     requested_resource = instance.request
     reason_for_request = instance.description
     username = self.request.user.username
     email.resource_request_email(self.request, username,
                                  requested_resource, reason_for_request,
                                  options)
예제 #4
0
 def perform_create(self, serializer):
     """
     Create a resource request
     """
     status, _ = StatusType.objects.get_or_create(name='pending')
     instance = serializer.save(created_by=self.request.user, status=status)
     options = {}
     if serializer.initial_data.get("admin_url"):
         options = {
             "admin_url":
             serializer.initial_data.get("admin_url") + str(instance.id)
         }
     email.resource_request_email(self.request, self.request.user.username,
                                  instance.request, instance.description,
                                  options)
예제 #5
0
 def _email(self, user, data):
     email_response = resource_request_email(
         self.request, user.username, data["quota"], data["reason"])
     if email_response.get('email_sent', False):
         return Response(email_response, status=status.HTTP_200_OK)
     else:
         return Response(email_response, status=status.HTTP_400_BAD_REQUEST)
예제 #6
0
    def _email(self, request, username, new_resource, reason):
        """
        Processes resource request increases. Sends email to [email protected]

        Returns a response.
        """
        return resource_request_email(request, username, new_resource, reason)
예제 #7
0
    def _email(self, request, username, new_resource, reason):
        """
        Processes resource request increases. Sends email to the admins

        Returns a response.
        """
        return resource_request_email(request, username, new_resource, reason)
예제 #8
0
파일: email.py 프로젝트: jmlowe/atmosphere
 def _email(self, user, data):
     email_response = resource_request_email(self.request, user.username,
                                             data["quota"], data["reason"])
     if email_response.get('email_sent', False):
         return Response(email_response, status=status.HTTP_200_OK)
     else:
         return Response(email_response, status=status.HTTP_400_BAD_REQUEST)
 def perform_create(self, serializer):
     """
     Create a resource request
     """
     status, _ = StatusType.objects.get_or_create(name='pending')
     instance = serializer.save(created_by=self.request.user, status=status)
     options = {}
     if serializer.initial_data.get("admin_url"):
         options = {
             "admin_url":
                 serializer.initial_data.get("admin_url") + str(instance.id)
         }
     email.resource_request_email(
         self.request, self.request.user.username, instance.request,
         instance.description, options
     )
예제 #10
0
    def _email(self, request, username, new_resource, reason):
        """
        Processes resource request increases. Sends email to the admins

        Returns a response.
        """
        return resource_request_email(request, username, new_resource, reason)
예제 #11
0
    def _email(self, request, username, new_resource, reason):
        """
        Processes resource request increases. Sends email to [email protected]

        Returns a response.
        """
        return resource_request_email(request, username, new_resource, reason)
예제 #12
0
파일: email.py 프로젝트: hwijung/atmosphere
 def _email(self, user, data):
     quota = data.pop('quota')
     reason = data.pop('reason')
     email_response = resource_request_email(
         self.request, user.username, quota, reason)
     if not email_response.get('email_sent', False):
         return Response(email_response, status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(email_response, status=status.HTTP_200_OK)
예제 #13
0
 def _email(self, user, data):
     quota = data.pop('quota')
     reason = data.pop('reason')
     email_response = resource_request_email(self.request, user.username,
                                             quota, reason)
     if not email_response.get('email_sent', False):
         return Response(email_response, status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(email_response, status=status.HTTP_200_OK)