|
14 | 14 |
|
15 | 15 | class TestPoweremailSignaturit(testing.OOTestCaseWithCursor): |
16 | 16 |
|
17 | | - signaturit_sandbox_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
18 | | - |
19 | | - def get_sandbox_client(self): |
20 | | - client = SignaturitClient(self.signaturit_sandbox_token, False) |
21 | | - return client |
22 | | - |
23 | | - def test_POST_email_simple(self): |
24 | | - cursor = self.cursor |
25 | | - uid = self.uid |
26 | | - pool = self.openerp.pool |
27 | | - #client = self.get_sandbox_client() |
28 | | - |
29 | | - # He comentat el test per no fer una crida sempre que es facin els tests, pero ho deixo per veure com es pot cridar la api |
30 | | - |
31 | | - # res = client.create_email( |
32 | | - # files=[], |
33 | | - # recipients=[{'name': 'Eduard', 'email': 'eberloso@gisce.net'}], |
34 | | - # subject="Email Certificat Simple", |
35 | | - # body="Aixo es un email <b>certificat</b>", |
36 | | - # params={'type': "open_email"} |
37 | | - # ) |
38 | | - # self.assertTrue(res['id']) |
39 | | - # self.assertEqual(res['certificates'][0]['status'], u'in_queue') |
40 | | - # self.assertEqual(res['certificates'][0]['name'], u'Eduard') |
41 | | - # self.assertEqual(res['certificates'][0]['email'], u'eberloso@gisce.net') |
42 | | - |
43 | 17 | @mock.patch("signaturit_sdk.signaturit_client.SignaturitClient.get_email") |
44 | | - @mock.patch("poweremail_signaturit.poweremail_core.get_signaturit_client") |
45 | | - def test_update_poweremail_certificat_state(self, mocked_get_signaturit_client, mocked): |
| 18 | + def test_update_poweremail_certificat_state(self, mocked): |
46 | 19 | cursor = self.cursor |
47 | 20 | uid = self.uid |
48 | 21 | pool = self.openerp.pool |
49 | | - client = self.get_sandbox_client() |
50 | | - config['signaturit_token'] = 'RANDOM_RANDOM' |
51 | | - mocked_get_signaturit_client.return_value = client |
52 | 22 |
|
53 | 23 | poweracc_o = pool.get("poweremail.core_accounts") |
54 | 24 | poweremail_o = pool.get("poweremail.mailbox") |
@@ -108,17 +78,13 @@ def test_update_poweremail_certificat_state(self, mocked_get_signaturit_client, |
108 | 78 | self.assertEqual(poweremail_o.read(cursor, uid, pwid, ['certificat_state'])['certificat_state'], "document_opened") |
109 | 79 |
|
110 | 80 | @mock.patch("signaturit_sdk.signaturit_client.SignaturitClient.create_email") |
111 | | - @mock.patch("poweremail_signaturit.poweremail_core.get_signaturit_client") |
112 | | - def test_send_mail_certificat_fails_and_returns_false(self, mocked_get_signaturit_client, mock_create_email): |
| 81 | + def test_send_mail_certificat_fails_and_returns_false(self, mock_create_email): |
113 | 82 | cursor = self.cursor |
114 | 83 | uid = self.uid |
115 | 84 | pool = self.openerp.pool |
116 | 85 | poweracc_o = pool.get("poweremail.core_accounts") |
117 | 86 | poweremail_o = pool.get("poweremail.mailbox") |
118 | 87 |
|
119 | | - client = self.get_sandbox_client() |
120 | | - mocked_get_signaturit_client.return_value = client |
121 | | - |
122 | 88 | ids = [ |
123 | 89 | poweracc_o.create(cursor, uid, { |
124 | 90 | 'email_id': "algunmail@gisce.net", |
@@ -148,20 +114,18 @@ def test_send_mail_certificat_fails_and_returns_false(self, mocked_get_signaturi |
148 | 114 | ) |
149 | 115 | self.assertFalse(res) |
150 | 116 |
|
151 | | - @mock.patch("poweremail_signaturit.poweremail_core.get_signaturit_client") |
152 | 117 | @mock.patch("signaturit_sdk.signaturit_client.SignaturitClient.create_email") |
153 | | - def test_send_mail_certificat_ok_and_returns_true(self, mocked_create_email, mocked_get_signaturit_client): |
| 118 | + def test_send_mail_certificat_ok_and_returns_true(self, mocked_create_email): |
154 | 119 | cursor = self.cursor |
155 | 120 | uid = self.uid |
156 | 121 | pool = self.openerp.pool |
157 | 122 | poweracc_o = pool.get("poweremail.core_accounts") |
158 | 123 | poweremail_o = pool.get("poweremail.mailbox") |
159 | 124 |
|
160 | | - client = self.get_sandbox_client() |
161 | | - mocked_get_signaturit_client.return_value = client |
162 | 125 | # Per evitar anar enviant emails, fem un mock id espres validem que es crida com esperem |
163 | 126 | mocked_create_email.return_value = {'id': "123456789"} |
164 | 127 |
|
| 128 | + compte_signaturit_company_1 = pool.get("ir.model.data").get_object_reference(cursor, uid, "giscedata_signatura_documents_signaturit", "giscedata_signature_provider_account_0001")[1] |
165 | 129 | ids = [ |
166 | 130 | poweracc_o.create(cursor, uid, { |
167 | 131 | 'email_id': "algunmail@gisce.net", |
@@ -195,3 +159,14 @@ def test_send_mail_certificat_ok_and_returns_true(self, mocked_create_email, moc |
195 | 159 | body=body['html'], |
196 | 160 | params={'type': "open_document", "recipients": {}} |
197 | 161 | ) |
| 162 | + # Si feia el mock de les dos coses alhora no ho sabia fer funcionar be perque un mock crida l'altre i es feia un lio |
| 163 | + with mock.patch('giscedata_signatura_documents_signaturit.giscedata_signature_providers.GiscedataSignatureProviderAccount.get_client') as mocked_get_client: |
| 164 | + poweracc_o.send_mail_certificat( |
| 165 | + cursor, uid, ids, addresses, subject=subject, body=body, payload=payload, context=context |
| 166 | + ) |
| 167 | + mocked_get_client.assert_called_with( |
| 168 | + cursor, |
| 169 | + uid, |
| 170 | + compte_signaturit_company_1, |
| 171 | + context={'poweremail_id': pwid} |
| 172 | + ) |
0 commit comments