from pyutrack import Credentials
from tests import PyutrackTest


class CredentialsTests(PyutrackTest):
    def test_empty(self):
        c = Credentials('root')
        self.assertIsNone(c.password)
        self.assertIsNone(c.cookies)

import json

import keyring

from pyutrack import Credentials
from tests import PyutrackTest


class CredentialsTests(PyutrackTest):
    def test_empty(self):
        c = Credentials('root')
        self.assertIsNone(c.password)
        self.assertIsNone(c.cookies)

    def test_persistence(self):
        c = Credentials('root', 'passwd', {"key": "value"})
        c.persist()
        self.assertEqual(
            keyring.get_password(Credentials.KEYRING_PASSWORD, 'root'), 'passwd'
        )
        self.assertEqual(
            json.loads(keyring.get_password(Credentials.KEYRING_COOKIE, 'root')),
            {"key": "value"}

        )



Add test for credential persistence
Add test for credential persistence

+ import json
+ 
+ import keyring
+ 
  from pyutrack import Credentials
  from tests import PyutrackTest
  
  
  class CredentialsTests(PyutrackTest):
      def test_empty(self):
          c = Credentials('root')
          self.assertIsNone(c.password)
          self.assertIsNone(c.cookies)
  
+     def test_persistence(self):
+         c = Credentials('root', 'passwd', {"key": "value"})
+         c.persist()
+         self.assertEqual(
+             keyring.get_password(Credentials.KEYRING_PASSWORD, 'root'), 'passwd'
+         )
+         self.assertEqual(
+             json.loads(keyring.get_password(Credentials.KEYRING_COOKIE, 'root')),
+             {"key": "value"}
+ 
+         )
+ 
+ 
+ 
Add test for credential persistence
## Code Before:
from pyutrack import Credentials
from tests import PyutrackTest


class CredentialsTests(PyutrackTest):
    def test_empty(self):
        c = Credentials('root')
        self.assertIsNone(c.password)
        self.assertIsNone(c.cookies)

## Instruction:
Add test for credential persistence
## Code After:
import json

import keyring

from pyutrack import Credentials
from tests import PyutrackTest


class CredentialsTests(PyutrackTest):
    def test_empty(self):
        c = Credentials('root')
        self.assertIsNone(c.password)
        self.assertIsNone(c.cookies)

    def test_persistence(self):
        c = Credentials('root', 'passwd', {"key": "value"})
        c.persist()
        self.assertEqual(
            keyring.get_password(Credentials.KEYRING_PASSWORD, 'root'), 'passwd'
        )
        self.assertEqual(
            json.loads(keyring.get_password(Credentials.KEYRING_COOKIE, 'root')),
            {"key": "value"}

        )


