import base64

from conio_sdk.generated_protobuf import v1_pb2
from test.integration.v1.base_integration_test import BaseV1IntegrationTest


class TestTC(BaseV1IntegrationTest):
    def test_tc(self):
        resp = self.client.get(
            '/v1/terms_and_conditions_and_privacy_policy',
            headers={'Content-Type': 'application/octet-stream'})
        self.assertEqual(200, resp.status_code)
        response = v1_pb2.TermsAndConditionsAndPrivacyPolicy()
        response.ParseFromString(base64.b64decode(resp.content))
        self.assertEqual(
            'https://conio-mobile-wallet.firebaseapp.com/mobile-tc-{language}.html',
            response.terms_and_conditions_url
        )
        self.assertEqual(
            'https://conio-mobile-wallet.firebaseapp.com/mobile-privacy-{language}.html',
            response.privacy_policies_url
        )
        expected_acceptances = {'APP_IMPROVEMENT', 'CLIENT_SUPPORT'}
        for a in response.acceptances:
            msg = str(a)
            self.assertTrue(a.acceptance_type in expected_acceptances, msg=msg)
            expected_acceptances.remove(a.acceptance_type)
            self.assertTrue(a.mandatory, msg=msg)
