"Fossies" - the Fresh Open Source Software Archive

Member "buku-4.3/tests/test_BukuCrypt.py" (31 Jan 2020, 1032 Bytes) of package /linux/privat/buku-4.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 """test module."""
    2 from unittest import mock
    3 import os
    4 
    5 import pytest
    6 
    7 
    8 def test_get_filehash(tmpdir):
    9     """test method."""
   10     exp_res = b'\x9f\x86\xd0\x81\x88L}e\x9a/\xea\xa0\xc5Z\xd0\x15\xa3\xbfO\x1b+\x0b\x82,\xd1]l\x15\xb0\xf0\n\x08'  # NOQA
   11     test_file = os.path.join(tmpdir.strpath, 'my_test_file.txt')
   12     with open(test_file, 'w') as f:
   13         f.write('test')
   14     from buku import BukuCrypt
   15     res = BukuCrypt.get_filehash(test_file)
   16     assert res == exp_res
   17 
   18 
   19 def touch(fname):
   20     """touch implementation for python."""
   21     if os.path.exists(fname):
   22         os.utime(fname, None)
   23     else:
   24         open(fname, 'a').close()
   25 
   26 
   27 def test_encrypt_decrypt(tmpdir):
   28     """test method."""
   29     dbfile = os.path.join(tmpdir.strpath, 'test_encrypt_decrypt_dbfile')
   30     touch(dbfile)
   31     with mock.patch('getpass.getpass', return_value='password'):
   32         from buku import BukuCrypt
   33         with pytest.raises(SystemExit):
   34             BukuCrypt.encrypt_file(1, dbfile=dbfile)
   35         BukuCrypt.decrypt_file(1, dbfile=dbfile)