Exemplo n.º 1
0
 def test_bad_write_permissions_file(self, tmpdir):
     test_file = os.path.join(tmpdir, 'filename')
     open(test_file, 'w+').close()
     os.chmod(test_file, 0o400)
     with pytest.raises(FileException) as excinfo:
         File(test_file, must_exist=True, writable=True)
     assert 'Cannot write' in str(excinfo.value)
Exemplo n.º 2
0
 def test_bad_permissions_file(self, tmpdir):
     test_file = os.path.join(tmpdir, 'filename')
     open(test_file, 'w+').close()
     os.chmod(test_file, 0000)
     with pytest.raises(FileException) as excinfo:
         File(test_file)
     assert 'Cannot open' in str(excinfo.value)
Exemplo n.º 3
0
 def test_bad_db_file(self, tmpdir):
     db_file_path = os.path.join(tmpdir, 'lambert.sqlite')
     with open(db_file_path, 'w+') as f:
         f.write('This is not a valid database file')
     db_file = File(db_file_path, writable=True)
     with pytest.raises(DatabaseException) as excinfo:
         Database(db_file)
     assert 'not correctly formatted' in str(excinfo.value)
Exemplo n.º 4
0
 def test_bad_permissions_directory(self, tmpdir):
     test_dir = os.path.join(tmpdir, 'dirname/')
     test_file = os.path.join(test_dir, 'filename')
     os.mkdir(test_dir)
     os.chmod(test_dir, 0000)
     with pytest.raises(FileException) as excinfo:
         File(test_file)
     assert 'Cannot create' in str(excinfo.value)
Exemplo n.º 5
0
 def test_good_db_file(self, tmpdir):
     db_file_path = os.path.join(tmpdir, 'lambert.sqlite')
     conn = sqlite3.connect(db_file_path)
     cursor = conn.cursor()
     cursor.execute((
         "CREATE TABLE backups"
         "(id INTEGER PRIMARY KEY ASC, directory TEXT, archive_id TEXT,"
         "vault TEXT, location TEXT, encrypted TEXT, multi_part INTEGER, size INTEGER,"
         "deleted INTEGER, date TEXT);"))
     db_file = File(db_file_path, writable=True)
     database = Database(db_file)
     assert type(database) == Database
Exemplo n.º 6
0
 def test_bad_db_schema(self, tmpdir):
     db_file_path = os.path.join(tmpdir, 'lambert.sqlite')
     conn = sqlite3.connect(db_file_path)
     cursor = conn.cursor()
     cursor.execute((
         "CREATE TABLE backups"
         "(id INTEGER PRIMARY KEY ASC, directory TEXT, archive_id TEXT,"
         "vault TEXT, location TEXT, encrypted TEXT, multi_part INTEGER, size INTEGER,"
         "deleted INTEGER, date INTEGER);"))
     db_file = File(db_file_path, writable=True)
     with pytest.raises(DatabaseException) as excinfo:
         Database(db_file)
     assert 'incorrect schema' in str(excinfo.value)
Exemplo n.º 7
0
 def test_delete_backup(self, tmpdir):
     data = {
         'directory': '/path/to/directory',
         'archive_id': 'VsjYaAN5LPMg7D1jITg',
         'vault': 'vault_name',
         'location': '/glacier/archive/location',
         'encrypted': '',
         'multi_part': 0,
         'size': 10000,
         'deleted': 0
     }
     database = Database(File(os.path.join(tmpdir, 'lambert.sqlite')))
     database.write_entry(data)
     database.delete_backup(data['archive_id'])
     results = database.get_backups('/path/to/directory')
     assert len(results) == 0
Exemplo n.º 8
0
 def test_write_db_entry(self, tmpdir):
     data = {
         'directory': '/path/to/directory',
         'archive_id': 'VsjYaAN5LPMg7D1jITg',
         'vault': 'vault_name',
         'location': '/glacier/archive/location',
         'encrypted': '',
         'multi_part': 0,
         'size': 10000,
         'deleted': 0
     }
     database = Database(File(os.path.join(tmpdir, 'lambert.sqlite')))
     database.write_entry(data)
     db_file = database.file.path
     conn = sqlite3.connect(db_file)
     cursor = conn.cursor()
     cursor.execute("SELECT * FROM backups")
     result = cursor.fetchone()
     for key, value in data.items():
         assert value in result
Exemplo n.º 9
0
 def test_get_backups(self, tmpdir):
     b1 = {
         'directory': '/path/to/directory',
         'archive_id': 'VsjYaAN5LPMg7D1jITg',
         'vault': 'vault_name',
         'location': '/glacier/archive/location',
         'encrypted': '',
         'multi_part': 0,
         'size': 10000,
         'deleted': 1
     }
     b2 = {
         'directory': '/path/to/directory',
         'archive_id': 'VsjYaAN5LPMg7D1jITg',
         'vault': 'vault_name',
         'location': '/glacier/archive/location',
         'encrypted': '',
         'multi_part': 0,
         'size': 10000,
         'deleted': 0
     }
     b3 = {
         'directory': '/path/to/directory',
         'archive_id': 'VsjYaAN5LPMg7D1jITg',
         'vault': 'vault_name',
         'location': '/glacier/archive/location',
         'encrypted': '',
         'multi_part': 0,
         'size': 10000,
         'deleted': 0
     }
     database = Database(File(os.path.join(tmpdir, 'lambert.sqlite')))
     database.write_entry(b1)
     database.write_entry(b2)
     database.write_entry(b3)
     results = database.get_backups('/path/to/directory')
     for key, value in b2.items():
         assert value in results[0]
     for key, value in b3.items():
         assert value in results[1]
Exemplo n.º 10
0
 def test_non_existant_directory(self, tmpdir):
     with pytest.raises(FileException) as excinfo:
         File(os.path.join(tmpdir, 'non-existant-directory/file'))
     assert 'invalid directory' in str(excinfo.value)
Exemplo n.º 11
0
 def test_write_existing_file(self, tmpdir):
     file_path = os.path.join(tmpdir, 'test_file')
     open(file_path, 'w+').close()
     os.chmod(file_path, 0o700)
     existing_file = File(file_path, must_exist=True, writable=True)
     assert existing_file.path == file_path
Exemplo n.º 12
0
 def test_create_file(self, tmpdir):
     file_path = os.path.join(tmpdir, 'test_file')
     new_file = File(file_path, must_exist=False)
     assert new_file.path == file_path
Exemplo n.º 13
0
 def test_non_existant_file(self, tmpdir):
     with pytest.raises(FileException) as excinfo:
         File(os.path.join(tmpdir, 'non-existant-file'), must_exist=True)
     assert 'Cannot locate' in str(excinfo.value)