示例#1
0
    def test_when_the_data_type_of_one_more_arg_is_incorrect(self):

        with self.assertRaises(TypeError):
            u.urlify(1, 2)

        with self.assertRaises(TypeError):
            u.urlify("hello world", "hi")
示例#2
0
    def test_when_the_input_string_is_empty(self):

        with self.assertRaises(ValueError):
            u.urlify("", 0)

        with self.assertRaises(ValueError):
            u.urlify(" ", 0)
示例#3
0
    def _update_or_create_item(self, **kwds):
        item_options_list = [
            'price', 'wholesale_price', 'quantity', 'barcode',
            'identifier', 'short_description', 'name', 'slug',
        ]
        item_options = {}
        for k, v in kwds.iteritems():
            if k in item_options_list:
                item_options[k] = v
        item_options['slug'] = urlify(kwds['name'])
        
        if kwds['identifier'] in self.data['item_by_identifier']:
            item = self.data['item_by_identifier'][kwds['identifier']]
            for k, v in item_options.iteritems():
                setattr(item, k, v)
            item.save()
 
            self.data['item_by_identifier'].update({item.identifier: item})
            logging.debug('[U] %s' % kwds['name'])
            # True if created
            return False
        else:
            item = Item(**item_options)
            item.save()

            tree_item = TreeItem(parent=kwds['parent'], content_object=item)
            tree_item.save()
            
            self.data['item_by_identifier'].update({item.identifier: item})
            logging.debug('[S] %s' % item.name)
            # True if created
            return True
示例#4
0
    def _get_or_create_section(self, name, parent):
        if name in self.data['section_by_name']:
            return self.data['section_by_name'][name].tree.get()
        else:
            section = Section(name=name, slug=urlify(name))
            section.save()

            section_tree_item = TreeItem(parent=parent, content_object=section)
            section_tree_item.save()

            self.data['section_by_name'].update({section.name: section})

            logging.debug('[S] === %s ===' % section)
            return section_tree_item
示例#5
0
    def _get_or_create_section(self, name, parent):
        if name in self.data['section_by_name']:
            return self.data['section_by_name'][name].tree.get()
        else:
            section = Section(
                name=name, slug = urlify(name)
            )
            section.save()

            section_tree_item  = TreeItem(parent=parent, content_object=section)
            section_tree_item.save()

            self.data['section_by_name'].update({section.name: section})
            
            logging.debug('[S] === %s ===' % section)
            return section_tree_item
示例#6
0
    def make_item(self, param_list):
        '''
        Makes a new item in catalog
        param_list = [identifier, quantity, '<section_name> <name>']
        '''
        options = {}
        options['identifier'] = param_list[0]
        options['quantity'] = param_list[1]
        options['wholesale_price'] = param_list[4]
        options['price'] = param_list[5]
        if len(param_list) == 7:
            options['barcode'] = param_list[6]
        else:
            options['barcode'] = None
        options['name'] = param_list[3].decode('cp1251').replace('""', '"')
        options['slug'] = urlify(options['name'])
        options['short_description'] = options['name'].split(' ').pop()
        section_name = param_list[2].decode('cp1251')
        section_tree_item = self._get_or_create_section(section_name, self.import_section)
        options['parent'] = section_tree_item

        return self._update_or_create_item(**options)
示例#7
0
    def _update_or_create_item(self, **kwds):
        item_options_list = [
            'price',
            'wholesale_price',
            'quantity',
            'barcode',
            'identifier',
            'short_description',
            'name',
            'slug',
        ]
        item_options = {}
        for k, v in kwds.iteritems():
            if k in item_options_list:
                item_options[k] = v
        item_options['slug'] = urlify(kwds['name'])

        if kwds['identifier'] in self.data['item_by_identifier']:
            item = self.data['item_by_identifier'][kwds['identifier']]
            for k, v in item_options.iteritems():
                setattr(item, k, v)
            item.save()

            self.data['item_by_identifier'].update({item.identifier: item})
            logging.debug('[U] %s' % kwds['name'])
            # True if created
            return False
        else:
            item = Item(**item_options)
            item.save()

            tree_item = TreeItem(parent=kwds['parent'], content_object=item)
            tree_item.save()

            self.data['item_by_identifier'].update({item.identifier: item})
            logging.debug('[S] %s' % item.name)
            # True if created
            return True
