"""Split model tests module."""

from splitio.models import token
from splitio.models.grammar.condition import Condition


class TokenTests(object):
    """Token model tests."""
    raw_false = {'pushEnabled': False}

    def test_from_raw_false(self):
        """Test token model parsing."""
        parsed = token.from_raw(self.raw_false)
        assert parsed == None
    
    raw_empty = {
        'pushEnabled': True,
        'token': '',
    }

    def test_from_raw_empty(self):
        """Test token model parsing."""
        parsed = token.from_raw(self.raw_empty)
        assert parsed == None

    raw_ok = {
        'pushEnabled': True,
        'token': '<KEY>',
    }

    def test_from_raw(self):
        """Test token model parsing."""
        parsed = token.from_raw(self.raw_ok)
        assert isinstance(parsed, token.Token)
        assert parsed.push_enabled == True
        assert parsed.iat == 1602084527
        assert parsed.exp == 1602088127
        assert parsed.channels['NzM2MDI5Mzc0_MTgyNTg1MTgwNg==_segments'] == ['subscribe']
        assert parsed.channels['NzM2MDI5Mzc0_MTgyNTg1MTgwNg==_splits'] == ['subscribe']
        assert parsed.channels['control_pri'] == ['subscribe', 'channel-metadata:publishers']
        assert parsed.channels['control_sec'] == ['subscribe', 'channel-metadata:publishers']


"""Split model tests module."""

from splitio.models import token
from splitio.models.grammar.condition import Condition


class TokenTests(object):
    """Token model tests."""
    raw_false = {'pushEnabled': False}

    def test_from_raw_false(self):
        """Test token model parsing."""
        parsed = token.from_raw(self.raw_false)
        assert parsed == None
    
    raw_empty = {
        'pushEnabled': True,
        'token': '',
    }

    def test_from_raw_empty(self):
        """Test token model parsing."""
        parsed = token.from_raw(self.raw_empty)
        assert parsed == None

    raw_ok = {
        'pushEnabled': True,
        'token': '<KEY>',
    }

    def test_from_raw(self):
        """Test token model parsing."""
        parsed = token.from_raw(self.raw_ok)
        assert isinstance(parsed, token.Token)
        assert parsed.push_enabled == True
        assert parsed.iat == 1602084527
        assert parsed.exp == 1602088127
        assert parsed.channels['NzM2MDI5Mzc0_MTgyNTg1MTgwNg==_segments'] == ['subscribe']
        assert parsed.channels['NzM2MDI5Mzc0_MTgyNTg1MTgwNg==_splits'] == ['subscribe']
        assert parsed.channels['control_pri'] == ['subscribe', 'channel-metadata:publishers']
        assert parsed.channels['control_sec'] == ['subscribe', 'channel-metadata:publishers']


Split model tests module. Token model tests. Test token model parsing. Test token model parsing. Test token model parsing.