testdonations.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # coding: utf-8
  2. from django.core.urlresolvers import reverse
  3. from rest_framework import status
  4. from rest_framework.test import APITestCase
  5. from .utils import utils
  6. from django.db import transaction
  7. from desecapi.models import Domain
  8. from django.core import mail
  9. import httpretty
  10. from django.conf import settings
  11. class UnsuccessfulDonationTests(APITestCase):
  12. def testExpectUnauthorizedOnGet(self):
  13. url = reverse('donation')
  14. response = self.client.get(url, format='json')
  15. self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
  16. def testExpectUnauthorizedOnPut(self):
  17. url = reverse('donation')
  18. response = self.client.put(url, format='json')
  19. self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
  20. def testExpectUnauthorizedOnDelete(self):
  21. url = reverse('donation')
  22. response = self.client.delete(url, format='json')
  23. self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
  24. class SuccessfulDonationTests(APITestCase):
  25. def testCanPostDonations(self):
  26. url = reverse('donation')
  27. data = \
  28. {
  29. 'name': 'Komplizierter Vörnämü-ßßß 马大为',
  30. 'iban': 'DE89370400440532013000',
  31. 'bic': 'BYLADEM1SWU',
  32. 'amount': 123.45,
  33. 'message': 'hi there, thank you. Also, some random chars: ™ • ½ ¼ ¾ ⅓ ⅔ † ‡ µ ¢ £ € « » ♤ ♧ ♥ ♢ ¿ ',
  34. 'email': 'email@example.com',
  35. }
  36. response = self.client.post(url, data)
  37. self.assertTrue(len(mail.outbox) > 0)
  38. email_internal = str(mail.outbox[0].message())
  39. direct_debit = str(mail.outbox[0].attachments[0][1])
  40. self.assertEqual(response.status_code, status.HTTP_201_CREATED)
  41. self.assertEqual(len(mail.outbox), 2)
  42. self.assertEqual(response.data['iban'], 'DE8937xxx')
  43. self.assertTrue('Komplizierter Vornamu' in direct_debit)
  44. self.assertTrue(data['iban'] in email_internal)