def test_cancel(self):
        # test registration workflow
        username, password = 'newuser', 'password'
        submit = {
            'username': username,
            'password': password,
            'first_name': 'Otto',
            'last_name': 'Test',
            'email': 'autotest@deis.io',
            # try to abuse superuser/staff level perms
            'is_superuser': True,
            'is_staff': True,
        }

        other_username, other_password = 'newuser2', 'password'
        other_submit = {
            'username': other_username,
            'password': other_password,
            'first_name': 'Test',
            'last_name': 'Tester',
            'email': 'autotest-2@deis.io',
            'is_superuser': False,
            'is_staff': False,
        }
        url = '/v1/auth/register'
        response = self.client.post(url, json.dumps(submit), content_type='application/json')
        self.assertEqual(response.status_code, 201)

        # cancel the account
        url = '/v1/auth/cancel'
        user = User.objects.get(username=username)
        token = Token.objects.get(user=user).key
        response = self.client.delete(url,
                                      HTTP_AUTHORIZATION='token {}'.format(token))
        self.assertEqual(response.status_code, 204)

        url = '/v1/auth/register'
        response = self.client.post(url, json.dumps(other_submit), content_type='application/json')
        self.assertEqual(response.status_code, 201)

        # normal user can't delete another user
        url = '/v1/auth/cancel'
        other_user = User.objects.get(username=other_username)
        other_token = Token.objects.get(user=other_user).key
        response = self.client.delete(url, json.dumps({'username': self.admin.username}),
                                      content_type='application/json',
                                      HTTP_AUTHORIZATION='token {}'.format(other_token))
        self.assertEqual(response.status_code, 403)

        # admin can delete another user
        response = self.client.delete(url, json.dumps({'username': other_username}),
                                      content_type='application/json',
                                      HTTP_AUTHORIZATION='token {}'.format(self.admin_token))
        self.assertEqual(response.status_code, 204)
        # user can not be deleted if it has an app attached to it
        response = self.client.post(
            '/v1/apps',
            HTTP_AUTHORIZATION='token {}'.format(self.admin_token)
        )
        self.assertEqual(response.status_code, 201)
        app_id = response.data['id']  # noqa
        self.assertIn('id', response.data)

        response = self.client.delete(url, json.dumps({'username': str(self.admin)}),
                                      content_type='application/json',
                                      HTTP_AUTHORIZATION='token {}'.format(self.admin_token))
        self.assertEqual(response.status_code, 409)
Validate that the email is not already registered with another user
dataset/ETHPy150Open deis/deis/controller/api/tests/test_auth.py/AuthTest.test_cancel--crossover with--dataset/ETHPy150Open bread-and-pepper/django-userena/userena/forms.py/ChangeEmailForm.clean_email