File: test_email_endpoints.py

package info (click to toggle)
auth0-python 4.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,280 kB
  • sloc: python: 8,933; makefile: 15; sh: 2
file content (48 lines) | stat: -rw-r--r-- 1,674 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import unittest
from unittest import mock

from ...management.email_templates import EmailTemplates


class TestClients(unittest.TestCase):
    def test_init_with_optionals(self):
        t = EmailTemplates(
            domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2)
        )
        self.assertEqual(t.client.options.timeout, (10, 2))
        telemetry_header = t.client.base_headers.get("Auth0-Client", None)
        self.assertEqual(telemetry_header, None)

    @mock.patch("auth0.management.email_templates.RestClient")
    def test_create(self, mock_rc):
        mock_instance = mock_rc.return_value

        c = EmailTemplates(domain="domain", token="jwttoken")
        c.create({"a": "b", "c": "d"})

        mock_instance.post.assert_called_with(
            "https://domain/api/v2/email-templates", data={"a": "b", "c": "d"}
        )

    @mock.patch("auth0.management.email_templates.RestClient")
    def test_get(self, mock_rc):
        mock_instance = mock_rc.return_value

        c = EmailTemplates(domain="domain", token="jwttoken")
        c.get("this-template-name")

        mock_instance.get.assert_called_with(
            "https://domain/api/v2/email-templates/this-template-name"
        )

    @mock.patch("auth0.management.email_templates.RestClient")
    def test_update(self, mock_rc):
        mock_instance = mock_rc.return_value

        c = EmailTemplates(domain="domain", token="jwttoken")
        c.update("this-template-name", {"a": "b", "c": "d"})

        mock_instance.patch.assert_called_with(
            "https://domain/api/v2/email-templates/this-template-name",
            data={"a": "b", "c": "d"},
        )