aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/test/unit/test_inbound_send.py
blob: 19ee5de1d5e28937bbf9707c52f02b10a587a0b3 (about) (plain)
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
49
import argparse
import unittest

from sendgrid.helpers.inbound import send

try:
    import unittest.mock as mock
except ImportError:
    import mock


class UnitTests(unittest.TestCase):
    def setUp(self):
        self.client_mock = mock.patch('sendgrid.helpers.inbound.send.Client')
        self.open_mock = mock.patch('sendgrid.helpers.inbound.send.open',
                                    mock.mock_open(), create=True)
        self.client_mock.start()
        self.open_mock.start()

    def tearDown(self):
        self.client_mock.stop()
        self.open_mock.stop()

    def test_send(self):

        fake_url = 'https://fake_url'
        x = send.Send(fake_url)
        x.test_payload(fake_url)

        send.Client.assert_called_once_with(
            host=fake_url,
            request_headers={
                'User-Agent': 'SendGrid-Test',
                'Content-Type': 'multipart/form-data; boundary=xYzZY'
            })

    def test_main_call(self):
        fake_url = 'https://fake_url'

        with mock.patch(
            'argparse.ArgumentParser.parse_args',
            return_value=argparse.Namespace(
                host=fake_url, data='test_file.txt')):
            send.main()
            send.Client.assert_called_once_with(
                host=fake_url,
                request_headers={
                    'User-Agent': 'SendGrid-Test',
                    'Content-Type': 'multipart/form-data; boundary=xYzZY'})