11from unittest .mock import ANY , MagicMock , patch
22
33import pytest
4+ from mesh_client import INT_ENDPOINT , LIVE_ENDPOINT
45
56from manage_breast_screening .notifications .services .mesh_inbox import MeshInbox
67
910class TestMeshInbox :
1011 @pytest .fixture (autouse = True )
1112 def setup (self , monkeypatch ):
12- monkeypatch .setenv ("NBSS_MESH_HOST " , "https://mesh.test " )
13+ monkeypatch .setenv ("DJANGO_ENV " , "dev " )
1314 monkeypatch .setenv ("NBSS_MESH_INBOX_NAME" , "mesh-inbox-name" )
1415 monkeypatch .setenv ("NBSS_MESH_PASSWORD" , "mesh-password" )
15- monkeypatch .setenv ("NBSS_MESH_SHARED_KEY" , "mesh-shared-key" )
1616 monkeypatch .setenv ("NBSS_MESH_CERT" , "mesh-cert" )
1717 monkeypatch .setenv ("NBSS_MESH_PRIVATE_KEY" , "mesh-private-key" )
18- monkeypatch .setenv ("NBSS_MESH_CA_CERT" , "mesh-ca-cert" )
1918
2019 def test_client_initialises (self , mock_mesh_client ):
2120 with patch .object (
2221 MeshInbox ,
2322 "ssl_credentials" ,
24- return_value = ("cert" , "private-key" , "ca-cert" ),
23+ return_value = ("cert" , "private-key" ),
2524 ):
2625 MeshInbox ()
2726
2827 mock_mesh_client .assert_called_once_with (
29- url = "https://mesh.test" ,
28+ INT_ENDPOINT ,
29+ mailbox = "mesh-inbox-name" ,
30+ password = "mesh-password" ,
31+ cert = ("cert" , "private-key" ),
32+ )
33+
34+ def test_client_initialises_with_prod_endpoint (self , mock_mesh_client , monkeypatch ):
35+ monkeypatch .setenv ("DJANGO_ENV" , "production" )
36+ with patch .object (
37+ MeshInbox ,
38+ "ssl_credentials" ,
39+ return_value = ("cert" , "private-key" ),
40+ ):
41+ MeshInbox ()
42+
43+ mock_mesh_client .assert_called_once_with (
44+ LIVE_ENDPOINT ,
3045 mailbox = "mesh-inbox-name" ,
3146 password = "mesh-password" ,
32- shared_key = "mesh-shared-key" ,
3347 cert = ("cert" , "private-key" ),
34- verify = "ca-cert" ,
3548 )
3649
3750 def test_constructor_as_contextmanager (self , mock_mesh_client ):
3851 with MeshInbox () as inbox :
3952 inbox .fetch_message_ids ()
4053
4154 mock_mesh_client .assert_called_once_with (
42- url = "https://mesh.test" ,
55+ INT_ENDPOINT ,
4356 mailbox = "mesh-inbox-name" ,
4457 password = "mesh-password" ,
45- shared_key = "mesh-shared-key" ,
4658 cert = (ANY , ANY ),
47- verify = ANY ,
4859 )
4960 mock_mesh_client .return_value .list_messages .assert_called_once ()
5061 mock_mesh_client .return_value .close .assert_called_once ()
@@ -54,21 +65,16 @@ def test_ssl_credentials(self, _unused_mock):
5465 mock_cert_file .name = "cert"
5566 mock_private_key_file = MagicMock ()
5667 mock_private_key_file .name = "private-key"
57- mock_ca_cert_file = MagicMock ()
58- mock_ca_cert_file .name = "ca-cert"
5968
6069 with patch .object (
6170 MeshInbox ,
6271 "to_file" ,
63- side_effect = [mock_cert_file , mock_private_key_file , mock_ca_cert_file ],
72+ side_effect = [mock_cert_file , mock_private_key_file ],
6473 ):
65- cert_file_name , private_key_file_name , ca_cert_file_name = (
66- MeshInbox .ssl_credentials ()
67- )
74+ cert_file_name , private_key_file_name = MeshInbox .ssl_credentials ()
6875
6976 assert cert_file_name == "cert"
7077 assert private_key_file_name == "private-key"
71- assert ca_cert_file_name == "ca-cert"
7278
7379 def test_fetch_message_ids (self , mock_mesh_client ):
7480 MeshInbox ().fetch_message_ids ()
0 commit comments