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")
def test_when_the_input_string_is_empty(self): with self.assertRaises(ValueError): u.urlify("", 0) with self.assertRaises(ValueError): u.urlify(" ", 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
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
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
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)
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)
def testEnglish(self): self.assertEqual(urlify(u'WOW. We Say ENGLISH.'), u'wow-we-say-english')
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 testArabic(self): # NOTE: arabic not supported: recognize only space in center; # therefore return '' r = urlify(u'اللغة العربية') self.assertEqual(r, '')
def testWestern(self): self.assertEqual(urlify(u'ÀÞβ Λğ-Ґє'), u'athb-lg-gye')
def testStopWords(self): self.assertEqual(urlify(u'hello, this is an blahblah'), u'hello-blahblah')
def testChinese(self): self.assertEqual(urlify(u'公共的模'), u'gong-gong-de-mo')
def testHyphen(self): self.assertEqual(urlify(u'Hello•Hello'), u'xuan-feng-dao-ying-2008-imagetunnel')
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 ")
def test(): for key, value in TEST.items(): assert(urlify(key) == value)
def test_urlify(): assert urlify("Mr John Smith ", 13) == "Mr%20John%20Smith"
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
def testHyphen(self): self.assertEqual(urlify(u' x--x- -x- -x- - -x- '), u'x--x---x---x-----x-')
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 '))
def testUnderline(self): self.assertEqual(urlify(u'pinyin urlify_30'), 'pinyin-urlify-30')
def testEnglish(self): self.assertEqual(urlify(u'WOW! We Say ENGLISH!!!'), u'wow-we-say-english')
) 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>
def testEmpty(self): self.assertEqual(urlify(u''), u'default')
def testMixedText(self): self.assertEqual(urlify(u' 公共的 模asdf! '), u'gong-gong-de-mo-asdf')
def testReservedWords(self): self.assertEqual(urlify(u' blog '), u'default')
def testHyphen(self): self.assertEqual(urlify(u'公共-的模'), u'gong-gong-de-mo')
def testRus(self): self.assertEqual(urlify(u'русский текст'), u'russkij-tekst')
def testChines(self): # NOTE: no one character in line suppoerted; return 'default' r = urlify(u'漢語') self.assertEqual(r, 'default')
def testNotInMaps(self): self.assertEqual(urlify(u'コにちわ'), u'default')
def test_case(self): self.assertTrue(urlify('a bc') == 'a%20bc')
def test_urlify(self): input1 = "Mr John Smith" input2 = "Courtney" self.assertEqual("Mr%20John%20Smith", urlify(input1, 13)) self.assertEqual("Courtney", urlify(input2, 8))
def hash_metadata(d): return urlify.urlify(d).replace('-', '')
def test_when_true_length_of_char_is_gt_than_num_of_char(self): with self.assertRaises(ValueError): u.urlify(" ", 5)