'Test get_or_create_customer_profile'

@patch('r2.lib.authorize.interaction.api.get_customer_profile')
@patch('r2.lib.authorize.interaction.api.create_customer_profile')
def test_get_or_create_customer_profile(self, create_customer_profile, get_customer_profile):

    create_customer_profile.return_value = 123
    profile = MagicMock()
    profile.merchantCustomerId = self.user._fullname
    get_customer_profile.return_value = profile
    get_or_create_customer_profile(self.user)
    self.assertEqual(create_customer_profile.call_count, 1)
    self.assertEqual(get_customer_profile.call_count, 1)
    with patch('r2.lib.authorize.interaction.CustomerID.get_id') as get_id:
        get_id.return_value = create_customer_profile.return_value
        get_or_create_customer_profile(self.user)
        self.assertEqual(create_customer_profile.call_count, 1)
        self.assertEqual(get_customer_profile.call_count, 2)
