Esempio n. 1
0
    def test_update_use_existing_lang_and_format(self, mock_slugs, mock_langs):
        """CTMS.update uses the existing language and format"""
        updated = {"updated": "fake_response"}
        interface = mock_interface("PATCH", 200, updated)
        ctms = CTMS(interface)

        user_data = {
            "token": "an-existing-user",
            "email_id": "an-existing-id",
            "lang": "fr",
            "format": "T",
        }
        update_data = {"newsletters": ["slug1"]}
        assert ctms.update(user_data, update_data) == updated
        interface.session.patch.assert_called_once_with(
            "/ctms/an-existing-id",
            json={
                "newsletters": [{
                    "name": "slug1",
                    "subscribed": True,
                    "lang": "fr",
                    "format": "T"
                }]
            },
        )
Esempio n. 2
0
    def test_update_email_id_not_in_existing_data(self):
        """
        CTMS.update requires an email_id in existing data.

        TODO: This should raise an exception after the SDFC to CTMS
        transition. However, the calling code is simplier if it does
        nothing when there is no existing email_id.
        """
        ctms = CTMS("interface should not be called")
        user_data = {"token": "an-existing-user"}
        update_data = {"first_name": "Elizabeth", "email_id": "a-new-email-id"}
        assert ctms.update(user_data, update_data) is None
Esempio n. 3
0
    def test_update(self):
        """CTMS.update calls PATCH /ctms/{email_id}."""
        updated = {
            "email": {
                "basket_token": "an-existing-user",
                "email_id": "an-existing-id",
                "first_name": "Jane",
            }
        }
        interface = mock_interface("PATCH", 200, updated)
        ctms = CTMS(interface)

        user_data = {"token": "an-existing-user", "email_id": "an-existing-id"}
        update_data = {"first_name": "Jane"}
        assert ctms.update(user_data, update_data) == updated
        interface.session.patch.assert_called_once_with(
            "/ctms/an-existing-id", json={"email": {"first_name": "Jane"}}
        )
Esempio n. 4
0
 def test_update_no_interface(self):
     """If the interface is None (disabled or other issue), None is returned."""
     ctms = CTMS(None)
     user_data = {"token": "an-existing-user", "email_id": "an-existing-id"}
     update_data = {"first_name": "Jane"}
     assert ctms.update(user_data, update_data) is None