Exemplo n.º 1
0
    def test_mainpage(self):

        res = self.client.get('/uds')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.get('/uds/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'uds_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post(
            '/uds/',
            {'date_posted_from': '1.1.2015',
             'date_posted_to': '1.7.2016',
             'desc_opt': 'icontains',
             'format': 'html',
             'submit': 'Hledat'},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        check_html(self, res.content)

        res = self.client.post(
            '/uds/',
            {'desc': 'rozvrh',
             'desc_opt': 'icontains',
             'format': 'html',
             'submit': 'Hledat'},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.redirect_chain[0][1], HTTPStatus.FOUND)
        check_html(self, res.content)
        self.assertTrue(link_equal(res.redirect_chain[0][0], '/uds/list/?desc=rozvrh&desc_opt=icontains&start=0'))

        res = self.client.post(
            '/uds/',
            {'date_posted_from': 'XXX',
             'desc_opt': 'icontains',
             'format': 'html',
             'submit': 'Hledat'})
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_mainpage.xhtml')
        self.assertEqual(res.context['err_message'], 'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)

        res = self.client.post(
            '/uds/',
            {'date_posted_from': '1.1.2015',
             'date_posted_to': '1.7.2014',
             'desc_opt': 'icontains',
             'format': 'html',
             'submit': 'Hledat'})
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_mainpage.xhtml')
        self.assertEqual(res.context['err_message'], 'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)
Exemplo n.º 2
0
    def test_htmllist(self):

        res = self.client.get('/udn/list')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.post('/udn/list/')
        self.assertEqual(res.status_code, HTTPStatus.METHOD_NOT_ALLOWED)

        res = self.client.get('/udn/list/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        check_html(self, res.content)

        res = self.client.get('/udn/list/?senate=-1')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?senate=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?register=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?register=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?number=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?number=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?year=1989')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?year=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?page=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?page=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?agenda=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?agenda=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?date_from=2015-X-01')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?date_to=2015-X-01')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?party_opt=X')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?start=-1')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get(
            '/udn/list/?date_from=2015-01-01&date_to=2199-07-01&register=As&agenda=1&party_opt=icontains')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?register=Ads')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?date_from=2199-07-01')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?date_from=2199-07-02')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?date_to=2199-07-01')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?date_to=2199-06-30')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        dec = models.Decision.objects.get().__dict__
        del dec['id'], dec['_state']
        for page in range(200, 437):
            dec['page'] = page
            models.Decision(**dec).save()

        res = self.client.get('/udn/list/?senate=8')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot tr a')
        self.assertEqual(len(links), 3)
        self.assertEqual(links[0]['href'], '#')
        self.assertTrue(link_equal(links[1]['href'], '/udn/list/?senate=8&start=50'))
        self.assertTrue(link_equal(links[2]['href'], '/udn/list/?senate=8&start=200'))

        res = self.client.get('/udn/list/?senate=8&start=50')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot tr a')
        self.assertEqual(len(links), 5)
        self.assertTrue(link_equal(links[0]['href'], '/udn/list/?senate=8&start=0'))
        self.assertTrue(link_equal(links[1]['href'], '/udn/list/?senate=8&start=0'))
        self.assertEqual(links[2]['href'], '#')
        self.assertTrue(link_equal(links[3]['href'], '/udn/list/?senate=8&start=100'))
        self.assertTrue(link_equal(links[4]['href'], '/udn/list/?senate=8&start=200'))

        res = self.client.get('/udn/list/?senate=8&start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot tr a')
        self.assertEqual(len(links), 5)
        self.assertTrue(link_equal(links[0]['href'], '/udn/list/?senate=8&start=0'))
        self.assertTrue(link_equal(links[1]['href'], '/udn/list/?senate=8&start=50'))
        self.assertEqual(links[2]['href'], '#')
        self.assertTrue(link_equal(links[3]['href'], '/udn/list/?senate=8&start=150'))
        self.assertTrue(link_equal(links[4]['href'], '/udn/list/?senate=8&start=200'))

        res = self.client.get('/udn/list/?senate=8&start=200')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(len(res.context['rows']), 38)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot tr a')
        self.assertEqual(len(links), 3)
        self.assertTrue(link_equal(links[0]['href'], '/udn/list/?senate=8&start=0'))
        self.assertTrue(link_equal(links[1]['href'], '/udn/list/?senate=8&start=150'))
        self.assertEqual(links[2]['href'], '#')
