def get_available_upstream_domains_for_user(domain_name, user): domains = [d.name for d in Domain.active_for_user(user)] return list({ domain for domain in domains if is_available_upstream_domain(domain, domain_name, user) })
def test_user_without_admin_access_returns_false(self, mock_user): with patch('corehq.apps.linked_domain.dbaccessors.is_active_upstream_domain') as mock_active_upstream,\ patch('corehq.apps.linked_domain.util.user_has_admin_access_in_all_domains') as mock_admin: mock_active_upstream.return_value = True mock_admin.return_value = False result = is_available_upstream_domain('potential-upstream', 'downstream', mock_user) self.assertFalse(result)
def test_same_domain_returns_false(self, mock_user): result = is_available_upstream_domain('domain', 'domain', mock_user) self.assertFalse(result)
def test_not_active_upstream_domain_returns_false(self, mock_user): with patch('corehq.apps.linked_domain.dbaccessors.is_active_upstream_domain') as mock_active_upstream: mock_active_upstream.return_value = False result = is_available_upstream_domain('potential-upstream', 'downstream', mock_user) self.assertFalse(result)
def test_none_potential_upstream_and_none_downstream_returns_false(self, mock_user): result = is_available_upstream_domain(None, None, mock_user) self.assertFalse(result)