Exemple #1
0
 def test_get_by_email_id_not_found(self):
     """If a contact is not found by email_id, an exception is raised."""
     ctms = CTMS(
         mock_interface("GET", 404, {"detail": "Unknown contact_id"}))
     with self.assertRaises(HTTPError) as context:
         ctms.get(email_id="unknown-id")
     assert context.exception.response.status_code == 404
Exemple #2
0
 def test_get_by_email_id(self):
     """If email_id is passed, GET /ctms/{email_id} is called."""
     email_id = self.TEST_CTMS_CONTACT["email"]["email_id"]
     interface = mock_interface("GET", 200, self.TEST_CTMS_CONTACT)
     ctms = CTMS(interface)
     user_data = ctms.get(email_id=email_id)
     assert user_data == self.TEST_BASKET_FORMAT
     interface.session.get.assert_called_once_with("/ctms/a-ctms-uuid")
Exemple #3
0
 def test_get_by_amo_id(self):
     """If amo_id is passed, GET /ctms?amo_id={amo_id} is called."""
     amo_id = self.TEST_CTMS_CONTACT["amo"]["user_id"]
     interface = mock_interface("GET", 200, [self.TEST_CTMS_CONTACT])
     ctms = CTMS(interface)
     user_data = ctms.get(amo_id=amo_id)
     assert user_data == self.TEST_BASKET_FORMAT
     interface.session.get.assert_called_once_with(
         "/ctms", params={"amo_user_id": amo_id})
Exemple #4
0
 def test_get_by_mofo_email_id(self):
     """If mofo_email_id is passed, GET /ctms?mofo_email_id={mofo_email_id} is called."""
     mofo_email_id = self.TEST_CTMS_CONTACT["mofo"]["mofo_email_id"]
     interface = mock_interface("GET", 200, [self.TEST_CTMS_CONTACT])
     ctms = CTMS(interface)
     user_data = ctms.get(mofo_email_id=mofo_email_id)
     assert user_data == self.TEST_BASKET_FORMAT
     interface.session.get.assert_called_once_with(
         "/ctms", params={"mofo_email_id": mofo_email_id})
Exemple #5
0
 def test_get_by_email(self):
     """If email is passed, GET /ctms?primary_email={email} is called."""
     email = self.TEST_CTMS_CONTACT["email"]["primary_email"]
     interface = mock_interface("GET", 200, [self.TEST_CTMS_CONTACT])
     ctms = CTMS(interface)
     user_data = ctms.get(email=email)
     assert user_data == self.TEST_BASKET_FORMAT
     interface.session.get.assert_called_once_with(
         "/ctms", params={"primary_email": email})
Exemple #6
0
 def test_get_by_token(self):
     """If token is passed, GET /ctms?basket_token={token} is called."""
     token = self.TEST_CTMS_CONTACT["email"]["basket_token"]
     interface = mock_interface("GET", 200, [self.TEST_CTMS_CONTACT])
     ctms = CTMS(interface)
     user_data = ctms.get(token=token)
     assert user_data == self.TEST_BASKET_FORMAT
     interface.session.get.assert_called_once_with(
         "/ctms", params={"basket_token": token})
Exemple #7
0
 def test_get_by_several_ids(self):
     """If if multiple IDs are passed, the best is used."""
     email_id = self.TEST_CTMS_CONTACT["email"]["email_id"]
     interface = mock_interface("GET", 200, self.TEST_CTMS_CONTACT)
     ctms = CTMS(interface)
     user_data = ctms.get(
         email_id=email_id, token="some-token", email="*****@*****.**"
     )
     assert user_data == self.TEST_BASKET_FORMAT
     interface.session.get.assert_called_once_with(f"/ctms/{email_id}")
Exemple #8
0
 def test_get_by_several_ids_both_none(self):
     """If multiple alt IDs are passed and all miss, None is returned."""
     interface = Mock(spec_set=["get_by_alternate_id"])
     interface.get_by_alternate_id.side_effect = ([], [])
     ctms = CTMS(interface)
     user_data = ctms.get(token="some-token",
                          email="*****@*****.**")
     assert user_data is None
     interface.get_by_alternate_id.assert_has_calls([
         call(basket_token="some-token"),
         call(primary_email="*****@*****.**"),
     ])
Exemple #9
0
 def test_get_by_several_ids_mult_then_one(self):
     """If multiple alt IDs are passed, the second is tried on dupes."""
     interface = Mock(spec_set=["get_by_alternate_id"])
     interface.get_by_alternate_id.side_effect = (
         [{"contact": 1}, {"contact": 2}],
         [self.TEST_CTMS_CONTACT],
     )
     ctms = CTMS(interface)
     user_data = ctms.get(sfdc_id="sfdc-123", amo_id="amo-123")
     assert user_data == self.TEST_BASKET_FORMAT
     interface.get_by_alternate_id.assert_has_calls(
         [call(amo_user_id="amo-123"), call(sfdc_id="sfdc-123")]
     )
Exemple #10
0
 def test_get_by_several_ids_none_then_one(self):
     """If multiple alt IDs are passed, the second is tried on miss."""
     interface = Mock(spec_set=["get_by_alternate_id"])
     interface.get_by_alternate_id.side_effect = ([], [self.TEST_CTMS_CONTACT])
     ctms = CTMS(interface)
     user_data = ctms.get(token="some-token", email="*****@*****.**")
     assert user_data == self.TEST_BASKET_FORMAT
     interface.get_by_alternate_id.assert_has_calls(
         [
             call(basket_token="some-token"),
             call(primary_email="*****@*****.**"),
         ]
     )
Exemple #11
0
 def test_get_by_token_not_found(self):
     """If a contact is not found by token, None is returned."""
     ctms = CTMS(mock_interface("GET", 200, []))
     assert ctms.get(token="unknown-token") is None
Exemple #12
0
 def test_get_no_interface(self):
     """If the interface is None (disabled or other issue), None is returned."""
     ctms = CTMS(None)
     assert ctms.get(token="token") is None