|
2 | 2 |
|
3 | 3 | from captcha.models import CaptchaStore |
4 | 4 |
|
5 | | -from apps.resources.models import ContactRequest |
| 5 | +from apps.resources.models import ContactRequest, RequestDemo |
| 6 | +from apps.tool_picker.factories import ToolFactory |
6 | 7 | from apps.user.factories import UserFactory |
7 | 8 | from main.tests import TestCase |
8 | 9 |
|
@@ -114,3 +115,78 @@ def test_create_contact_request_without_captcha(self): |
114 | 115 | "pydantic_errors": None, |
115 | 116 | }, |
116 | 117 | ] |
| 118 | + |
| 119 | + |
| 120 | +class TestRequestDemoMutation(TestCase): |
| 121 | + class Mutation: |
| 122 | + CREATE_DEMO_REQUEST = """ |
| 123 | + mutation createDemoRequest($data: RequestDemoInput!) { |
| 124 | + createDemoRequest(data: $data) { |
| 125 | + ... on RequestDemoTypeMutationResponseType { |
| 126 | + errors |
| 127 | + ok |
| 128 | + result { |
| 129 | + id |
| 130 | + name |
| 131 | + email |
| 132 | + nationalSociety |
| 133 | + content |
| 134 | + tool{ |
| 135 | + pk |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + ... on OperationInfo { |
| 140 | + __typename |
| 141 | + messages { |
| 142 | + code |
| 143 | + field |
| 144 | + kind |
| 145 | + message |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + """ |
| 151 | + |
| 152 | + @typing.override |
| 153 | + @classmethod |
| 154 | + def setUpClass(cls): |
| 155 | + super().setUpClass() |
| 156 | + cls.user = UserFactory.create(email="test@gmail.com") |
| 157 | + cls.tool = ToolFactory.create() |
| 158 | + |
| 159 | + def _create_tool_demo_request_mutation(self, data: dict[str, str | int], **kwargs: typing.Any): |
| 160 | + return self.query_check( |
| 161 | + query=self.Mutation.CREATE_DEMO_REQUEST, |
| 162 | + variables={ |
| 163 | + "data": data, |
| 164 | + }, |
| 165 | + ) |
| 166 | + |
| 167 | + def test_create_tool_demo_request(self): |
| 168 | + tool_demo_request_data = { |
| 169 | + "name": "John", |
| 170 | + "email": "john@test.com", |
| 171 | + "nationalSociety": "Test National Society", |
| 172 | + "content": "This is test content", |
| 173 | + "tool": self.tool.id, |
| 174 | + } |
| 175 | + |
| 176 | + content = self._create_tool_demo_request_mutation(data=tool_demo_request_data) |
| 177 | + response_data = content["data"]["createDemoRequest"] |
| 178 | + |
| 179 | + assert response_data["ok"] is True |
| 180 | + assert response_data["errors"] is None |
| 181 | + |
| 182 | + demo_request = RequestDemo.objects.get(pk=response_data["result"]["id"]) |
| 183 | + assert response_data["result"] == { |
| 184 | + "id": self.gID(demo_request.pk), |
| 185 | + "name": demo_request.name, |
| 186 | + "email": demo_request.email, |
| 187 | + "content": demo_request.content, |
| 188 | + "nationalSociety": demo_request.national_society, |
| 189 | + "tool": { |
| 190 | + "pk": self.gID(demo_request.tool.pk), |
| 191 | + }, |
| 192 | + } |
0 commit comments