'Given an unauthenticated user, and an existing, inactive user account
with a linked identity, this should claim that identity and create
a new user account.'

def test_flow_as_unauthenticated_existing_inactive_user_with_merge_and_existing_identity(self):

    organization = self.create_organization(name='foo', owner=self.user)
    auth_provider = AuthProvider.objects.create(organization=organization, provider='dummy')
    user = self.create_user('bar@example.com', is_active=False)
    auth_identity = AuthIdentity.objects.create(auth_provider=auth_provider, user=user, ident='adfadsf@example.com')
    path = reverse('sentry-auth-organization', args=[organization.slug])
    resp = self.client.post(path)
    assert (resp.status_code == 200)
    assert (self.provider.TEMPLATE in resp.content.decode('utf-8'))
    path = reverse('sentry-auth-sso')
    resp = self.client.post(path, {'email': 'adfadsf@example.com'})
    self.assertTemplateUsed(resp, 'sentry/auth-confirm-identity.html')
    assert (resp.status_code == 200)
    assert (not resp.context['existing_user'])
    assert resp.context['login_form']
    resp = self.client.post(path, {'op': 'newuser'})
    assert (resp.status_code == 302)
    assert (resp['Location'] == ('http://testserver' + reverse('sentry-login')))
    auth_identity = AuthIdentity.objects.get(id=auth_identity.id)
    assert (auth_identity.ident == 'adfadsf@example.com')
    new_user = auth_identity.user
    assert (new_user != user)
    member = OrganizationMember.objects.get(organization=organization, user=new_user)
    assert getattr(member.flags, 'sso:linked')
    assert (not getattr(member.flags, 'sso:invalid'))
