def test_new():
    # def new(localfile, jottapath, JFS):
    _localfile = u'tests/requirements.txt'
    _jottapath = u'/Jotta/Archive/TEST/test_new_ascii_filename.txt'
    _new = jottacloud.new(_localfile, _jottapath, jfs)
    assert isinstance(_new, JFS.JFSFile)
    _new.delete()
    _localfile2 = u'tests/requirements.txt'
    _jottapath2 = u'/Jotta/Archive/TEST/test_new_blåbær_utf8_filename.txt'
    _new2 = jottacloud.new(_localfile2, _jottapath2, jfs)
    assert isinstance(_new2, JFS.JFSFile)
    assert _new2.path.endswith(_jottapath2)
    _new2.delete()
Example #2
0
def test_new():
    # def new(localfile, jottapath, JFS):
    _localfile = u'tests/requirements.txt'
    _jottapath = u'//Jotta/Archive/Test/test_new_ascii_filename.txt'
    _new = jottacloud.new(_localfile, _jottapath, jfs)
    assert isinstance(_new, JFS.JFSFile)
    _new.delete()
    _localfile2 = u'tests/requirements.txt'
    _jottapath2 = u'/Jotta/Archive/Test/test_new_blåbær_utf8_filename.txt'
    _new2 = jottacloud.new(_localfile2, u'/' + _jottapath2, jfs)
    assert isinstance(_new2, JFS.JFSFile)
    assert _new2.path.endswith(_jottapath2)
    _new2.delete()
Example #3
0
def test_delete():
    # def delete(jottapath, JFS):
    _localfile = u'tests/requirements.txt'
    _jottapath = u'//Jotta/Archive/Test/test_delete.txt'
    _new = jottacloud.new(_localfile, _jottapath, jfs)
    _del = _new.delete()
    assert _del.is_deleted() == True
Example #4
0
def test_is_file():
    # def is_file(jottapath, JFS):
    _localfile = u'tests/requirements.txt'
    _jottapath = u'//Jotta/Archive/Test/test_is_file.txt'
    _new = jottacloud.new(_localfile, _jottapath, jfs)
    assert jottacloud.is_file(_jottapath, jfs)
    _new.delete()
Example #5
0
    def _new(self, src_path, dry_run=False, remove_uploaded=False):
            'Code to upload'
            # are we getting a symbolic link?
            if os.path.islink(src_path):
                sourcefile = os.path.normpath(os.path.join(self.topdir, os.readlink(src_path)))
                if not os.path.exists(sourcefile): # broken symlink
                    log.error("broken symlink %s->%s", src_path, sourcefile)
                    raise IOError("broken symliknk %s->%s", src_path, sourcefile)
                jottapath = self.get_jottapath(src_path, filename=os.path.basename(sourcefile))
            elif os.path.splitext(src_path)[1].lower() == '.lnk':
                # windows .lnk
                sourcefile = os.path.normpath(readlnk(src_path))
                if not os.path.exists(sourcefile): # broken symlink
                    log.error("broken fat32lnk %s->%s", src_path, sourcefile)
                    raise IOError("broken fat32lnk %s->%s", src_path, sourcefile)
                jottapath = self.get_jottapath(src_path, filename=os.path.basename(sourcefile))
            else:
                sourcefile = src_path
                if not os.path.exists(sourcefile): # file not exis
                    log.error("file does not exist: %s", sourcefile)
                    raise IOError("file does not exist: %s", sourcefile)
                jottapath = self.get_jottapath(src_path)

            log.info('Uploading file %s to %s', sourcefile, jottapath)
            if not dry_run:
                if not jottacloud.new(sourcefile, jottapath, self.jfs):
                    log.error('Uploading file %s failed', sourcefile)
                    raise
            if remove_uploaded:
                log.info('Removing file after upload: %s', src_path)
                if not dry_run:
                    os.remove(src_path)
def test_is_file():
    # def is_file(jottapath, JFS):
    _localfile = u'tests/requirements.txt'
    _jottapath = u'/Jotta/Archive/TEST/test_is_file.txt'
    _new = jottacloud.new(_localfile, _jottapath, jfs)
    assert jottacloud.is_file(_jottapath, jfs)
    _new.delete()
def test_delete():
    # def delete(jottapath, JFS):
    _localfile = u'tests/requirements.txt'
    _jottapath = u'/Jotta/Archive/TEST/test_delete.txt'
    _new = jottacloud.new(_localfile, _jottapath, jfs)
    _del = _new.delete()
    assert _del.is_deleted() == True
def test_replace_if_changed(tmpdir):
    # def replace_if_changed(localfile, jottapath, JFS):
    # first test non-existing jottapath
    # it should raise a not found JFSNotFoundError
    _localfile = os.path.join('tests', 'requirements.txt')
    rndm = random.randint(0, 1000)
    with pytest.raises(JFS.JFSNotFoundError):
        assert jottacloud.replace_if_changed(_localfile,
                                             '/Jotta/Archive/test_replace_if_changed_nonexisting-%i.txt' % rndm,
                                             jfs)
    # now, put some data there and uplaod
    _localfile = tmpdir.join('test_replace_if_changed-%s.txt' % rndm)
    _localfile.write(1*TESTFILEDATA)
    _jottapath = u'/Jotta/Archive/TEST/test_replace_if_changed.txt'
    assert jottacloud.new(str(_localfile), _jottapath, jfs)
    # lastly, edit data, and see if it is automatically reuploaded
    newdata = 2*TESTFILEDATA
    _localfile.write(newdata)
    jottacloud.replace_if_changed(str(_localfile), _jottapath, jfs)
    cloudobj = jfs.getObject(_jottapath)
    assert cloudobj.read() == newdata
    _del = cloudobj.delete()
Example #9
0
def test_replace_if_changed(tmpdir):
    # def replace_if_changed(localfile, jottapath, JFS):
    # first test non-existing jottapath
    # it should raise a not found JFSNotFoundError
    _localfile = os.path.join('tests', 'requirements.txt')
    rndm = random.randint(0, 1000)
    with pytest.raises(JFS.JFSNotFoundError):
        assert jottacloud.replace_if_changed(
            _localfile,
            '//Jotta/Archive/test_replace_if_changed_nonexisting-%i.txt' %
            rndm, jfs)
    # now, put some data there and uplaod
    _localfile = tmpdir.join('test_replace_if_changed-%s.txt' % rndm)
    _localfile.write_binary(1 * TESTFILEDATA.encode('utf-8'))
    _jottapath = u'//Jotta/Archive/Test/test_replace_if_changed.txt'
    assert jottacloud.new(str(_localfile), _jottapath, jfs)
    # lastly, edit data, and see if it is automatically reuploaded
    newdata = 2 * TESTFILEDATA
    _localfile.write_binary(newdata.encode('utf-8'))
    jottacloud.replace_if_changed(str(_localfile), _jottapath, jfs)
    cloudobj = jfs.getObject(_jottapath)
    assert cloudobj.read().encode('utf-8') == _localfile.read_binary()
    _del = cloudobj.delete()