Esempio n. 1
0
class ModelsTest(TestCase):

    def repeat(func, repeat=10, *args, **kwargs):
        def wrapper(*args, **kwargs):
            for i in range(0, repeat):
                func(*args, **kwargs)
        return wrapper

    def setUp(self):
        self.fs = FsUrlModel()
        self.graph = FolderPoint(self.fs.root, depth=4)

    def test_init_mixin(self):
        def test(kwargs):
            instance = TestClass(**kwargs)
            self.assertDictEqual(origin, instance.to_dict())

        class TestClass(InitMixin):
            simpleAttr = None
            complicityAttr = None

            def to_dict(self):
                return dict(simpleAttr=self.simpleAttr,
                            complicityAttr=self.complicityAttr)

        origin = dict(simpleAttr='Простой', complicityAttr='Сложный')

        kwargs = dict(simpleAttr='Простой', complicityAttr='Сложный')
        test(kwargs)

        kwargs.update({'extra': 'extra'})
        test(kwargs)


    @repeat
    def test_moving(self):
        folder = self.graph.deep()
        self.fs.into(folder.diff())
        self.assertEqual(self.fs.cwd, folder.path)
        print "cd %s and ls : %s" % (self.fs.cwd, folder.path)
        self.fs.to_root()

    @repeat
    def test_back(self):
        folder = self.graph.deep()
        self.fs.into(folder.diff())
        self.fs.back()
        self.assertEqual(self.fs.cwd, folder.parent.path)
        print "cd %s and back , pwd -> %s , actual -> %s" %\
              (folder.diff(), self.fs.cwd, folder.parent.path)
        self.fs.to_root()

    @repeat
    def test_back_path(self):
        folder = self.graph.deep()
        self.fs.into(folder.diff())
        back_path = "/".join(self.fs.back_path)
        self.assertEqual(back_path, folder.diff())
        self.fs.to_root()

    @repeat
    def test_files(self):
        folder = self.graph.deep()
        self.fs.into(folder.diff())
        self.assertListEqual(self.fs.files, folder.files)
        print "cd %s files : %s" % (folder.diff(), self.fs.files_url)
        self.fs.to_root()

    @repeat
    def test_dir_url(self):
        folder = self.graph.deep()
        self.fs.into(folder.diff())
        self.assertNotEqual(self.fs.dir_url, None)
        print "cd %s foldes : %s" % (folder.diff(), self.fs.files_url)
        self.fs.to_root()

    @repeat
    def test_files_url(self):
        folder = self.graph.deep()
        self.fs.into(folder.diff())
        self.assertNotEqual(self.fs.files_url, None)
        print "cd %s files : %s" % (folder.diff(), self.fs.files_url)
        self.fs.to_root()
Esempio n. 2
0
 def setUp(self):
     self.fs = FsUrlModel()
     self.graph = FolderPoint(self.fs.root, depth=4)