Changeset 744:3a967f693570 in hatta-dev for tests/test_repo.py


Ignore:
Timestamp:
01/24/10 15:19:13 (2 years ago)
Author:
sheep@…
Branch:
default
Message:

implemet the subdirectory storage, more tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/test_repo.py

    r741 r744  
    6868    comment = u'test comment' 
    6969 
    70     @py.test.mark.xfail 
    71     def test_filename(self, repo): 
     70    title_encodings = { 
     71        u'test title': 'test title', 
     72        u'.test title': '%2Etest title', 
     73        u'../test title': '%2E./test title', 
     74        u'test/./title': 'test/%2E/title', 
     75        u'test/../title': 'test/%2E./title', 
     76        u'test//title': 'test/%2Ftitle', 
     77        u'/test/title': '%2Ftest/title', 
     78    } 
     79 
     80 
     81    def test_title_to_file(self, subdir_repo): 
     82        for title, filename in self.title_encodings.iteritems(): 
     83            escaped = subdir_repo._title_to_file(title) 
     84            assert escaped == filename 
     85 
     86    def test_filename(self, subdir_repo): 
    7287        """ 
    7388        Check if the page's file is named properly. 
    7489        """ 
    7590 
    76         title = u'some/page.txt' 
    77         filename = 'some/page.txt' 
    78         filepath = os.path.join(repo.path, filename) 
    79         repo.save_text(title, self.text, self.author, self.comment, parent=-1) 
    80         exists = os.path.exists(filepath) 
    81         assert exists 
    82  
    83     # XXX Put your tests here. 
     91        for title, filename in self.title_encodings.iteritems(): 
     92            filepath = os.path.join(subdir_repo.path, filename) 
     93            subdir_repo.save_text(title, self.text, self.author, self.comment, 
     94                                  parent=-1) 
     95            exists = os.path.exists(filepath) 
     96            assert exists 
     97 
    8498 
    8599class TestMercurialStorage(object): 
     
    105119        exists = os.path.exists(filepath) 
    106120        assert exists 
     121 
     122    def test_check_path(self, repo): 
     123        py.test.raises(werkzeug.exceptions.Forbidden, repo._check_path, "/") 
     124        py.test.raises(werkzeug.exceptions.Forbidden, repo._check_path, "..") 
     125        py.test.raises(werkzeug.exceptions.Forbidden, repo._check_path, 
     126                       repo.path+"/..") 
     127        path = os.path.join(repo.path, 'aaa') 
     128        os.symlink('/', path) 
     129        py.test.raises(werkzeug.exceptions.Forbidden, repo._check_path, path) 
     130        path = os.path.join(repo.path, 'bbb') 
     131        os.mkdir(path) 
     132        py.test.raises(werkzeug.exceptions.Forbidden, repo._check_path, path) 
    107133 
    108134    @py.test.mark.skipif("sys.platform == 'win32'") 
Note: See TracChangeset for help on using the changeset viewer.