Esempio n. 1
0
def drc_title(tag='h1', css_class='', language=''):
    u"""
    Retrieve random title.
    Uses langauge from global settings if an override is not provided.
    """
    language = get_language(language)
    titles = get_text_file(language, 'titles')

    data = {
        'title': random_lines(titles, 1),
    }

    # backwards compatibility with 0.1.5 - if only heading size was sent
    try:
        tag = int(tag)
        if tag > 6:
            tag = 6
        tag = 'h{}'.format(tag)
    except ValueError:
        pass

    # make sure that only/at least one word is the tag
    # (important for closing tags)
    try:
        data['tag'] = tag.split()[0]
    except IndexError:
        data['tag'] = 'h1'

    data['css_class'] = css_class
    return data
    def test_save(self):
        save_content(self.soup, 'p', text_type='paragraphs',
            url='www.example.com', language=self.lang, min_length=10)

        text_file = get_text_file(self.lang, text_type='paragraphs')
        self.assertIsNotNone(text_file)
        self.assertTrue(hasattr(text_file, 'read'))

        lines = text_file.read().splitlines()
        clean_lines = [line for line in lines
            if line.startswith('#') is False and line.strip() != '']
        self.assertEqual(len(clean_lines), 3)

        self.assertTrue(any(line for line in lines
            if line.startswith('# www.example.com')))
Esempio n. 3
0
def drc_paragraphs(no_of_paragraphs=1, css_class='', language=''):
    u"""
    Retrieve n random paragraphs.
    Uses langauge from global settings if an override is not provided.
    """
    language = get_language(language)
    paragraphs = get_text_file(language, 'paragraphs')

    random_paragraphs = random_lines(paragraphs, no_of_paragraphs)

    # fix when returning only 1 paragraph
    if isinstance(random_paragraphs, six.string_types):
        temp_list = []
        temp_list.append(random_paragraphs)
        random_paragraphs = temp_list

    data = {
        'paragraphs': random_paragraphs,
    }

    data['css_class'] = css_class
    return data
 def test_nonexisting_file(self):
     text_file = get_text_file('xyz')
     self.assertIsNone(text_file)
 def test_existing_file(self):
     text_file = get_text_file('en')
     self.assertIsNotNone(text_file)
     self.assertTrue(hasattr(text_file, 'read'))