Ejemplo n.º 1
0
 def test_folder_size(self):
     COMMON_SIZE = 1099776
     a = CourseFile('name', 'url', '1000')
     b = CourseFile('name', 'url', '10001')
     c = CourseFile('name', 'url', '10001')
     d = CourseFile('name', 'url', '10001')
     e = CourseFile('name', 'url', '10001')
     f = CourseFile('name', 'url', '10001')
     a.size = COMMON_SIZE
     b.size = COMMON_SIZE
     c.size = COMMON_SIZE
     d.size = COMMON_SIZE
     e.size = COMMON_SIZE
     f.size = COMMON_SIZE
     top = Folder('top', 'url')
     middle = Folder('middle', 'url')
     bottom = Folder('bottom', 'url')
     top.files.append(a)
     middle.files.append(b)
     middle.files.append(c)
     bottom.files.append(d)
     bottom.files.append(e)
     bottom.files.append(f)
     middle.folders.append(bottom)
     top.folders.append(middle)
     sizes = []
     assert sum(folder_total_size(top, sizes)) == COMMON_SIZE * 6
Ejemplo n.º 2
0
 def test_filenotonline(self):
     gmt1 = GMT1()
     online = Folder('online', 'fake')
     local = Folder('local', 'fake')
     a = CourseFile('a', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
     local.files.append(a)
     synclocalwithonline(local, online)
     assert local.files == []
Ejemplo n.º 3
0
    def test_existsonlyonline(self):
        online = Folder({'name': 'online', 'friendlyURL': 'fake'})
        local = Folder({'name': 'local', 'friendlyURL': 'fake'})
        a = CourseFile({'title': 'a', 'modifiedDate': 631152060000})

        online.files.append(a)
        synclocalwithonline(local, online)
        assert local.files == [a]
Ejemplo n.º 4
0
 def test_recursive_datenone(self):
     gmt1 = GMT1()
     top = '/a/fake/path'
     a = CourseFile('a', 'url', datetime(1991, 1, 1, 1, 1, tzinfo=gmt1))
     docs = Folder('root', 'fake')
     sub = Folder('sub', 'fake')
     sub.files.append(a)
     docs.folders.append(sub)
     assert need_syncing(docs, top, []) == [(a, os.path.join(top, 'sub'))]
Ejemplo n.º 5
0
 def test_recursive_datenone(self):
     gmt1 = GMT1()
     top = '/a/fake/path'
     a = CourseFile({'title': 'a', 'modifiedDate': 662688060000})
     docs = Folder({'name': 'root', 'friendlyURL': 'fake'})
     sub = Folder({'name': 'sub', 'friendlyURL': 'fake'})
     sub.files.append(a)
     docs.folders.append(sub)
     assert need_syncing(docs, top) == [(a, os.path.join(top, 'sub'))]
Ejemplo n.º 6
0
 def test_recursive_olddate(self):
     gmt1 = GMT1()
     top = '/a/fake/path'
     a = CourseFile({'title': 'a', 'modifiedDate': 662688060000})
     a.local_creation_time = datetime(1990, 1, 1, 1, 1, tzinfo=gmt1)
     docs = Folder({'name': 'root', 'friendlyURL': 'fake'})
     sub = Folder({'name': 'sub', 'friendlyURL': 'fake'})
     sub.files.append(a)
     docs.folders.append(sub)
     assert need_syncing(docs, top) == [(a, os.path.join(top, 'sub'))]
Ejemplo n.º 7
0
 def test_neweronline(self):
     gmt1 = GMT1()
     online = Folder('online', 'fake')
     local = Folder('local', 'fake')
     a = CourseFile('a', 'url', datetime(1991, 1, 1, 1, 1, tzinfo=gmt1))
     b = CourseFile('a', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
     online.files.append(a)
     local.files.append(b)
     synclocalwithonline(local, online)
     assert local.files[0].last_online_edit_time == \
         datetime(1991, 1, 1, 1, 1, tzinfo=gmt1)
Ejemplo n.º 8
0
    def test_foldernotonline(self):
        online = Folder({'name': 'online', 'friendlyURL': 'fake'})
        local = Folder({'name': 'local', 'friendlyURL': 'fake'})

        sub = Folder({'name': 'sub'})
        sub2 = Folder({'name': 'sub2'})
        local.folders.append(sub)
        local.folders.append(sub2)
        online.folders.append(sub)
        synclocalwithonline(local, online)
        assert local.folders == online.folders
Ejemplo n.º 9
0
    def test_recursive_newdate(self, tmpdir):
        gmt1 = GMT1()
        b = tmpdir.mkdir('sub').join('a')
        b.write('content')
        a = CourseFile({'title': 'a', 'modifiedDate': 631152060000})
        a.local_creation_time = datetime(1991, 1, 1, 1, 1, tzinfo=gmt1)
        docs = Folder({'name': 'root', 'friendlyURL': 'fake'})
        sub = Folder({'name': 'sub', 'friendlyURL': 'fake'})
        sub.files.append(a)
        docs.folders.append(sub)

        assert need_syncing(docs, str(tmpdir)) == []
Ejemplo n.º 10
0
    def test_neweronline(self):
        gmt1 = GMT1()
        online = Folder({'name': 'online', 'friendlyURL': 'fake'})
        local = Folder({'name': 'local', 'friendlyURL': 'fake'})
        a = CourseFile({'title': 'a', 'modifiedDate': 662688060000})
        b = CourseFile({'title': 'b', 'modifiedDate': 631152060000})

        online.files.append(a)
        local.files.append(b)
        synclocalwithonline(local, online)
        assert local.files[0].last_online_edit_time == \
            datetime(1991, 1, 1, 1, 1, tzinfo=gmt1)
Ejemplo n.º 11
0
 def test_recursive_filenamewithoutextension(self, tmpdir):
     gmt1 = GMT1()
     b = tmpdir.mkdir('sub').join('a.pdf')
     b.write('content')
     a = CourseFile('a', 'url', datetime(1991, 1, 1, 1, 1, tzinfo=gmt1))
     a.local_creation_time = datetime(1990, 1, 1, 1, 1, tzinfo=gmt1)
     docs = Folder('root', 'fake')
     sub = Folder('sub', 'fake')
     sub.files.append(a)
     docs.folders.append(sub)
     assert need_syncing(docs, str(tmpdir), []) == [(a, os.path.join(
         str(tmpdir), 'sub'))]
Ejemplo n.º 12
0
 def test_foldernotonline(self):
     gmt1 = GMT1()
     online = Folder('online', 'fake')
     local = Folder('local', 'fake')
     a = CourseFile('a', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
     sub = Folder('sub', 'fake')
     sub2 = Folder('sub2', 'fake')
     local.folders.append(sub)
     local.folders.append(sub2)
     online.folders.append(sub)
     synclocalwithonline(local, online)
     assert local.folders == online.folders
Ejemplo n.º 13
0
 def test_recursive_filenamewithoutextension(self, tmpdir):
     gmt1 = GMT1()
     b = tmpdir.mkdir('sub').join('a.pdf')
     b.write('content')
     a = CourseFile({'title': 'a', 'modifiedDate': 662688060000})
     a.local_creation_time = datetime(1990, 1, 1, 1, 1, tzinfo=gmt1)
     docs = Folder({'name': 'root', 'friendlyURL': 'fake'})
     sub = Folder({'name': 'sub', 'friendlyURL': 'fake'})
     sub.files.append(a)
     docs.folders.append(sub)
     assert need_syncing(docs, str(tmpdir)) == [
         (a, os.path.join(str(tmpdir), 'sub'))
     ]
Ejemplo n.º 14
0
 def test_recursive_foldernotonline(self):
     gmt1 = GMT1()
     online = Folder('online', 'fake')
     local = Folder('local', 'fake')
     a = CourseFile('a', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
     localsub = Folder('sub', 'fake')
     localsubsub = Folder('subsub', 'fake')
     localsubsub.files.append(a)
     onlinesub = Folder('sub', 'fake')
     localsub.folders.append(localsubsub)
     local.folders.append(localsub)
     online.folders.append(onlinesub)
     synclocalwithonline(local, online)
     assert local.folders[0].folders == []
Ejemplo n.º 15
0
    def test_recursive_foldernotonline(self):
        online = Folder({'name': 'online', 'friendlyURL': 'fake'})
        local = Folder({'name': 'local', 'friendlyURL': 'fake'})
        a = CourseFile({'title': 'a', 'modifiedDate': 631152060000})
        localsub = Folder({'name': 'sub'})
        localsubsub = Folder({'name': 'subsub'})
        localsubsub.files.append(a)
        onlinesub = Folder({'name': 'sub'})

        localsub.folders.append(localsubsub)
        local.folders.append(localsub)
        online.folders.append(onlinesub)
        synclocalwithonline(local, online)
        assert local.folders[0].folders == []
Ejemplo n.º 16
0
    def test_flat_datenone(self):
        top = '/a/fake/path'
        a = CourseFile({'title': 'a', 'modifiedDate': 662688060000})
        docs = Folder({'name': 'root', 'friendlyURL': 'fake'})
        docs.files.append(a)

        assert need_syncing(docs, top) == [(a, top)]
Ejemplo n.º 17
0
    def test_flat_datenone(self):
        gmt1 = GMT1()
        top = '/a/fake/path'
        a = CourseFile('a', 'url', datetime(1991, 1, 1, 1, 1, tzinfo=gmt1))
        docs = Folder('root', 'fake')
        docs.files.append(a)

        assert need_syncing(docs, top, []) == [(a, top)]
Ejemplo n.º 18
0
 def test_flat_nofileondisk(self, tmpdir):
     gmt1 = GMT1()
     b = tmpdir.join('b')
     b.write('content')
     a = CourseFile({'title': 'a', 'modifiedDate': 631152060000})
     a.local_creation_time = datetime(1991, 1, 1, 1, 1, tzinfo=gmt1)
     docs = Folder({'name': 'root', 'friendlyURL': 'fake'})
     docs.files.append(a)
     assert need_syncing(docs, str(tmpdir)) == [(a, str(tmpdir))]
Ejemplo n.º 19
0
 def test_flat_nofileondisk(self, tmpdir):
     gmt1 = GMT1()
     b = tmpdir.join('b')
     b.write('content')
     a = CourseFile('a.pdf', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
     a.local_creation_time = datetime(1991, 1, 1, 1, 1, tzinfo=gmt1)
     docs = Folder('root', 'fake')
     docs.files.append(a)
     assert need_syncing(docs, str(tmpdir), []) == [(a, str(tmpdir))]
Ejemplo n.º 20
0
    def test_recursiveexistsonlyonline(self):
        online = Folder({'name': 'online', 'friendlyURL': 'fake'})
        local = Folder({'name': 'local', 'friendlyURL': 'fake'})
        a = CourseFile({'title': 'a', 'modifiedDate': 631152060000})
        b = CourseFile({'title': 'b', 'modifiedDate': 631152060000})
        c = CourseFile({'title': 'c', 'modifiedDate': 631152060000})
        sub = Folder({'name': 'subfolder'})
        subsub = Folder({'name': 'subsubfolder'})

        online.files.append(a)
        sub.files.append(b)
        subsub.files.append(c)
        sub.folders.append(subsub)
        online.folders.append(sub)
        synclocalwithonline(local, online)
        assert local.files == [a]
        assert local.folders == [sub]
        assert local.folders[0].folders == [subsub]
        assert local.folders[0].files == [b]
        assert local.folders[0].folders[0].files == [c]
Ejemplo n.º 21
0
    def test_flat_newdate(self, tmpdir):
        """local date newer: should not update the file if the file exists"""
        gmt1 = GMT1()
        b = tmpdir.join('a')
        b.write('content')
        a = CourseFile('a', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
        a.local_creation_time = datetime(1991, 1, 1, 1, 1, tzinfo=gmt1)
        docs = Folder('root', 'fake')
        docs.files.append(a)

        assert need_syncing(docs, str(tmpdir), []) == []
Ejemplo n.º 22
0
 def test_recursiveexistsonlyonline(self):
     gmt1 = GMT1()
     online = Folder('online', 'fake')
     local = Folder('local', 'fake')
     a = CourseFile('a', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
     sub = Folder('subfolder', 'fake')
     subsub = Folder('subsubfolder', 'fake')
     b = CourseFile('b', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
     c = CourseFile('c', 'url', datetime(1990, 1, 1, 1, 1, tzinfo=gmt1))
     online.files.append(a)
     sub.files.append(b)
     subsub.files.append(c)
     sub.folders.append(subsub)
     online.folders.append(sub)
     synclocalwithonline(local, online)
     assert local.files == [a]
     assert local.folders == [sub]
     assert local.folders[0].folders == [subsub]
     assert local.folders[0].files == [b]
     assert local.folders[0].folders[0].files == [c]
Ejemplo n.º 23
0
    def test_flat_olddate(self):
        """local date older: should update the file (doesn't matter if file
        exists or not"""
        gmt1 = GMT1()
        top = '/a/fake/path'
        a = CourseFile('a', 'url', datetime(1991, 1, 1, 1, 1, tzinfo=gmt1))
        a.local_creation_time = datetime(1990, 1, 1, 1, 1, tzinfo=gmt1)
        docs = Folder('root', 'fake')
        docs.files.append(a)

        assert need_syncing(docs, top, []) == [(a, top)]
Ejemplo n.º 24
0
    def test_flat_olddate(self):
        """local date older: should update the file (doesn't matter if file
        exists or not"""
        gmt1 = GMT1()
        top = '/a/fake/path'
        a = CourseFile({'title': 'a', 'modifiedDate': 662688060000})
        a.local_creation_time = datetime(1990, 1, 1, 1, 1, tzinfo=gmt1)
        docs = Folder({'name': 'root', 'friendlyURL': 'fake'})
        docs.files.append(a)

        assert need_syncing(docs, top) == [(a, top)]
Ejemplo n.º 25
0
    def test_flat_newdate(self, tmpdir):
        """local date newer: should not update the file if the file exists"""
        gmt1 = GMT1()
        b = tmpdir.join('a')
        b.write('content')
        a = CourseFile({'title': 'a', 'modifiedDate': 631152060000})
        a.local_creation_time = datetime(1991, 1, 1, 1, 1, tzinfo=gmt1)
        docs = Folder({'name': 'root', 'friendlyURL': 'fake'})
        docs.files.append(a)

        assert need_syncing(docs, str(tmpdir)) == []
Ejemplo n.º 26
0
    def _update_time(self, folder, file, path_list):
        logger.debug(f'inside {folder.name}')
        for path in path_list:
            logger.debug(f'namegoto: {path}')
            folder_dict = {'name': path}
            fakefolder = Folder(folder_dict)
            logger.debug(f'contained folders:  {folder.folders}')
            ind = folder.folders.index(fakefolder)
            goto = folder.folders[ind]
            self._update_time(goto, file, path_list)

        if file in folder.files:
            ind = folder.files.index(file)
            thisfile = folder.files[ind]
            thisfile.local_creation_time = file.local_creation_time
Ejemplo n.º 27
0
 def _update_time(self, folder, file, path_list):
     print('inside ', folder.name)
     print('path_list: ', path_list)
     while len(path_list) > 0:
         namegoto = path_list.pop(0)
         print('namegoto: ', namegoto)
         # perché a volte è vuoto?
         if namegoto != "":
             fakefolder = Folder(namegoto, 'fake')
             print('contained folders: ', folder.folders)
             ind = folder.folders.index(fakefolder)
             goto = folder.folders[ind]
             self._update_time(goto, file, path_list)
     if file in folder.files:
         ind = folder.files.index(file)
         thisfile = folder.files[ind]
         thisfile.local_creation_time = file.local_creation_time
         self.dumpUser()
Ejemplo n.º 28
0
 def test_repr(self):
     a = Folder('name', 'fakeurl')
     assert repr(a) == "name folder"