Exemplo n.º 3
0
    def test_mainpage(self):

        res = self.client.get('/dir')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.get('/dir/')
        self.assertEqual(res.status_code, HTTPStatus.FOUND)

        res = self.client.get('/dir/', follow=True)
        self.assertTemplateUsed(res, 'login.xhtml')

        self.assertTrue(self.client.login(username='******', password='******'))

        res = self.client.get('/dir/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'dir_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post(
            '/dir/',
            {'email': 'xxx',
             'submit': 'Změnit'},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'dir_mainpage.xhtml')
        self.assertContains(res, 'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)

        res = self.client.post(
            '/dir/',
            {'email': 'alt@' + LOCAL_DOMAIN,
             'submit': 'Změnit'},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.user = User.objects.first()
        self.assertEqual(self.user.email, 'alt@' + LOCAL_DOMAIN)
        check_html(self, res.content)

        res = self.client.get('/dir/')
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertFalse(soup.select('table#list'))

        models.Debtor(
            uid=self.user,
            name_opt=0,
            first_name_opt=0,
            desc='Test').save()

        res = self.client.get('/dir/')
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertEqual(len(soup.select('table#list tbody tr')), 1)
        for number in range(200, 437):
            models.Debtor(uid=self.user, name_opt=0, first_name_opt=0, desc=('Test {:d}'.format(number))).save()

        res = self.client.get('/dir/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'dir_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/dir/debtorform/')
        self.assertEqual(links[1]['href'], '#')
        self.assertTrue(link_equal(links[2]['href'], '/dir/?start=50'))
        self.assertTrue(link_equal(links[3]['href'], '/dir/?start=200'))

        res = self.client.get('/dir/?start=50')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'dir_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 6)
        self.assertEqual(links[0]['href'], '/dir/debtorform/')
        self.assertTrue(link_equal(links[1]['href'], '/dir/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/dir/?start=0'))
        self.assertEqual(links[3]['href'], '#')
        self.assertTrue(link_equal(links[4]['href'], '/dir/?start=100'))
        self.assertTrue(link_equal(links[5]['href'], '/dir/?start=200'))

        res = self.client.get('/dir/?start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'dir_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 6)
        self.assertEqual(links[0]['href'], '/dir/debtorform/')
        self.assertTrue(link_equal(links[1]['href'], '/dir/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/dir/?start=50'))
        self.assertEqual(links[3]['href'], '#')
        self.assertTrue(link_equal(links[4]['href'], '/dir/?start=150'))
        self.assertTrue(link_equal(links[5]['href'], '/dir/?start=200'))

        res = self.client.get('/dir/?start=200')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'dir_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 38)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/dir/debtorform/')
        self.assertTrue(link_equal(links[1]['href'], '/dir/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/dir/?start=150'))
        self.assertEqual(links[3]['href'], '#')

        res = self.client.get('/dir/?start=500')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'dir_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 1)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/dir/debtorform/')
        self.assertTrue(link_equal(links[1]['href'], '/dir/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/dir/?start=187'))
        self.assertEqual(links[3]['href'], '#')
Exemplo n.º 4
0
    def test_htmllist(self):

        res = self.client.get('/psj/list')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.post('/psj/list/')
        self.assertEqual(res.status_code, HTTPStatus.METHOD_NOT_ALLOWED)

        res = self.client.get('/psj/list/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        check_html(self, res.content)

        res = self.client.get('/psj/list/?senate=-1')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?senate=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?register=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?register=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?number=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?number=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?year=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?year=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?courtroom=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?courtroom=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?judge=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?judge=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?date_from=2015-X-01')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?date_to=2015-X-01')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?party_opt=X')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/psj/list/?start=-1')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get(
            '/psj/list/?date_from=2015-01-01&date_to=2199-07-01&register=C&party_opt=icontains'
        )
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 2)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 2)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?register=T')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?date_from=2016-12-01')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 2)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?date_from=2016-12-02')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?date_to=2016-12-01')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 2)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?date_to=2016-11-30')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?court=OSPHA02')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 2)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?court=OSPHA03')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?courtroom={:d}'.format(
            models.Courtroom.objects.first().id))
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 2)

        res = self.client.get('/psj/list/?courtroom=9999')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?judge={:d}'.format(
            models.Hearing.objects.first().judge_id))
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 2)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?judge=9999')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?party=moroz&party_opt=icontains')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?party=mgr&party_opt=istartswith')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/psj/list/?party=zová&party_opt=iendswith')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get(
            '/psj/list/?party=mgr.+helena+morozová&party_opt=iexact')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        hear = models.Hearing.objects.first().__dict__
        del hear['id'], hear['_state']
        for number in range(200, 437):
            hear['number'] = number
            models.Hearing(**hear).save()

        res = self.client.get('/psj/list/?senate=26')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 3)
        self.assertEqual(links[0]['href'], '#')
        self.assertTrue(
            link_equal(links[1]['href'], '/psj/list/?senate=26&start=50'))
        self.assertTrue(
            link_equal(links[2]['href'], '/psj/list/?senate=26&start=200'))

        res = self.client.get('/psj/list/?senate=26&start=50')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 5)
        self.assertTrue(
            link_equal(links[0]['href'], '/psj/list/?senate=26&start=0'))
        self.assertTrue(
            link_equal(links[1]['href'], '/psj/list/?senate=26&start=0'))
        self.assertEqual(links[2]['href'], '#')
        self.assertTrue(
            link_equal(links[3]['href'], '/psj/list/?senate=26&start=100'))
        self.assertTrue(
            link_equal(links[4]['href'], '/psj/list/?senate=26&start=200'))

        res = self.client.get('/psj/list/?senate=26&start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 5)
        self.assertTrue(
            link_equal(links[0]['href'], '/psj/list/?senate=26&start=0'))
        self.assertTrue(
            link_equal(links[1]['href'], '/psj/list/?senate=26&start=50'))
        self.assertEqual(links[2]['href'], '#')
        self.assertTrue(
            link_equal(links[3]['href'], '/psj/list/?senate=26&start=150'))
        self.assertTrue(
            link_equal(links[4]['href'], '/psj/list/?senate=26&start=200'))

        res = self.client.get('/psj/list/?senate=26&start=200')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(len(res.context['rows']), 39)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 3)
        self.assertTrue(
            link_equal(links[0]['href'], '/psj/list/?senate=26&start=0'))
        self.assertTrue(
            link_equal(links[1]['href'], '/psj/list/?senate=26&start=150'))
        self.assertEqual(links[2]['href'], '#')
