'test that a superuser can register when registration is admin only.'

@override_settings(REGISTRATION_MODE=u'admin_only')
def test_auth_registration_admin_only_works(self):

    url = u'/v1/auth/register'
    (username, password) = (u'newuser_by_admin', u'password')
    (first_name, last_name) = (u'Otto', u'Test')
    email = u'autotest@deis.io'
    submit = {u'username': username, u'password': password, u'first_name': first_name, u'last_name': last_name, u'email': email, u'is_superuser': True, u'is_staff': True}
    response = self.client.post(url, json.dumps(submit), content_type=u'application/json', HTTP_AUTHORIZATION=u'token    {}'.format(self.admin_token))
    self.assertEqual(response.status_code, 201)
    for key in response.data:
        self.assertIn(key, [u'id', u'last_login', u'is_superuser', u'username', u'first_name', u'last_name', u'email', u'is_active', u'is_superuser', u'is_staff', u'date_joined', u'groups', u'user_permissions'])
    expected = {u'username': username, u'email': email, u'first_name': first_name, u'last_name': last_name, u'is_active': True, u'is_superuser': False, u'is_staff': False}
    self.assertDictContainsSubset(expected, response.data)
    url = u'/v1/auth/login/'
    payload = urllib.urlencode({u'username': username, u'password': password})
    response = self.client.post(url, data=payload, content_type=u'application/x-www-form-urlencoded')
    self.assertEqual(response.status_code, 200)
