from ykman.oath import Credential
import unittest


class TestOathFunctions(unittest.TestCase):

    def test_credential_parse_period_and_issuer_and_name(self):
        period, issuer, name = Credential.parse_name('20/Issuer:name')
        self.assertEqual(20, period)
        self.assertEqual('Issuer', issuer)
        self.assertEqual('name', name)

    def test_credential_parse_wierd_issuer_and_name(self):
        period, issuer, name = Credential.parse_name('wierd/Issuer:name')
        self.assertEqual(30, period)
        self.assertEqual('wierd/Issuer', issuer)
        self.assertEqual('name', name)

    def test_credential_parse_issuer_and_name(self):
        period, issuer, name = Credential.parse_name('Issuer:name')
        self.assertEqual(30, period)
        self.assertEqual('Issuer', issuer)
        self.assertEqual('name', name)

    def test_credential_parse_period_and_name(self):
        period, issuer, name = Credential.parse_name('20/name')
        self.assertEqual(20, period)
        self.assertEqual(None, issuer)
        self.assertEqual('name', name)

    def test_credential_parse_only_name(self):
        period, issuer, name = Credential.parse_name('name')
        self.assertEqual(30, period)
        self.assertEqual(None, issuer)
        self.assertEqual('name', name)

    def test_credential_serialize_name(self):
        self.assertEqual('name', Credential.serialize_name('name'))
        self.assertEqual(
            'Issuer:name', Credential.serialize_name('name', issuer='Issuer'))
        self.assertEqual(
            '20/Issuer:name', Credential.serialize_name(
                'name', issuer='Issuer', period=20))
        self.assertEqual(
            'Issuer:name', Credential.serialize_name(
                'name', issuer='Issuer', period=30))
        self.assertEqual(
            '20/name', Credential.serialize_name('name', period=20))

    def test_credential_expiration(self):
        cred = Credential('name')
        cred.update_expiration(0)
        self.assertEqual(30, cred.expiration)
        cred.update_expiration(30)
        self.assertEqual(60, cred.expiration)
        cred.update_expiration(60)
        self.assertEqual(90, cred.expiration)

@@ -194,32 +194,37 @@
 redential.parse_
+long_
 name('20/Issuer:
@@ -453,24 +453,29 @@
 ntial.parse_
+long_
 name('wierd/
@@ -711,24 +711,29 @@
 ntial.parse_
+long_
 name('Issuer
@@ -957,24 +957,29 @@
 ntial.parse_
+long_
 name('20/nam
@@ -1193,16 +1193,21 @@
 l.parse_
+long_
 name('na
@@ -1416,38 +1416,35 @@
 edential
-.serialize_name('
+('name').long_
 name
-'
+(
 ))%0A     
@@ -1497,39 +1497,24 @@
 , Credential
-.serialize_name
 ('name', iss
@@ -1526,16 +1526,28 @@
 Issuer')
+.long_name()
 )%0A      
@@ -1602,39 +1602,24 @@
 , Credential
-.serialize_name
 (%0A          
@@ -1659,16 +1659,28 @@
 riod=20)
+.long_name()
 )%0A      
@@ -1736,31 +1736,16 @@
 edential
-.serialize_name
 (%0A      
@@ -1789,16 +1789,28 @@
 riod=30)
+.long_name()
 )%0A      
@@ -1866,23 +1866,8 @@
 tial
-.serialize_name
 ('na
@@ -1881,16 +1881,28 @@
 riod=20)
+.long_name()
 )%0A%0A    d

fix oath tests