Пример #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
    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
    )
    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)