import datetime
import os

from aws_lambda_tools.common import openapi_json_serde
from conio_sdk_generated.openapi.v2.serde.models.success import Success

from dist_v2.conio_sdk_generated.openapi.v2.serde.models.signin_response import SigninResponse
from test.integration.v2.base_integration_test import BaseV2IntegrationTest


class TestFullSignup(BaseV2IntegrationTest):
    def test(self):
        now = datetime.datetime.now()
        msg = self.create_full_signup_message(
            first_name=f'Test first name {now}',
            last_name=f'Test last name {now}',
            email='{}@test.com'.format(os.urandom(32).hex())
        )

        response = self.post('full_signup', msg, Success)
        self.assertEqual('success', response.status)
        response = self.login_external_user_id(
            msg.conio_credentials.user_id,
            msg.conio_credentials.password,
            '<UNRELEVANT>',
            'profile'
        )
        signin_response: SigninResponse = openapi_json_serde.deserialize(response.content, SigninResponse)
        self.assertEqual(3600, signin_response.expires_in)
        self.assertTrue(signin_response.access_token)
        self.assertTrue(signin_response.refresh_token)
