'Ensure user repositories aren\'t leaked to other users'

def test_permissions(self):

    client = APIClient()
    account_a = get(SocialAccount, provider='github')
    account_b = get(SocialAccount, provider='github')
    account_c = get(SocialAccount, provider='github')
    user_a = get(User, password='test', socialaccount_set=[account_a])
    user_b = get(User, password='test', socialaccount_set=[account_b])
    user_c = get(User, password='test', socialaccount_set=[account_c])
    org_a = get(RemoteOrganization, users=[user_a], account=account_a)
    repo_a = get(RemoteRepository, users=[user_a], organization=org_a, account=account_a)
    repo_b = get(RemoteRepository, users=[user_b], organization=None, account=account_b)
    client.force_authenticate(user=user_a)
    resp = client.get('/api/v2/remote/repo/', format='json')
    self.assertEqual(resp.status_code, status.HTTP_200_OK)
    repos = resp.data['results']
    self.assertEqual(repos[0]['id'], repo_a.id)
    self.assertEqual(repos[0]['organization']['id'], org_a.id)
    self.assertEqual(len(repos), 1)
    resp = client.get('/api/v2/remote/org/', format='json')
    self.assertEqual(resp.status_code, status.HTTP_200_OK)
    orgs = resp.data['results']
    self.assertEqual(orgs[0]['id'], org_a.id)
    self.assertEqual(len(orgs), 1)
    client.force_authenticate(user=user_b)
    resp = client.get('/api/v2/remote/repo/', format='json')
    self.assertEqual(resp.status_code, status.HTTP_200_OK)
    repos = resp.data['results']
    self.assertEqual(repos[0]['id'], repo_b.id)
    self.assertEqual(repos[0]['organization'], None)
    self.assertEqual(len(repos), 1)
    client.force_authenticate(user=user_c)
    resp = client.get('/api/v2/remote/repo/', format='json')
    self.assertEqual(resp.status_code, status.HTTP_200_OK)
    repos = resp.data['results']
    self.assertEqual(len(repos), 0)