示例#8
0
    def make_item(self, param_list):
        '''
        Makes a new item in catalog
        param_list = [identifier, quantity, '<section_name> <name>']
        '''
        options = {}
        options['identifier'] = param_list[0]
        options['quantity'] = param_list[1]
        options['wholesale_price'] = param_list[4]
        options['price'] = param_list[5]
        if len(param_list) == 7:
            options['barcode'] = param_list[6]
        else:
            options['barcode'] = None
        options['name'] = param_list[3].decode('cp1251').replace('""', '"')
        options['slug'] = urlify(options['name'])
        options['short_description'] = options['name'].split(' ').pop()
        section_name = param_list[2].decode('cp1251')
        section_tree_item = self._get_or_create_section(
            section_name, self.import_section)
        options['parent'] = section_tree_item

        return self._update_or_create_item(**options)
示例#9
0
 def testEnglish(self):
     self.assertEqual(urlify(u'WOW. We Say ENGLISH.'),
                      u'wow-we-say-english')
示例#10
0
 def testMaxLengthLimit(self):
     self.assertEqual(
         urlify(
             u'urlstring url instance class request embodies. Example, data headers, calling:'
         ), u'urlstring-url-instance-class-request-embodies-exam')
示例#11
0
    def testArabic(self):
        # NOTE: arabic not supported: recognize only space in center;
        # therefore return ''

        r = urlify(u'اللغة العربية')
        self.assertEqual(r, '')
示例#12
0
 def testWestern(self):
     self.assertEqual(urlify(u'ÀÞβ Λğ-Ґє'), u'athb-lg-gye')
示例#13
0
 def testStopWords(self):
     self.assertEqual(urlify(u'hello, this is an blahblah'),
                      u'hello-blahblah')
示例#14
0
 def testChinese(self):
     self.assertEqual(urlify(u'公共的模'),
                      u'gong-gong-de-mo')
示例#15
0
 def testHyphen(self):
     self.assertEqual(urlify(u'Hello•Hello'),
                      u'xuan-feng-dao-ying-2008-imagetunnel')
示例#16
0
    def test_when_all_args_are_correct(self):

        self.assertEqual(u.urlify("hello world", 11), "hello%20world")
        self.assertEqual(u.urlify("hello world     ", 11),
                         "hello%20world     ")
示例#17
0
def test():
    for key, value in TEST.items():
        assert(urlify(key) == value)
示例#18
0
def test_urlify():
    assert urlify("Mr John Smith    ", 13) == "Mr%20John%20Smith"
