'''
test.backend.svrtools.crypto.__init__

'''

import unittest

from my.backend import Backend
# from my.backend.crypto import is_this_the_correct_dollhouse_password
from my.globals.exceptions import WrongDollhousePasswordError
from my.miscellany import random_alphanum_string


class Test_is_this_the_correct_dollhouse_password(unittest.TestCase):
    '''
    Test the supplied password. If it's the right one to decrypt the dollhouse key, return True; else, False.

    Inputs:
        pw            string; if we are using DMCRYPT, use 'pw' to try to decrypt the key
                      and check to see if the password is the right onw. If we are using
                      ECRYPTFS, this function is not used because ECRYPTFS (in our usage)
                      does not use an external keyfile but uses a password instead.

    Outputs:
        True/False    is password valid?
    '''

    def setUp(self):
        Backend.dollhouse.close()

    def 
(self):
        Backend.dollhouse.close()

#     def test_is_this_the_correct_dollhouse_password(self):
#         '''
#         Test is_this_the_correct_dollhouse_password() with a known-good password
#         and then with a known-bad password
#         '''
#         for pw in (random_alphanum_string(20), '12345678', random_alphanum_string(10), '12345678'):
#             Backend.dollhouse.open(pw=pw, wipe=True)
#             self.assertTrue(Backend.dollhouse.is_open)
#             Backend.dollhouse.close()
#             self.assertTrue(is_this_the_correct_dollhouse_password(pw))
#             self.assertFalse(Backend.dollhouse.is_open)
#             self.assertFalse(is_this_the_correct_dollhouse_password('nahh' + pw + 'unhunh'))

    def test_data_persistence(self):
        '''
        Test the mounted dollhouse's ability to retain information in between dismounts/mounts.
        '''
        for pw in (random_alphanum_string(20), '12345678', random_alphanum_string(10), '12345678'):
            Backend.dollhouse.open(pw=pw, wipe=True)
            teststring = random_alphanum_string(30)
            with open('/.home_rw/hi.txt', 'w') as f:
                f.write(teststring)
            Backend.dollhouse.close()
            Backend.dollhouse.open(pw=pw)
            with open('/.home_rw/hi.txt', 'r') as f:
                whatwassaved = f.read()
            self.assertEqual(teststring, whatwassaved)
            Backend.dollhouse.close()
            try:
                Backend.dollhouse.open(teststring)
                raise Exception('We should not be able to unlock with wrong password')
            except WrongDollhousePasswordError:
                pass
            self.assertTrue(Backend.dollhouse.is_open)
            Backend.dollhouse.close()
            self.assertFalse(Backend.dollhouse.is_open)


if __name__ == "__main__":
    # import sys;sys.argv = ['', 'Test.testName']
    unittest.main()

if __name__ == "__main__":
    unittest.main()

tearDown