def test_find_note(self): ''' Make a note and find it again. ''' # Make a note TestFileStuff.clean_directory() file_path, _ = brain.create_new_note(TEST_TOPIC, 'note') # Did we make a note? file_count = os.listdir(TEST_DATA_DIRECTORY) self.assertEqual(len(file_count), 1, msg='os.listdir') # Tag it for retrieval brain.add_tags_to_file(TEST_TAGS_IN, file_path) # Can we find the note? args = { 'keyword_string': ' '.join(TEST_TAGS_IN), 'archives': False, 'full_text': True, } match_files = brain.get_keyword_files(**args) self.assertEqual(len(match_files), 1, msg='get_keyword_files') # Can we remove the tags? brain.remove_tags_from_file(TEST_TAGS_IN, file_path) # This time we should not find it. match_files = brain.get_keyword_files(**args) self.assertEqual(len(match_files), 0, 'get_keyword_files find 0')
def test_find_note(self): ''' Make a note and find it again. ''' # Make a note TestFileStuff.clean_directory() file_path, _ = brain.create_new_note(TEST_TOPIC, 'note') # Did we make a note? file_count = os.listdir(TEST_DATA_DIRECTORY) self.assertEqual(len(file_count), 1, msg='os.listdir') # Tag it for retrieval brain.add_tags_to_file(TEST_TAGS_IN, file_path) # Can we find the note? args = { 'keyword_string': ' '.join(TEST_TAGS_IN), 'archives': False, 'full_text': True, } match_files = brain.get_keyword_files(**args) self.assertEqual(len(match_files), 1, msg='get_keyword_files') # Can we remove the tags? brain.remove_tags_from_file(TEST_TAGS_IN, file_path) # This time we should not find it. match_files = brain.get_keyword_files(**args) self.assertEqual(len(match_files), 0, 'get_keyword_files find 0')
def test_create_new_note(self): TestFileStuff.clean_directory() file_path, _ = brain.create_new_note(TEST_TOPIC, note_template='note') file_count = os.listdir(TEST_DATA_DIRECTORY) self.assertEqual(len(file_count), 1) self.assertEqual(file_path, TEST_FILE_PATH) content = brain.get_file_content(TEST_FILE_PATH) self.assertTrue(TEST_FILE_INITIAL_CONTENT in content)
def test_create_new_note(self): TestFileStuff.clean_directory() file_path, _ = brain.create_new_note(TEST_TOPIC, note_template='note') file_count = os.listdir(TEST_DATA_DIRECTORY) self.assertEqual(len(file_count), 1) self.assertEqual(file_path, TEST_FILE_PATH) content = brain.get_file_content(TEST_FILE_PATH) self.assertTrue(TEST_FILE_INITIAL_CONTENT in content)
def test_list_recent_with_recent_file(self): # Arrange TestFileStuff.clean_directory() recent_file_path, _ = brain.create_new_note(TEST_TOPIC, 'note') expected = dict() expected[datetime.today().date()] = [recent_file_path] # Act match_files = brain.find_files(filter=[], days=1) actual = brain.list_recent(match_files) # Assert self.assertEqual(expected, actual)
def test_list_recent_with_recent_file(self): # Arrange TestFileStuff.clean_directory() recent_file_path, _ = brain.create_new_note(TEST_TOPIC, 'note') expected = dict() expected[datetime.today().date()] = [recent_file_path] # Act match_files = brain.find_files(filter=[], days=1) actual = brain.list_recent(match_files) # Assert self.assertEqual(expected, actual)
def test_strays(self): ''' Run the strays method. ''' # Arrange TestFileStuff.clean_directory() # Since we didn't tag it, it is considered 'stray' _, _ = brain.create_new_note(TEST_TOPIC, note_template='note') # Act results = brain.list_stray_files() # Assert self.assertEqual(len(results), 1)
def test_strays(self): ''' Run the strays method. ''' # Arrange TestFileStuff.clean_directory() # Since we didn't tag it, it is considered 'stray' _, _ = brain.create_new_note(TEST_TOPIC, note_template='note') # Act results = brain.list_stray_files() # Assert self.assertEqual(len(results), 1)
def test_list_recent_with_old_file(self): if not sys.platform == 'darwin': # Arrange TestFileStuff.clean_directory() recent_file_path, _ = brain.create_new_note(TEST_TOPIC, 'note') old_date = 2014-04-01 os.utime(recent_file_path, (old_date, old_date)) expected = dict() # Act match_files = brain.find_files(filter=[], days=1) actual = brain.list_recent(match_files) # Assert self.assertEqual(expected, actual)
def test_list_recent_with_old_file(self): if not sys.platform == 'darwin': # Arrange TestFileStuff.clean_directory() recent_file_path, _ = brain.create_new_note(TEST_TOPIC, 'note') old_date = 2014 - 04 - 01 os.utime(recent_file_path, (old_date, old_date)) expected = dict() # Act match_files = brain.find_files(filter=[], days=1) actual = brain.list_recent(match_files) # Assert self.assertEqual(expected, actual)
def test_create_new_note_with_mildly_complex_filename_template(self): # Arrange TestFileStuff.clean_directory() topic = 'test note 348' today_date = date.today() expected_filename = today_date.isoformat() + '-test-note-348.txt' expected_line = 4 # Act (actual_filename, actual_line) = brain.create_new_note( topic, notes_dir=TEST_DATA_DIRECTORY, filename_template='{today}-{topic}') # Assert self.assertEqual(TEST_DATA_DIRECTORY + '/' + expected_filename, actual_filename) self.assertEqual(expected_line, actual_line) files = os.listdir(TEST_DATA_DIRECTORY) self.assertEqual(expected_filename, files[0])
def test_create_new_note_with_default_template_and_filename(self): # Arrange TestFileStuff.clean_directory() topic = 'test note 347' expected_filename = 'test-note-347.txt' expected_line = 4 # Act (actual_filename, actual_line) = brain.create_new_note( topic, notes_dir=TEST_DATA_DIRECTORY) # Assert # assert on return values self.assertEqual(TEST_DATA_DIRECTORY + '/' + expected_filename, actual_filename) self.assertEqual(expected_line, actual_line) # assert the file was successfully created files = os.listdir(TEST_DATA_DIRECTORY) self.assertEqual(expected_filename, files[0])
def test_create_new_note_with_mildly_complex_filename_template(self): # Arrange TestFileStuff.clean_directory() topic = 'test note 348' today_date = date.today() expected_filename = today_date.isoformat() + '-test-note-348.txt' expected_line = 4 # Act (actual_filename, actual_line) = brain.create_new_note( topic, notes_dir=TEST_DATA_DIRECTORY, filename_template='{today}-{topic}') # Assert self.assertEqual(TEST_DATA_DIRECTORY + '/' + expected_filename, actual_filename) self.assertEqual(expected_line, actual_line) files = os.listdir(TEST_DATA_DIRECTORY) self.assertEqual(expected_filename, files[0])
def test_create_new_note_with_default_template_and_filename(self): # Arrange TestFileStuff.clean_directory() topic = 'test note 347' expected_filename = 'test-note-347.txt' expected_line = 4 # Act (actual_filename, actual_line) = brain.create_new_note(topic, notes_dir=TEST_DATA_DIRECTORY) # Assert # assert on return values self.assertEqual(TEST_DATA_DIRECTORY + '/' + expected_filename, actual_filename) self.assertEqual(expected_line, actual_line) # assert the file was successfully created files = os.listdir(TEST_DATA_DIRECTORY) self.assertEqual(expected_filename, files[0])
def test_archive_note(self): ''' archive a note.''' # Make a note TestFileStuff.clean_directory() file_path, _ = brain.create_new_note(TEST_TOPIC, note_template='note') dir_contents = os.listdir(TEST_DATA_INBOX) # Inbox exists. self.assertEqual(len(dir_contents), 1, '1 in inbox') # Tag and find it. brain.add_tags_to_file(TEST_TAGS_IN, file_path) tags_found = brain.get_tags(file_path) for tag in TEST_TAGS_OUT: self.assertTrue(tag in tags_found, msg='Find tag ' + tag) args = { 'keyword_string': ' '.join(TEST_TAGS_IN), 'archives': False, 'full_text': True, } EXPECTED_MATCH = '/tmp/test_minion/inbox/This-is-a-test-topic.txt' match_files = brain.get_keyword_files(**args) self.assertEqual(len(match_files), 1, 'found file by tags') self.assertEqual(match_files, [EXPECTED_MATCH]) # Try finding it again, because it was the last modified file. match_file = brain.get_last_modified() self.assertEqual(match_file, EXPECTED_MATCH) # Archive it. brain.archive(file_path) # Is it gone (from tag find?) match_files = brain.get_keyword_files(**args) self.assertEqual(len(match_files), 0, 'archived, so cannot find')
def test_archive_note(self): ''' archive a note.''' # Make a note TestFileStuff.clean_directory() file_path, _ = brain.create_new_note(TEST_TOPIC, note_template='note') dir_contents = os.listdir(TEST_DATA_INBOX) # Inbox exists. self.assertEqual(len(dir_contents), 1, '1 in inbox') # Tag and find it. brain.add_tags_to_file(TEST_TAGS_IN, file_path) tags_found = brain.get_tags(file_path) for tag in TEST_TAGS_OUT: self.assertTrue(tag in tags_found, msg='Find tag ' + tag) args = { 'keyword_string': ' '.join(TEST_TAGS_IN), 'archives': False, 'full_text': True, } EXPECTED_MATCH = '/tmp/test_minion/inbox/This-is-a-test-topic.txt' match_files = brain.get_keyword_files(**args) self.assertEqual(len(match_files), 1, 'found file by tags') self.assertEqual(match_files, [EXPECTED_MATCH]) # Try finding it again, because it was the last modified file. match_file = brain.get_last_modified() self.assertEqual(match_file, EXPECTED_MATCH) # Archive it. brain.archive(file_path) # Is it gone (from tag find?) match_files = brain.get_keyword_files(**args) self.assertEqual(len(match_files), 0, 'archived, so cannot find')