def test_rules_parsing(): ''' Test the rules file is properly read ''' with patch.multiple(mailer, os=DEFAULT, open=DEFAULT, json=DEFAULT, validate_rules=DEFAULT) as mocks: mocks['os'].path.exists.return_value = True mocks['os'].walk().__iter__\ .return_value = [('/', None, ['cantopen.json', 'invalid.json', 'valid.json'])] invalid_file = MagicMock() valid_file = MagicMock() mocks['open'].side_effect = [IOError, invalid_file, valid_file] doc = [{'notify': {'fields': []}}] mocks['json'].load.side_effect = [TypeError, doc] mocks['validate_rules'].return_value = doc res = mailer.parse_group_rules('config_file') # Assert that we checked for folder existence mocks['os'].path.exists.called_once_with('confile_file') # Check that validation was called for valid file mocks['validate_rules'].assert_called_once_with(doc) assert mocks['validate_rules'].call_count == 1 # Assert that we tried to open all 3 files assert mocks['open'].call_count == 3 # Assert that we tried to load 2 files only assert mocks['json'].load.call_count == 2 # Assert that we have proper return value assert res == doc
def test_rules_dont_exist(): ''' Test the rules file is read ''' with patch('mailer.os') as system_os: system_os.path.exists.return_value = False res = mailer.parse_group_rules('config_file') system_os.path.exists.called_once_with('confile_file')
def test_rules_dont_exist(): ''' Test the rules file is read ''' with patch('mailer.os') as system_os: system_os.path.exists.return_value = False res = mailer.parse_group_rules('config_file') system_os.path.exists.called_once_with('confile_file') assert res is None