Ejemplo n.º 1
0
 def test_missing_and_untracked_files(self):
     database = Database(TEST_LOG_PATH)
     documents = [{
         'name': 'first.txt',
         'type': 'txt',
         'path': 'first.txt'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'images/second.png'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'second.png'
     }]
     for document in documents:
         database.create_document(**document)
     storage = Storage(TEST_ROOT_PATH)
     storage_paths = {'first.txt', 'second.txt', 'third.txt'}
     for path in storage_paths:
         absolute_path = TEST_ROOT_PATH + path
         touch(absolute_path)
     repository = Repository(database, storage)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, {'second.txt', 'third.txt'})
     missing_files = repository.collect_missing_file_paths()
     self.assertEqual(missing_files, {'second.png', 'images/second.png'})
Ejemplo n.º 2
0
def create_sample_database():
    """
    Create a sample database for testing.
    :return: a `Context` object
    """
    database = Database(path=TEST_LOG_PATH)
    for document_id in range(1, 9):
        database.create_document(**sample_documents[document_id])
    for tag_id in range(1, 7):
        database.create_tag(name=sample_tags[tag_id])
    for relation in sample_relations:
        database.create_relation(document_id=relation[0], tag_id=relation[1])
    return database
Ejemplo n.º 3
0
 def test_missing_files(self):
     database = Database(TEST_LOG_PATH)
     storage = Storage(TEST_ROOT_PATH)
     documents = [{
         'name': 'first.txt',
         'type': 'txt',
         'path': 'first.txt'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'images/second.png'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'second.png'
     }]
     paths = {'first.txt', 'second.png', 'images/second.png'}
     for document in documents:
         database.create_document(**document)
     repository = Repository(database, storage)
     missing_file_paths = repository.collect_missing_file_paths()
     self.assertEqual(missing_file_paths, paths)
Ejemplo n.º 4
0
 def test_document_untracking(self):
     database = Database(TEST_LOG_PATH)
     documents = [{
         'name': 'first.txt',
         'type': 'txt',
         'path': 'first.txt'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'images/second.png'
     }, {
         'name': 'second.png',
         'type': 'png',
         'path': 'second.png'
     }]
     for document in documents:
         database.create_document(**document)
     storage = Storage(TEST_ROOT_PATH)
     storage_paths = {'first.txt', 'images/second.png', 'second.png'}
     os.mkdir(TEST_ROOT_PATH + 'images')
     for path in storage_paths:
         absolute_path = TEST_ROOT_PATH + path
         touch(absolute_path)
     repository = Repository(database, storage)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, set())
     repository.untrack_document(3)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, {'second.png'})
     repository.untrack_document(1)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files, {'first.txt', 'second.png'})
     repository.untrack_document(2)
     untracked_files = repository.collect_untracked_file_paths()
     self.assertEqual(untracked_files,
                      {'first.txt', 'images/second.png', 'second.png'})