示例#19
0
文件: post.py 项目: torrez/post
    print(body)
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    wants_to_publish = raw_input("Do you want to publish that now? (If you say no, you can publish it later.) [Y/n]")
    wants_to_publish = wants_to_publish.lower()
    if wants_to_publish == 'y' or wants_to_publish == '':
        cursor.execute("""UPDATE posts SET status = ? WHERE rowid = ?""", 
                        (PUBLISHED, cursor.lastrowid))

        cursor.execute("""SELECT title, body, status, created_at FROM posts WHERE status = ? ORDER BY created_at desc LIMIT 10""", (PUBLISHED,))
        rows = cursor.fetchall()

        index_html = ""

        #write individual files
        for row in rows:
            slug = urlify.urlify(row[0].encode('utf-8'))
            post_file_name = "{0}.html".format(slug)
            with open("{0}{1}".format(public_html_path, post_file_name), 'w') as f:
                f.write("<h1>{0}</h1>\n".format(row[0].encode('utf-8')) )
                f.write(row[1].encode('utf-8'))

            index_html = index_html + "<br>" + "<h1>" + row[0] + "</h1><p>" +  row[1].replace("\n", "<br>") + "</p>"

        #write the index
        with open("{0}{1}".format(public_html_path, "index.html"), 'w') as f:
            f.write("""
                <!DOCTYPE html>
                <html>
                <head>
                <title>
                BLOG
示例#20
0
 def testHyphen(self):
     self.assertEqual(urlify(u' x--x- -x-  -x- - -x- '),
                      u'x--x---x---x-----x-')
示例#21
0
 def testMaxLengthLimit(self):
     self.assertEqual(urlify(u'urlstring url instance class request embodies. Example, data headers, calling:'),
                      u'urlstring-url-instance-class-request-embodies-exam')
    def test_urlify(self):

        s = list('a')
        urlify(s, 1)
        self.assertEqual(s, list('a'))

        s = list('ab')
        urlify(s, 2)
        self.assertEqual(s, list('ab'))

        s = list('abc')
        urlify(s, 3)
        self.assertEqual(s, list('abc'))

        s = list('   ')
        urlify(s, 1)
        self.assertEqual(s, list('%20'))

        s = list('      ')
        urlify(s, 2)
        self.assertEqual(s, list('%20%20'))

        s = list('         ')
        urlify(s, 3)
        self.assertEqual(s, list('%20%20%20'))

        s = list('a   ')
        urlify(s, 2)
        self.assertEqual(s, list('a%20'))

        s = list('a b  ')
        urlify(s, 3)
        self.assertEqual(s, list('a%20b'))

        s = list('ab c  ')
        urlify(s, 4)
        self.assertEqual(s, list('ab%20c'))

        s = list('a b c    ')
        urlify(s, 5)
        self.assertEqual(s, list('a%20b%20c'))

        s = list(' a  ')
        urlify(s, 2)
        self.assertEqual(s, list('%20a'))

        s = list(' a     ')
        urlify(s, 3)
        self.assertEqual(s, list('%20a%20'))

        s = list(' a b    ')
        urlify(s, 4)
        self.assertEqual(s, list('%20a%20b'))

        s = list(' ab c    ')
        urlify(s, 5)
        self.assertEqual(s, list('%20ab%20c'))

        s = list(' a b c      ')
        urlify(s, 6)
        self.assertEqual(s, list('%20a%20b%20c'))

        s = list(' a b c              ')
        urlify(s, 6)
        self.assertEqual(s, list('%20a%20b%20c        '))
示例#23
0
 def testUnderline(self):
     self.assertEqual(urlify(u'pinyin urlify_30'), 'pinyin-urlify-30')
示例#24
0
 def testEnglish(self): 
     self.assertEqual(urlify(u'WOW! We Say ENGLISH!!!'),
                      u'wow-we-say-english')
示例#25
0
文件: post.py 项目: torrez/post
    )
    wants_to_publish = wants_to_publish.lower()
    if wants_to_publish == 'y' or wants_to_publish == '':
        cursor.execute("""UPDATE posts SET status = ? WHERE rowid = ?""",
                       (PUBLISHED, cursor.lastrowid))

        cursor.execute(
            """SELECT title, body, status, created_at FROM posts WHERE status = ? ORDER BY created_at desc LIMIT 10""",
            (PUBLISHED, ))
        rows = cursor.fetchall()

        index_html = ""

        #write individual files
        for row in rows:
            slug = urlify.urlify(row[0].encode('utf-8'))
            post_file_name = "{0}.html".format(slug)
            with open("{0}{1}".format(public_html_path, post_file_name),
                      'w') as f:
                f.write("<h1>{0}</h1>\n".format(row[0].encode('utf-8')))
                f.write(row[1].encode('utf-8'))

            index_html = index_html + "<br>" + "<h1>" + row[
                0] + "</h1><p>" + row[1].replace("\n", "<br>") + "</p>"

        #write the index
        with open("{0}{1}".format(public_html_path, "index.html"), 'w') as f:
            f.write("""
                <!DOCTYPE html>
                <html>
                <head>
示例#26
0
 def testWestern(self): 
     self.assertEqual(urlify(u'ÀÞβ Λğ-Ґє'),
                      u'athb-lg-gye')
示例#27
0
 def testEmpty(self):
     self.assertEqual(urlify(u''), u'default')
示例#28
0
 def testMixedText(self):
     self.assertEqual(urlify(u'  公共的  模asdf! '),
                      u'gong-gong-de-mo-asdf')
示例#29
0
 def testReservedWords(self):
     self.assertEqual(urlify(u'  blog  '), u'default')
示例#30
0
 def testHyphen(self):
     self.assertEqual(urlify(u'公共-的模'),
                      u'gong-gong-de-mo')
示例#31
0
 def testRus(self):
     self.assertEqual(urlify(u'русский текст'), u'russkij-tekst')
示例#32
0
 def testEmpty(self):
     self.assertEqual(urlify(u''),
                      u'default')
示例#33
0
 def testChines(self):
     # NOTE: no one character in line suppoerted; return 'default'
     r = urlify(u'漢語')
     self.assertEqual(r, 'default')
示例#34
0
 def testNotInMaps(self):
     self.assertEqual(urlify(u'コにちわ'),
                      u'default')
示例#35
0
 def test_case(self):
   self.assertTrue(urlify('a bc') == 'a%20bc')
示例#36
0
 def testStopWords(self):
     self.assertEqual(urlify(u'hello, this is an blahblah'),
                      u'hello-blahblah')
    def test_urlify(self):
        input1 = "Mr John Smith"
        input2 = "Courtney"

        self.assertEqual("Mr%20John%20Smith", urlify(input1, 13))
        self.assertEqual("Courtney", urlify(input2, 8))
示例#38
0
 def testReservedWords(self):
     self.assertEqual(urlify(u'  blog  '),
                      u'default')
示例#39
0
def hash_metadata(d):
    return urlify.urlify(d).replace('-', '')
示例#40
0
    def test_when_true_length_of_char_is_gt_than_num_of_char(self):

        with self.assertRaises(ValueError):
            u.urlify(" ", 5)