def test_user_without_admin_access_returns_false(self, mock_user): with patch('corehq.apps.linked_domain.util.is_domain_in_active_link') as mock_active_link,\ patch('corehq.apps.linked_domain.util.user_has_admin_access_in_all_domains') as mock_admin: mock_active_link.return_value = False mock_admin.return_value = False result = is_domain_available_to_link('upstream', 'downstream', mock_user) self.assertFalse(result)
def get_available_domains_to_link_for_user(upstream_domain_name, user): """ Finds available domains to link based on domains that the provided user is active or an admin in """ domains = [d.name for d in Domain.active_for_user(user)] return list({ domain for domain in domains if is_domain_available_to_link(upstream_domain_name, domain, user) })
def test_same_domain_returns_false(self, mock_user): result = is_domain_available_to_link('domain', 'domain', mock_user) self.assertFalse(result)
def test_domain_in_active_link_returns_false(self, mock_user): with patch('corehq.apps.linked_domain.util.is_domain_in_active_link') as mock_active_link: mock_active_link.return_value = True result = is_domain_available_to_link('upstream', 'downstream', mock_user) self.assertFalse(result)
def test_none_upstream_and_none_candidate_domain_returns_false(self, mock_user): result = is_domain_available_to_link(None, None, mock_user) self.assertFalse(result)