<s> from collections import namedtuple <EOL> import os <EOL> import shutil <EOL> import sys <EOL> import tempfile <EOL> import yaml <EOL> from passpie . importers import find_importer , BaseImporter , get_instances <EOL> from passpie . importers . default_importer import DefaultImporter <EOL> from passpie . importers . pysswords_importer import PysswordsImporter <EOL> def mock_open ( ) : <EOL> try : <EOL> from mock import mock_open as mopen <EOL> except : <EOL> from unittest . mock import mock_open as mopen <EOL> return mopen ( ) <EOL> def test_pysswords_returns_false_with_logging_when_not_installed ( mocker ) : <EOL> to_patch = '<STR_LIT>' <EOL> mocker . patch ( to_patch , return_value = False ) <EOL> importer = PysswordsImporter ( ) <EOL> importer . log = mocker . Mock ( ) <EOL> result = importer . match ( '<STR_LIT>' ) <EOL> assert result is False <EOL> assert importer . log . called <EOL> importer . log . assert_called_once_with ( '<STR_LIT>' ) <EOL> def test_pysswords_returns_false_with_logging_when_path_not_dir ( mocker ) : <EOL> to_patch = '<STR_LIT>' <EOL> mocker . patch ( to_patch , return_value = True ) <EOL> mock_os = mocker . patch ( '<STR_LIT>' ) <EOL> mock_os . path . is_dir . return_value = False <EOL> importer = PysswordsImporter ( ) <EOL> importer . log = mocker . Mock ( ) <EOL> result = importer . match ( '<STR_LIT>' ) <EOL> assert result is False <EOL> assert importer . log . called <EOL> importer . log . assert_called_once_with ( '<STR_LIT>' ) <EOL> def test_pysswords_returns_false_with_logging_when_keys_not_in_path ( mocker ) : <EOL> to_patch = '<STR_LIT>' <EOL> mocker . patch ( to_patch , return_value = True ) <EOL> mock_os = mocker . patch ( '<STR_LIT>' ) <EOL> mock_os . path . is_dir . return_value = True <EOL> mock_os . listdir . return_value = [ ] <EOL> importer = PysswordsImporter ( ) <EOL> importer . log = mocker . Mock ( ) <EOL> result = importer . match ( '<STR_LIT>' ) <EOL> assert result is False <EOL> assert importer . log . called <EOL> importer . log . assert_called_once_with ( '<STR_LIT>' ) <EOL> def test_pysswords_match_returns_true_when_expected_path ( mocker ) : <EOL> to_patch = '<STR_LIT>' <EOL> mocker . patch ( to_patch , return_value = True ) <EOL> mock_os = mocker . patch ( '<STR_LIT>' ) <EOL> mock_os . path . is_dir . return_value = True <EOL> mock_os . listdir . return_value = [ '<STR_LIT>' ] <EOL> importer = PysswordsImporter ( ) <EOL> result = importer . match ( '<STR_LIT>' ) <EOL> assert result is True <EOL> def test_pysswords_handle_returns_empty_when_bad_passphrase ( mocker ) : <EOL> mocker . patch ( '<STR_LIT>' ) <EOL> to_patch = '<STR_LIT>' <EOL> mock_pysswords_db = mocker . patch ( to_patch , create = True ) ( ) <EOL> mock_pysswords_db . check . return_value = False <EOL> importer = PysswordsImporter ( ) <EOL> result = importer . handle ( '<STR_LIT:path>' ) <EOL> assert result == [ ] <EOL> def test_pysswords_handle_returns_pysswords_credentials ( mocker ) : <EOL> Cred = namedtuple ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> credentials = [ <EOL> Cred ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' ) <EOL> ] <EOL> mocker . patch ( '<STR_LIT>' ) <EOL> mocker . patch ( '<STR_LIT>' ) <EOL> to_patch = '<STR_LIT>' <EOL> mock_pysswords_db = mocker . patch ( to_patch , create = True ) ( ) <EOL> mock_pysswords_db . check . return_value = True <EOL> mock_pysswords_db . credentials = credentials <EOL> importer = PysswordsImporter ( ) <EOL> result = importer . handle ( '<STR_LIT:path>' ) <EOL> assert credentials [ <NUM_LIT:0> ] . name in [ c [ '<STR_LIT:name>' ] for c in result ] </s>