Exemplo n.º 5
0
    def test_mainpage(self):

        res = self.client.get('/psj')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.get('/psj/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'psj_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post('/psj/', {
            'date_from': '1.1.2015',
            'date_to': '1.7.2016',
            'register': 'C',
            'party_opt': 'icontains',
            'format': 'html',
            'submit': 'Hledat'
        },
                               follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        check_html(self, res.content)

        res = self.client.post('/psj/', {
            'party': 'Ing',
            'party_opt': 'icontains',
            'format': 'html',
            'submit': 'Hledat'
        },
                               follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_list.xhtml')
        self.assertEqual(res.redirect_chain[0][1], HTTPStatus.FOUND)
        check_html(self, res.content)
        self.assertTrue(
            link_equal(res.redirect_chain[0][0],
                       '/psj/list/?party=Ing&party_opt=icontains&start=0'))

        res = self.client.post(
            '/psj/', {
                'date_from': 'XXX',
                'party_opt': 'icontains',
                'format': 'html',
                'submit': 'Hledat'
            })
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_mainpage.xhtml')
        self.assertEqual(res.context['err_message'],
                         'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)

        res = self.client.post(
            '/psj/', {
                'date_from': '1.1.2015',
                'date_to': '1.7.2014',
                'register': 'C',
                'party_opt': 'icontains',
                'format': 'html',
                'submit': 'Hledat'
            })
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'psj_mainpage.xhtml')
        self.assertEqual(res.context['err_message'],
                         'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)
Exemplo n.º 6
0
    def test_htmllist(self):

        res = self.client.get('/uds/list')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.post('/uds/list/')
        self.assertEqual(res.status_code, HTTPStatus.METHOD_NOT_ALLOWED)

        res = self.client.get('/uds/list/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        check_html(self, res.content)

        res = self.client.get('/uds/list/?senate=-1')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?senate=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?number=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?number=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?year=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?year=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?page=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?page=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?agenda=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?agenda=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?date_posted_from=2015-X-01')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?date_posted_to=2015-X-01')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?desc_opt=X')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/uds/list/?start=-1')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get(
            '/uds/list/?date_posted_from=2005-01-01&date_posted_to=2199-07-01&register=SPR&desc_opt=icontains')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?register=T')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?date_posted_from=2009-07-29')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?date_posted_from=2009-07-30')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?date_posted_to=2009-07-29')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?date_posted_to=2009-07-28')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        pub = models.Publisher.objects.first().id
        res = self.client.get('/uds/list/?publisher={:d}'.format(pub))
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)

        res = self.client.get('/uds/list/?publisher={:d}'.format(pub + 1))
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 0)

        res = self.client.get('/uds/list/?agenda={:d}'.format(models.Agenda.objects.first().id))
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)

        res = self.client.get('/uds/list/?agenda=9999')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?desc=ozvrh&desc_opt=icontains')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?desc=rozvrh&desc_opt=istartswith')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?desc=1&desc_opt=iendswith')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/uds/list/?desc=rozvrh práce, změna č. 1&desc_opt=iexact')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        doc = models.Document.objects.first().__dict__
        del doc['id'], doc['_state']
        for docid in range(200, 438):
            doc['docid'] = docid
            if docid == 437:
                doc['number'] = 654
            models.Document(**doc).save()

        res = self.client.get('/uds/list/?number=653')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 3)
        self.assertEqual(links[0]['href'], '#')
        self.assertTrue(link_equal(links[1]['href'], '/uds/list/?number=653&start=50'))
        self.assertTrue(link_equal(links[2]['href'], '/uds/list/?number=653&start=200'))

        res = self.client.get('/uds/list/?number=653&start=50')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 5)
        self.assertTrue(link_equal(links[0]['href'], '/uds/list/?number=653&start=0'))
        self.assertTrue(link_equal(links[1]['href'], '/uds/list/?number=653&start=0'))
        self.assertEqual(links[2]['href'], '#')
        self.assertTrue(link_equal(links[3]['href'], '/uds/list/?number=653&start=100'))
        self.assertTrue(link_equal(links[4]['href'], '/uds/list/?number=653&start=200'))

        res = self.client.get('/uds/list/?number=653&start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 5)
        self.assertTrue(link_equal(links[0]['href'], '/uds/list/?number=653&start=0'))
        self.assertTrue(link_equal(links[1]['href'], '/uds/list/?number=653&start=50'))
        self.assertEqual(links[2]['href'], '#')
        self.assertTrue(link_equal(links[3]['href'], '/uds/list/?number=653&start=150'))
        self.assertTrue(link_equal(links[4]['href'], '/uds/list/?number=653&start=200'))

        res = self.client.get('/uds/list/?number=653&start=200')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'uds_list.xhtml')
        self.assertEqual(len(res.context['rows']), 38)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 3)
        self.assertTrue(link_equal(links[0]['href'], '/uds/list/?number=653&start=0'))
        self.assertTrue(link_equal(links[1]['href'], '/uds/list/?number=653&start=150'))
        self.assertEqual(links[2]['href'], '#')
