class FusionAuthClientTest(unittest2.TestCase):
    def setUp(self):
        self.client = FusionAuthClient('bf69486b-4733-4470-a592-f1bfce7af580',
                                       'http://*****:*****@vandaleyindustries.com')
        if get_user_response.status is 200:
            delete_user_response = self.client.delete_user(
                get_user_response.success_response['user']['id'])
            self.assertEqual(delete_user_response.status, 200,
                             delete_user_response.error_response)
        else:
            self.assertEqual(get_user_response.status, 404,
                             get_user_response.error_response)

        # Create a new registration for this user.
        user_request = {
            'sendSetPasswordEmail': False,
            'skipVerification': True,
            'user': {
                'email': '*****@*****.**',
                'password': '******'
            }
        }
        create_user_response = self.client.create_user(None, user_request)
        self.assertEqual(create_user_response.status, 200,
                         create_user_response.error_response)

        # Retrieve the user
        user_id = create_user_response.success_response['user']['id']
        get_user_response = self.client.retrieve_user(user_id)
        self.assertEqual(get_user_response.status, 200)
        self.assertIsNotNone(get_user_response.success_response)
        self.assertIsNone(get_user_response.error_response)
        self.assertEquals(get_user_response.success_response['user']['email'],
                          '*****@*****.**')
        self.assertFalse(
            'password' in get_user_response.success_response['user'])
        self.assertFalse('salt' in get_user_response.success_response['user'])

    def test_retrieve_user_missing(self):
        user_id = uuid.uuid4()
        client_response = self.client.retrieve_user(user_id)
        self.assertEqual(client_response.status, 404)
        self.assertIsNone(client_response.success_response)
        self.assertIsNone(client_response.error_response)
    def get(self, request):

        user_id = is_user_login_ok(request)
        if not user_id:
            login_url = get_login_url(request)
            return redirect(login_url)

        user = None
        birthday = None
        try:
            client = FusionAuthClient(settings.FUSION_AUTH_API_KEY,
                                      settings.FUSION_AUTH_BASE_URL)
            print(user_id)
            r = client.retrieve_user(user_id)
            print(request.user.username)
            if r.was_successful():
                birthday = r.success_response["user"].get(
                    "birthDate", 'unknown')
                print(birthday)
            else:
                print("coudln't get user")
                print(r.error_response)
            print("render dashboard with ", user_id)
            return render(request, "secretbirthdaysapp/dashboard.html", {
                "birthday": birthday,
                "user_id": user_id
            })
        except Exception as e:
            print("couldn't get user")
            print(e)
            return redirect(login_url)
class FusionAuthClientTest(unittest2.TestCase):
    def setUp(self):
        fusionauth_url = os.getenv(
            'FUSIONAUTH_URL'
        ) if 'FUSIONAUTH_URL' in os.environ else 'http://*****:*****@vandaleyindustries.com')
        if get_user_response.status is 200:
            delete_user_response = self.client.delete_user(
                get_user_response.success_response['user']['id'])
            self.assertEqual(delete_user_response.status, 200,
                             delete_user_response.error_response)
        else:
            self.assertEqual(get_user_response.status, 404,
                             get_user_response.error_response)

        # Create a new registration for this user.
        user_request = {
            'sendSetPasswordEmail': False,
            'skipVerification': True,
            'user': {
                'email': '*****@*****.**',
                'password': '******'
            }
        }
        create_user_response = self.client.create_user(user_request)
        self.assertEqual(create_user_response.status, 200,
                         create_user_response.error_response)

        # Retrieve the user
        user_id = create_user_response.success_response['user']['id']
        get_user_response = self.client.retrieve_user(user_id)
        self.assertEqual(get_user_response.status, 200)
        self.assertIsNotNone(get_user_response.success_response)
        self.assertIsNone(get_user_response.error_response)
        self.assertEquals(get_user_response.success_response['user']['email'],
                          '*****@*****.**')
        self.assertFalse(
            'password' in get_user_response.success_response['user'])
        self.assertFalse('salt' in get_user_response.success_response['user'])

    def test_retrieve_user_missing(self):
        user_id = uuid.uuid4()
        client_response = self.client.retrieve_user(user_id)
        self.assertEqual(client_response.status, 404)
        self.assertIsNone(client_response.success_response)
        self.assertIsNone(client_response.error_response)