Пример #1
0
 def test_init_site_with_initial_is_under_real_base_should_set_tree_ready_to_true(
         self):
     s = s2site.Site(self.www_dir)
     self.assertTrue(
         s.tree_ready,
         "tree_ready is NOT True after initialization with a dir that is under a real base dir."
     )
Пример #2
0
 def test_inst_should_add_default_config(self):
     s = s2site.Site(self.temp_dir)
     s.init_structure()
     sfs = glob.glob(os.path.join(s.dirs['base'], "*"))
     sfs = [os.path.split(p)[1] for p in sfs]
     self.assertTrue('config.yml' in sfs,
                     "init_structure did not create the config file.")
Пример #3
0
 def test_init_site_without_params_should_set_tree_ready_to_false_when_called_from_non_s2dir(
         self):
     s = s2site.Site()
     self.assertFalse(
         s.tree_ready,
         "tree_ready is False after initialization with no dir in non-s2 dir."
     )
Пример #4
0
 def test_init_site_with_initial_is_under_real_base_should_set_correct_dirs(
         self):
     s = s2site.Site(self.www_dir)
     self.assertTrue(s.dirs['base'] == self.base_dir and \
                     s.dirs['source'] == self.source_dir and \
                     s.dirs['www'] == self.www_dir and \
                     s.dirs['common'] == self.common_dir and \
                     s.dirs['s2'] == self.s2_dir,
         "One or more of the dirs set up after creating site are not correct.")
Пример #5
0
 def test_inst_should_copy_data_dirs(self):
     pdl = s2site.package_data_location()
     pddirlist = glob.glob(os.path.join(pdl, "*"))
     pddirset = set([os.path.split(d)[1] for d in pddirlist])
     s = s2site.Site(self.temp_dir)
     s.init_structure()
     strucfilelist = glob.glob(os.path.join(s.dirs['base'], "*"))
     strucfileset = set([os.path.split(d)[1] for d in strucfilelist])
     self.assertTrue(pddirset.issubset(strucfileset),
                     "init_structure did not copy the package data dirs.")
Пример #6
0
 def setUp(self):
     self.temp_dir = tempfile.mkdtemp()
     self.site = s2site.Site(self.temp_dir)
     self.site.init_structure()
     #first create a page
     self.p1title = "This is a new page"
     self.p1slug = util.make_slug(self.p1title)
     self.p1 = s2page.Page(self.site, self.p1title)
     content = util.random_text()
     self.p1.content = content
Пример #7
0
def make_site_obj(argdict):
    '''Instantiate and return the site. This will be used for all commands'''
    d = os.getcwd() #'.'
    if 'directory' in argdict:
        d = argdict['directory']
    try:
        s = s2site.Site(d)
    except:
        print "Could not instantiate site object."
        sys.exit()
    return s
Пример #8
0
 def test_inst_on_ok_path_should_not_create_extraneous_subdirs(self):
     s = s2site.Site(self.temp_dir)
     s.init_structure()
     allf = glob.glob(os.path.join(self.temp_dir, "*"))
     allf += glob.glob(os.path.join(self.temp_dir, ".*"))
     dirlist = [f for f in allf if os.path.isdir(f)]  #filter for dirs
     dirset = set([os.path.split(d)[1]
                   for d in dirlist])  #remove leading path
     expectedset = set(['www', '.s2', 'common', 'source', 'themes'])
     self.assertEqual(
         dirset.difference(expectedset), set([]),
         "init_structure created some extraneous subdirectories.")
Пример #9
0
 def test_do_add_should_create_page_in_source(self):
     # init site
     site = s2site.Site(self.temp_dir)
     site.init_structure()
     # add page
     title = 'This is the new page title'
     args = self.parser.parse_args(['add', title, '-d', self.temp_dir])
     argdict = vars(args)
     s2.dispatch(argdict)  #this triggers call to do_add
     # verify that the page is there
     self.assertTrue(site.page_exists_on_disk(util.make_slug(title)),
                     "page does not exist after add_page.")
Пример #10
0
def make_site_obj(argdict):
    '''Instantiate and return the site. This will be used for all commands'''
    #d = '.'
    d = None
    if 'dirname' in argdict:
        d = argdict['dirname']
    try:
        s = s2site.Site(d)
    except Exception:  # pragma: no cover
        print "Could not instantiate site object."
        sys.exit()
    return s