Exemplo n.º 7
0
    def test_htmllist(self):

        res = self.client.get('/udn/list')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.post('/udn/list/')
        self.assertEqual(res.status_code, HTTPStatus.METHOD_NOT_ALLOWED)

        res = self.client.get('/udn/list/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        check_html(self, res.content)

        res = self.client.get('/udn/list/?senate=-1')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?senate=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?register=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?register=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?number=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?number=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?year=1989')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?year=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?page=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?page=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?agenda=0')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?agenda=XXX')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?date_from=2015-X-01')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?date_to=2015-X-01')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?party_opt=X')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get('/udn/list/?start=-1')
        self.assertEqual(res.status_code, HTTPStatus.NOT_FOUND)

        res = self.client.get(
            '/udn/list/?date_from=2015-01-01&date_to=2199-07-01&register=As&agenda=1&party_opt=icontains'
        )
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?register=Ads')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?date_from=2199-07-01')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?date_from=2199-07-02')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?date_to=2199-07-01')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 1)
        check_html(self, res.content)

        res = self.client.get('/udn/list/?date_to=2199-06-30')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(res.context['total'], 0)
        check_html(self, res.content)

        dec = models.Decision.objects.get().__dict__
        del dec['id'], dec['_state']
        for page in range(200, 437):
            dec['page'] = page
            models.Decision(**dec).save()

        res = self.client.get('/udn/list/?senate=8')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot tr a')
        self.assertEqual(len(links), 3)
        self.assertEqual(links[0]['href'], '#')
        self.assertTrue(
            link_equal(links[1]['href'], '/udn/list/?senate=8&start=50'))
        self.assertTrue(
            link_equal(links[2]['href'], '/udn/list/?senate=8&start=200'))

        res = self.client.get('/udn/list/?senate=8&start=50')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot tr a')
        self.assertEqual(len(links), 5)
        self.assertTrue(
            link_equal(links[0]['href'], '/udn/list/?senate=8&start=0'))
        self.assertTrue(
            link_equal(links[1]['href'], '/udn/list/?senate=8&start=0'))
        self.assertEqual(links[2]['href'], '#')
        self.assertTrue(
            link_equal(links[3]['href'], '/udn/list/?senate=8&start=100'))
        self.assertTrue(
            link_equal(links[4]['href'], '/udn/list/?senate=8&start=200'))

        res = self.client.get('/udn/list/?senate=8&start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot tr a')
        self.assertEqual(len(links), 5)
        self.assertTrue(
            link_equal(links[0]['href'], '/udn/list/?senate=8&start=0'))
        self.assertTrue(
            link_equal(links[1]['href'], '/udn/list/?senate=8&start=50'))
        self.assertEqual(links[2]['href'], '#')
        self.assertTrue(
            link_equal(links[3]['href'], '/udn/list/?senate=8&start=150'))
        self.assertTrue(
            link_equal(links[4]['href'], '/udn/list/?senate=8&start=200'))

        res = self.client.get('/udn/list/?senate=8&start=200')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'udn_list.xhtml')
        self.assertEqual(len(res.context['rows']), 38)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot tr a')
        self.assertEqual(len(links), 3)
        self.assertTrue(
            link_equal(links[0]['href'], '/udn/list/?senate=8&start=0'))
        self.assertTrue(
            link_equal(links[1]['href'], '/udn/list/?senate=8&start=150'))
        self.assertEqual(links[2]['href'], '#')
