Exemple #1
0
    def test_new_topic(self):
        """Creating new topics and replying"""
        # create the user
        models.User('user1', '*****@*****.**', 'default')
        session.commit()

        # login and submit
        self.login('user1', 'default')
        response = self.submit_form(
            '/en/new', {
                'title': 'Hello World',
                'text': 'This is just a small test\n\n**test**',
                'tags': 'foo, bar, baz'
            })

        # we will need the topic URL later for commit submission,
        # capture it!
        topic_url = '/' + response.headers['Location'].split('/', 3)[-1]
        response = self.client.get(topic_url)
        q = lambda x: html_xpath(response.html, x)

        # we have a headline
        self.assertEqual(q('//html:h1')[0].text, 'Hello World')

        # and all the tags
        tags = sorted(x.text for x in q('//html:p[@class="tags"]/html:a'))
        self.assertEqual(tags, ['bar', 'baz', 'foo'])

        # and the text is present and parsed
        pars = q('//html:div[@class="text"]/html:p')
        self.assertEqual(len(pars), 2)
        self.assertEqual(pars[0].text, 'This is just a small test')
        self.assertEqual(pars[1][0].tag,
                         '{http://www.w3.org/1999/xhtml}strong')
        self.assertEqual(pars[1][0].text, 'test')

        # now try to submit a reply
        response = self.submit_form(
            topic_url, {'text': 'This is a reply\n\nwith //text//'},
            follow_redirects=True)
        q = lambda x: html_xpath(response.html, x)

        # do we have the text?
        pars = q(
            '//html:div[@class="replies"]//html:div[@class="text"]/html:p')
        self.assertEqual(len(pars), 2)
        self.assertEqual(pars[0].text, 'This is a reply')
        self.assertEqual(pars[1].text, 'with ')
        self.assertEqual(pars[1][0].tag, '{http://www.w3.org/1999/xhtml}em')
        self.assertEqual(pars[1][0].text, 'text')
Exemple #2
0
    def test_new_topic(self):
        """Creating new topics and replying"""
        # create the user
        models.User('user1', '*****@*****.**', 'default')
        session.commit()

        # login and submit
        self.login('user1', 'default')
        response = self.submit_form('/en/new', {
            'title':    'Hello World',
            'text':     'This is just a small test\n\n**test**',
            'tags':     'foo, bar, baz'
        })

        # we will need the topic URL later for commit submission,
        # capture it!
        topic_url = '/' + response.headers['Location'].split('/', 3)[-1]
        response = self.client.get(topic_url)
        q = lambda x: html_xpath(response.html, x)

        # we have a headline
        self.assertEqual(q('//html:h1')[0].text, 'Hello World')

        # and all the tags
        tags = sorted(x.text for x in q('//html:p[@class="tags"]/html:a'))
        self.assertEqual(tags, ['bar', 'baz', 'foo'])

        # and the text is present and parsed
        pars = q('//html:div[@class="text"]/html:p')
        self.assertEqual(len(pars), 2)
        self.assertEqual(pars[0].text, 'This is just a small test')
        self.assertEqual(pars[1][0].tag, '{http://www.w3.org/1999/xhtml}strong')
        self.assertEqual(pars[1][0].text, 'test')

        # now try to submit a reply
        response = self.submit_form(topic_url, {
            'text':     'This is a reply\n\nwith //text//'
        }, follow_redirects=True)
        q = lambda x: html_xpath(response.html, x)

        # do we have the text?
        pars = q('//html:div[@class="replies"]//html:div[@class="text"]/html:p')
        self.assertEqual(len(pars), 2)
        self.assertEqual(pars[0].text, 'This is a reply')
        self.assertEqual(pars[1].text, 'with ')
        self.assertEqual(pars[1][0].tag, '{http://www.w3.org/1999/xhtml}em')
        self.assertEqual(pars[1][0].text, 'text')
Exemple #3
0
 def visit(url):
     url = urljoin(BASE_URL, url).split('#', 1)[0]
     if not url.startswith(BASE_URL) or url in visited_links:
         return
     visited_links.add(url)
     path = url.split('/', 3)[-1]
     response = self.client.get(path, follow_redirects=True)
     content_type = response.headers['Content-Type']
     if content_type.split(';')[0].strip() == 'text/html':
         self.doExternalValidation(url, response.data, content_type)
     for link in html_xpath(response.html, '//html:a[@href]'):
         visit(link.attrib['href'])
Exemple #4
0
 def visit(url):
     url = urljoin(BASE_URL, url).split('#', 1)[0]
     if not url.startswith(BASE_URL) or url in visited_links:
         return
     visited_links.add(url)
     path = '/' + url.split('/', 3)[-1]
     if path.startswith('/logout?'):
         return
     response = self.client.get(path, follow_redirects=True)
     self.assertEqual(response.status_code, 200)
     for link in html_xpath(response.html, '//html:a[@href]'):
         visit(link.attrib['href'])
Exemple #5
0
 def visit(url):
     url = urljoin(BASE_URL, url).split('#', 1)[0]
     if not url.startswith(BASE_URL) or url in visited_links:
         return
     visited_links.add(url)
     path = '/' + url.split('/', 3)[-1]
     if path.startswith('/logout?'):
         return
     response = self.client.get(path, follow_redirects=True)
     self.assertEqual(response.status_code, 200)
     for link in html_xpath(response.html, '//html:a[@href]'):
         visit(link.attrib['href'])
Exemple #6
0
 def get_vote_count(response):
     el = html_xpath(response.html, '//html:div[@class="votebox"]/html:h4')
     return int(el[0].text)
Exemple #7
0
 def get_vote_count(response):
     el = html_xpath(response.html,
                     '//html:div[@class="votebox"]/html:h4')
     return int(el[0].text)