|
| 1 | +from mock import mock |
| 2 | + |
| 3 | +from django.template.loader import render_to_string |
| 4 | +from django.conf import settings as ccsettings |
| 5 | + |
| 6 | +from contentcuration.tests import testdata |
| 7 | +from contentcuration.tests.base import StudioAPITestCase |
| 8 | +from contentcuration.views.settings import StorageSettingsView |
| 9 | +from contentcuration.forms import StorageRequestForm |
| 10 | + |
| 11 | +class StorageSettingsViewTestCase(StudioAPITestCase): |
| 12 | + |
| 13 | + def setUp(self): |
| 14 | + super(StorageSettingsViewTestCase, self).setUp() |
| 15 | + self.view = StorageSettingsView() |
| 16 | + self.view.request = mock.Mock() |
| 17 | + self.view.request.user = testdata.user(email="tester@tester.com") |
| 18 | + |
| 19 | + def test_storage_request(self): |
| 20 | + |
| 21 | + with mock.patch("contentcuration.views.settings.send_mail") as send_mail: |
| 22 | + |
| 23 | + data = dict( |
| 24 | + storage="storage", |
| 25 | + kind="kind", |
| 26 | + resource_count="resource_count", |
| 27 | + resource_size="resource_size", |
| 28 | + creators="creators", |
| 29 | + sample_link="sample_link", |
| 30 | + license="license", |
| 31 | + public="channel1, channel2", |
| 32 | + audience="audience", |
| 33 | + import_count="import_count", |
| 34 | + location="location", |
| 35 | + uploading_for="uploading_for", |
| 36 | + organization_type="organization_type", |
| 37 | + time_constraint="time_constraint", |
| 38 | + message="message" |
| 39 | + ) |
| 40 | + self.form = StorageRequestForm(data=data) |
| 41 | + |
| 42 | + self.assertTrue(self.form.is_valid()) |
| 43 | + self.view.form_valid(self.form) |
| 44 | + |
| 45 | + message = render_to_string( |
| 46 | + "settings/storage_request_email.txt", |
| 47 | + { |
| 48 | + "data": self.form.cleaned_data, |
| 49 | + "user": self.view.request.user, |
| 50 | + "channels": ["channel1", "channel2"] |
| 51 | + }, |
| 52 | + ) |
| 53 | + |
| 54 | + send_mail.assert_called_once() |
| 55 | + send_mail.assert_called_with( |
| 56 | + f"Kolibri Studio storage request from {self.view.request.user.email}", |
| 57 | + message, |
| 58 | + ccsettings.DEFAULT_FROM_EMAIL, |
| 59 | + [ccsettings.SPACE_REQUEST_EMAIL, self.view.request.user.email], |
| 60 | + ) |
0 commit comments