Exemplo n.º 8
0
    def test_mainpage(self):

        res = self.client.get('/szr')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.get('/szr/')
        self.assertEqual(res.status_code, HTTPStatus.FOUND)

        res = self.client.get('/szr/', follow=True)
        self.assertTemplateUsed(res, 'login.xhtml')

        self.assertTrue(self.client.login(username='******', password='******'))

        res = self.client.get('/szr/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post(
            '/szr/',
            {'email': 'xxx',
             'submit': 'Změnit'},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertContains(res, 'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)

        res = self.client.post(
            '/szr/',
            {'email': 'alt@' + LOCAL_DOMAIN,
             'submit': 'Změnit'},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.user = User.objects.get(username='******')
        self.assertEqual(self.user.email, 'alt@' + LOCAL_DOMAIN)
        check_html(self, res.content)

        res = self.client.get('/szr/')
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertFalse(soup.select('table#list'))
        check_html(self, res.content)

        self.client.force_login(User.objects.get(pk=1))

        res = self.client.get('/szr/')
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertEqual(len(soup.select('table#list tbody tr')), 7)
        models.Proceedings(
            uid_id=1,
            court_id='OSPHA02',
            senate=15,
            register='C',
            number=13287,
            year=2016,
            desc='Test').save()

        res = self.client.get('/szr/')
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertEqual(len(soup.select('table#list tbody tr')), 8)
        for number in range(200, 437):
            models.Proceedings(
                uid_id=1,
                court_id='OSPHA02',
                senate=15,
                register='C',
                number=number,
                year=2016,
                desc='Test {:d}'.format(number)).save()

        res = self.client.get('/szr/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertEqual(links[1]['href'], '#')
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=50'))
        self.assertTrue(link_equal(links[3]['href'], '/szr/?start=200'))

        res = self.client.get('/szr/?start=50')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 6)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertTrue(link_equal(links[1]['href'], '/szr/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=0'))
        self.assertEqual(links[3]['href'], '#')
        self.assertTrue(link_equal(links[4]['href'], '/szr/?start=100'))
        self.assertTrue(link_equal(links[5]['href'], '/szr/?start=200'))

        res = self.client.get('/szr/?start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 6)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertTrue(link_equal(links[1]['href'], '/szr/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=50'))
        self.assertEqual(links[3]['href'], '#')
        self.assertTrue(link_equal(links[4]['href'], '/szr/?start=150'))
        self.assertTrue(link_equal(links[5]['href'], '/szr/?start=200'))

        res = self.client.get('/szr/?start=200')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 45)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertTrue(link_equal(links[1]['href'], '/szr/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=150'))
        self.assertEqual(links[3]['href'], '#')

        res = self.client.get('/szr/?start=500')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 1)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertTrue(link_equal(links[1]['href'], '/szr/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=194'))
        self.assertEqual(links[3]['href'], '#')
Exemplo n.º 9
0
    def test_mainpage(self):

        res = self.client.get('/sur')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.get('/sur/')
        self.assertEqual(res.status_code, HTTPStatus.FOUND)

        res = self.client.get('/sur/', follow=True)
        self.assertTemplateUsed(res, 'login.xhtml')

        self.assertTrue(self.client.login(username='******', password='******'))

        res = self.client.get('/sur/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'sur_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post('/sur/', {
            'email': 'xxx',
            'submit': 'Změnit'
        },
                               follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'sur_mainpage.xhtml')
        self.assertContains(res, 'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)

        res = self.client.post('/sur/', {
            'email': 'alt@' + LOCAL_DOMAIN,
            'submit': 'Změnit'
        },
                               follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.user = User.objects.first()
        self.assertEqual(self.user.email, 'alt@' + LOCAL_DOMAIN)
        check_html(self, res.content)

        res = self.client.get('/sur/')
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertFalse(soup.select('table#list'))
        models.Party(uid=self.user, party_opt=0, party='Test').save()

        res = self.client.get('/sur/')
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertEqual(len(soup.select('table#list tbody tr')), 1)
        for number in range(200, 437):
            models.Party(uid=self.user,
                         party_opt=0,
                         party='Test {:d}'.format(number)).save()

        res = self.client.get('/sur/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'sur_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/sur/partyform/')
        self.assertEqual(links[1]['href'], '#')
        self.assertTrue(link_equal(links[2]['href'], '/sur/?start=50'))
        self.assertTrue(link_equal(links[3]['href'], '/sur/?start=200'))

        res = self.client.get('/sur/?start=50')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'sur_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 6)
        self.assertEqual(links[0]['href'], '/sur/partyform/')
        self.assertTrue(link_equal(links[1]['href'], '/sur/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/sur/?start=0'))
        self.assertEqual(links[3]['href'], '#')
        self.assertTrue(link_equal(links[4]['href'], '/sur/?start=100'))
        self.assertTrue(link_equal(links[5]['href'], '/sur/?start=200'))

        res = self.client.get('/sur/?start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'sur_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 6)
        self.assertEqual(links[0]['href'], '/sur/partyform/')
        self.assertTrue(link_equal(links[1]['href'], '/sur/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/sur/?start=50'))
        self.assertEqual(links[3]['href'], '#')
        self.assertTrue(link_equal(links[4]['href'], '/sur/?start=150'))
        self.assertTrue(link_equal(links[5]['href'], '/sur/?start=200'))

        res = self.client.get('/sur/?start=200')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'sur_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 38)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/sur/partyform/')
        self.assertTrue(link_equal(links[1]['href'], '/sur/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/sur/?start=150'))
        self.assertEqual(links[3]['href'], '#')

        res = self.client.get('/sur/?start=500')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'sur_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 1)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/sur/partyform/')
        self.assertTrue(link_equal(links[1]['href'], '/sur/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/sur/?start=187'))
        self.assertEqual(links[3]['href'], '#')
Exemplo n.º 10
0
    def test_mainpage(self):

        res = self.client.get('/szr')
        self.assertEqual(res.status_code, HTTPStatus.MOVED_PERMANENTLY)

        res = self.client.get('/szr/')
        self.assertEqual(res.status_code, HTTPStatus.FOUND)

        res = self.client.get('/szr/', follow=True)
        self.assertTemplateUsed(res, 'login.xhtml')

        self.assertTrue(self.client.login(username='******', password='******'))

        res = self.client.get('/szr/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], FULL_CONTENT_TYPE)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post('/szr/', {
            'email': 'xxx',
            'submit': 'Změnit'
        },
                               follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertContains(res, 'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)

        res = self.client.post('/szr/', {
            'email': 'alt@' + LOCAL_DOMAIN,
            'submit': 'Změnit'
        },
                               follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.user = User.objects.get(username='******')
        self.assertEqual(self.user.email, 'alt@' + LOCAL_DOMAIN)
        check_html(self, res.content)

        res = self.client.get('/szr/')
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertFalse(soup.select('table#list'))
        check_html(self, res.content)

        self.client.force_login(User.objects.get(pk=1))

        res = self.client.get('/szr/')
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertEqual(len(soup.select('table#list tbody tr')), 7)
        models.Proceedings(uid_id=1,
                           court_id='OSPHA02',
                           senate=15,
                           register='C',
                           number=13287,
                           year=2016,
                           desc='Test').save()

        res = self.client.get('/szr/')
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        self.assertEqual(len(soup.select('table#list tbody tr')), 8)
        for number in range(200, 437):
            models.Proceedings(uid_id=1,
                               court_id='OSPHA02',
                               senate=15,
                               register='C',
                               number=number,
                               year=2016,
                               desc='Test {:d}'.format(number)).save()

        res = self.client.get('/szr/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertEqual(links[1]['href'], '#')
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=50'))
        self.assertTrue(link_equal(links[3]['href'], '/szr/?start=200'))

        res = self.client.get('/szr/?start=50')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 6)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertTrue(link_equal(links[1]['href'], '/szr/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=0'))
        self.assertEqual(links[3]['href'], '#')
        self.assertTrue(link_equal(links[4]['href'], '/szr/?start=100'))
        self.assertTrue(link_equal(links[5]['href'], '/szr/?start=200'))

        res = self.client.get('/szr/?start=100')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 50)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 6)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertTrue(link_equal(links[1]['href'], '/szr/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=50'))
        self.assertEqual(links[3]['href'], '#')
        self.assertTrue(link_equal(links[4]['href'], '/szr/?start=150'))
        self.assertTrue(link_equal(links[5]['href'], '/szr/?start=200'))

        res = self.client.get('/szr/?start=200')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 45)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertTrue(link_equal(links[1]['href'], '/szr/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=150'))
        self.assertEqual(links[3]['href'], '#')

        res = self.client.get('/szr/?start=500')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'szr_mainpage.xhtml')
        self.assertEqual(len(res.context['rows']), 1)
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        links = soup.select('.list tfoot a')
        self.assertEqual(len(links), 4)
        self.assertEqual(links[0]['href'], '/szr/procform/')
        self.assertTrue(link_equal(links[1]['href'], '/szr/?start=0'))
        self.assertTrue(link_equal(links[2]['href'], '/szr/?start=194'))
        self.assertEqual(links[3]['href'], '#')