Пример #11
0
 def test_inst_on_ok_path_should_create_all_subdirs(self):
     s = s2site.Site(self.temp_dir)
     s.init_structure()
     allf = glob.glob(os.path.join(self.temp_dir, "*"))
     allf += glob.glob(os.path.join(self.temp_dir, ".*"))
     dirlist = [f for f in allf if os.path.isdir(f)]  #filter for dirs
     dirlist = [os.path.split(d)[1] for d in dirlist]  #remove leading path
     self.assertTrue( 'www' in dirlist and \
                      '.s2' in dirlist and \
                      'common' in dirlist and \
                      'source' in dirlist ,
                       "init_structure did not create all the necessary subdirectories.")
Пример #12
0
 def setUp(self):
     # create fake tempdir with the structure
     self.temp_dir = tempfile.mkdtemp()
     self.site = s2site.Site(self.temp_dir)
     self.site.init_structure()
     self.ntg = random.randint(8, 100)
     self.gpi = []
     for i in range(0, self.ntg):
         title = util.random_title()
         self.gpi.append({
             'slug': util.make_slug(title),
             'title': title,
             'date': util.random_date()
         })
     self.epp = random.randint(5, self.ntg)
     self.correctnumpag = math.ceil(float(self.ntg) / self.epp)
Пример #13
0
 def setUp(self):
     # create fake tempdir with the structure
     self.temp_dir = tempfile.mkdtemp()
     self.s2 = s2site.Site(self.temp_dir)
     self.s2.init_structure()
     # create a bunch of fake pages
     pgs = []
     for i in range(0, 11):
         pg = util.make_slug(util.random_title())
         pgs.append(pg)
         pgfp = os.path.join(self.s2.dirs['source'], pg)
         os.mkdir(pgfp)
         fname = os.path.join(pgfp, pg) + '.s2md'
         fout = open(fname, 'w')
         fout.close()
     self.pages = pgs
Пример #14
0
 def test_do_rename_should_create_new_pagedir_in_source(self):
     # init site
     site = s2site.Site(self.temp_dir)
     site.init_structure()
     # add random page
     p = site.random_page()
     newtitle = "This will be the new title of the page."
     args = self.parser.parse_args(
         ['rename', p.slug, newtitle, '-d', self.temp_dir])
     argdict = vars(args)
     s2.dispatch(argdict)  #this triggers call to do_rename
     # verify that the page is there
     self.assertTrue(site.page_exists_on_disk(util.make_slug(newtitle)),
                     "new page directory does not exist after rename.")
     # and that the old page is not there.
     #Maybe it's a little unorthodox to do another assert in the same test... but it's for brevity
     self.assertFalse(site.page_exists_on_disk(p.slug),
                      "old page still exists after rename.")
Пример #15
0
 def test_do_generate_should_create_directory_in_www(self):
     # init site
     site = s2site.Site(self.temp_dir)
     site.init_structure()
     # generate a random number of random pages
     slugs = []
     for i in range(0, random.randrange(11, 31)):
         p = site.random_page()
         p.set_published()
         p.write()
         slugs.append(p.slug)
     args = self.parser.parse_args(['gen', '-d', self.temp_dir])
     argdict = vars(args)
     s2.dispatch(argdict)  #this triggers call to generate
     # verify that the directories for the pages are there
     wlist = glob.glob(os.path.join(site.dirs['www'], "*"))
     wlist = [f for f in wlist if os.path.isdir(f)]
     wlist = [os.path.split(f)[1] for f in wlist]
     wset = set(wlist)
     slugset = set(slugs)
     self.assertTrue(
         slugset.issubset(wset),
         "after site generation, the addition of directories to www was not correct."
     )
Пример #16
0
 def setUp(self):
     # create fake tempdir with the structure
     self.temp_dir = tempfile.mkdtemp()
     self.s2 = s2site.Site(self.temp_dir)
     self.s2.init_structure()
Пример #17
0
 def setUp(self):
     self.temp_dir = tempfile.mkdtemp()
     self.site = s2site.Site(self.temp_dir)
     self.site.init_structure()
Пример #18
0
 def test_inst_on_nonwritable_path_should_raise_valueError(self):
     # make temp_dir nonwritable
     set_directory_writability(self.temp_dir, writable=False)
     s = s2site.Site(self.temp_dir)
     self.assertRaises(ValueError, s.init_structure)
Пример #19
0
 def test_inst_on_nonempty_path_should_raise_valueError(self):
     #put something in the temp_dir
     fout = open(os.path.join(self.temp_dir, 'afile'), 'w')
     fout.close()
     s = s2site.Site(self.temp_dir)
     self.assertRaises(ValueError, s.init_structure)
Пример #20
0
 def test_init_site_without_params_should_set_run_dir_to_CWD(self):
     s = s2site.Site()
     self.assertEqual(
         s.dirs['run'], os.getcwd(),
         "run dir is not set to CWD after initialization with no dir.")