def test_two_debits(sdd):
    payment1 = {
        "name": "Test von Testenstein",
        "IBAN": "NL50BANK1234567890",
        "BIC": "BANKNL2A",
        "amount": 1012,
        "type": "FRST",
        "collection_date": datetime.date.today(),
        "mandate_id": "1234",
        "mandate_date": datetime.date.today(),
        "description": "Test transaction1"
    }
    payment2 = {
        "name": "Test du Test",
        "IBAN": "NL50BANK1234567890",
        "BIC": "BANKNL2A",
        "amount": 5000,
        "type": "RCUR",
        "collection_date": datetime.date.today(),
        "mandate_id": "1234",
        "mandate_date": datetime.date.today(),
        "description": "Test transaction2"
    }

    sdd.add_payment(payment1)
    sdd.add_payment(payment2)
    xmlout = sdd.export()
    xmlpretty = validate_xml(xmlout, "pain.008.003.02")
    assert clean_ids(xmlpretty.strip()) == clean_ids(SAMPLE_RESULT.strip())
def test_two_debits(sdd):
    payment1 = {
        "name": "Test & Co.",
        "IBAN": "NL50BANK1234567890",
        "BIC": "BANKNL2A",
        "amount": 1012,
        "type": "FRST",
        "collection_date": datetime.date.today(),
        "mandate_id": "1234",
        "mandate_date": datetime.date.today(),
        "description": "Test transaction1",
        "endtoend_id": "ebd75e7e649375d91b33dc11ae44c0e1"
    }
    payment2 = {
        "name": "Test du Test",
        "IBAN": "NL50BANK1234567890",
        "BIC": "BANKNL2A",
        "amount": 5000,
        "type": "RCUR",
        "collection_date": datetime.date.today(),
        "mandate_id": "1234",
        "mandate_date": datetime.date.today(),
        "description": u"Testgrüße <html>",
        "endtoend_id": "af755a40cb692551ed9f9d55f7179525"
    }

    sdd.add_payment(payment1)
    sdd.add_payment(payment2)
    xmlout = sdd.export()
    xmlpretty = validate_xml(xmlout, "pain.008.003.02")
    assert clean_ids(xmlpretty.strip()) == clean_ids(SAMPLE_RESULT.strip())
def test_two_debits(strf):
    payment1 = {
        "endtoend_id": "ebd75e7e649375d91b33dc11ae44c0e1",
        "name": "Test von Testenstein",
        "IBAN": "NL50BANK1234567890",
        "BIC": "BANKNL2A",
        "amount": 1012,
        "execution_date": datetime.date.today(),
        "description": "Test transaction1"
    }
    payment2 = {
        "name": "Test von Testenstein",
        "IBAN": "NL50BANK1234567890",
        "BIC": "BANKNL2A",
        "amount": 1012,
        "execution_date": datetime.date.today(),
        "description": "Test transaction1",
        "endtoend_id": "af755a40cb692551ed9f9d55f7179525"
    }

    strf.add_payment(payment1)
    strf.add_payment(payment2)
    xmlout = strf.export()
    xmlpretty = validate_xml(xmlout, "pain.001.001.03")
    print(xmlpretty.decode())
    assert clean_ids(xmlpretty.strip()) == clean_ids(SAMPLE_RESULT.strip())
Exemple #4
0
    def test_xml(self):

        idx = 1
        while True:
            try:
                with open(join(TEST_DATA_DIR, 'hjp_debt{:d}.xml'.format(idx)), 'rb') as infile:
                    dat = infile.read()
            except:
                self.assertGreater(idx, 1)
                break
            res = views.from_xml(dat)
            self.assertIsNone(res[1])
            self.assertIs(type(res[0]), views.Debt)
            err = views.to_xml(res[0])
            self.assertTrue(validate_xml(err, XSD))
            self.assertXMLEqual(strip_xml(dat), strip_xml(err), msg=str(idx))
            idx += 1
        self.assertEqual(views.from_xml(b'XXX'), (None, 'Chybný formát souboru'))
Exemple #5
0
def test_two_transfers(strf):
    payment1 = {
        "name": "Test von Testenstein",
        "IBAN": "NL50BANK1234567890",
        "amount": 1012,
        "execution_date": datetime.date.today(),
        "description": "Test transaction1"
    }
    payment2 = {
        "name": "Test du Test",
        "IBAN": "NL50BANK1234567890",
        "amount": 5000,
        "execution_date": datetime.date.today(),
        "description": "Test transaction2"
    }

    strf.add_payment(payment1)
    strf.add_payment(payment2)
    xmlout = strf.export()
    xmlpretty = validate_xml(xmlout, "pain.001.001.03")
    assert clean_ids(xmlpretty.strip()).decode() == clean_ids(SAMPLE_RESULT.strip()).decode()
Exemple #6
0
    def test_xmllist(self):

        res0 = '''<?xml version="1.0" encoding="utf-8"?>
<decisions application="udn" created="2016-08-04T00:20:47" version="1.1" xmlns="http://{0}" xmlns:xsi="http://www.w3\
.org/2001/XMLSchema-instance" xsi:schemaLocation="http://{0} {1}/static/udn-1.0.xsd"></decisions>
'''.format(LOCAL_SUBDOMAIN, LOCAL_URL)

        res1 = '''<?xml version="1.0" encoding="utf-8"?>
<decisions application="udn" created="2016-08-04T00:20:47" version="1.1" xmlns="http://{0}" xmlns:xsi="http://www.w3\
.org/2001/XMLSchema-instance" xsi:schemaLocation="http://{0} {1}/static/udn-1.0.xsd"><decision><court id="NSS">Nejvy\
šší správní soud</court><date>2199-07-01</date><ref><senate>8</senate><register>As</register><number>158</number><ye\
ar>2015</year><page>33</page></ref><agenda>Ochrana hospodářské soutěže a veřejné zakázky</agenda><parties><party>Úřa\
d pro ochranu hospodářské soutěže</party><party>BUREAU VERITAS CZECH REPUBLIC, spol. s r.o.</party><party>Zlínský kr\
aj</party></parties><files><file type="abridged">{2}udn/0158_8As__1500033S.pdf</file></files></decision></decisions>
'''.format(LOCAL_SUBDOMAIN, LOCAL_URL, REPO_URL)

        res2 = '''<?xml version="1.0" encoding="utf-8"?>
<decisions application="udn" created="2016-08-04T00:20:47" version="1.1" xmlns="http://{0}" xmlns:xsi="http://www.w3\
.org/2001/XMLSchema-instance" xsi:schemaLocation="http://{0} {1}/static/udn-1.0.xsd"><decision><court id="NSS">Nejvy\
šší správní soud</court><date>2199-07-01</date><ref><senate>8</senate><register>As</register><number>158</number><ye\
ar>2015</year><page>33</page></ref><agenda>Ochrana hospodářské soutěže a veřejné zakázky</agenda><parties><party>Úřa\
d pro ochranu hospodářské soutěže</party><party>BUREAU VERITAS CZECH REPUBLIC, spol. s r.o.</party><party>Zlínský kr\
aj</party></parties><files><file type="abridged">{2}udn/0158_8As__1500033S.pdf</file><file type="anonymized">{2}udn/\
0067_5As__1500054_20151119130217_prevedeno.pdf</file></files></decision></decisions>
'''.format(LOCAL_SUBDOMAIN, LOCAL_URL, REPO_URL)

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

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

        res = self.client.get('/udn/xmllist/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], 'text/xml; charset=utf-8')
        self.assertTrue(validate_xml(res.content, XSD))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        res = self.client.get('/udn/xmllist/?register=Ads')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertXMLEqual(strip_xml(res.content), strip_xml(res0.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        res = self.client.get(
            '/udn/xmllist/?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.assertXMLEqual(strip_xml(res.content), strip_xml(res1.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        models.Decision.objects.update(
            anonfilename='0067_5As__1500054_20151119130217_prevedeno.pdf')

        res = self.client.get(
            '/udn/xmllist/?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.assertXMLEqual(
            strip_xml(res.content),
            strip_xml(res2.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        exlim = views.EXLIM
        views.EXLIM = 0
        res = self.client.get('/udn/xmllist/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'exlim.xhtml')
        check_html(self, res.content)
        views.EXLIM = exlim
Exemple #7
0
    def test_xmllist(self):

        res0 = '''<?xml version="1.0" encoding="utf-8"?>
<hearings application="psj" created="2016-11-18T15:43:27" version="1.1" xmlns="http://legal.pecina.cz" xmlns:xsi="ht\
tp://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://legal.pecina.cz https://legal.pecina.cz/static/p\
sj-1.1.xsd"><hearing><court id="OSPHA02">Obvodní soud Praha 2</court><courtroom>č. 101/přízemí - přístavba</courtroo\
m><time>2016-12-01T09:00:00</time><ref><senate>26</senate><register>C</register><number>181</number><year>2015</year\
></ref><judge>JUDr. Henzlová Šárka</judge><parties><party>ČR - Ministerstvo spravedlnosti ČR</party><party>Mgr. Hele\
na Morozová</party></parties><form>Jednání</form><closed>false</closed><cancelled>false</cancelled></hearing><hearin\
g><court id="OSPHA02">Obvodní soud Praha 2</court><courtroom>č. 101/přízemí - přístavba</courtroom><time>2016-12-01T\
12:00:00</time><ref><senate>26</senate><register>C</register><number>94</number><year>2015</year></ref><judge>JUDr. \
Henzlová Šárka</judge><parties><party>Česká republika - Ministerstvo spravedlnosti</party><party>Alois Hlásenský</pa\
rty></parties><form>Jednání</form><closed>false</closed><cancelled>false</cancelled></hearing></hearings>
'''

        res1 = '''<?xml version="1.0" encoding="utf-8"?>
<hearings application="psj" created="2016-11-18T16:00:01" version="1.1" xmlns="http://legal.pecina.cz" xmlns:xsi="ht\
tp://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://legal.pecina.cz https://legal.pecina.cz/static/p\
sj-1.1.xsd"><hearing><court id="OSPHA02">Obvodní soud Praha 2</court><courtroom>č. 101/přízemí - přístavba</courtroo\
m><time>2016-12-01T12:00:00</time><ref><senate>26</senate><register>C</register><number>94</number><year>2015</year>\
</ref><judge>JUDr. Henzlová Šárka</judge><parties><party>Česká republika - Ministerstvo spravedlnosti</party><party>\
Alois Hlásenský</party></parties><form>Jednání</form><closed>false</closed><cancelled>false</cancelled></hearing></h\
earings>
'''

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

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

        res = self.client.get('/psj/xmllist/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], 'text/xml; charset=utf-8')
        self.assertTrue(validate_xml(res.content, XSD))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        res = self.client.get('/psj/xmllist/?register=C')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertXMLEqual(strip_xml(res.content),
                            strip_xml(res0.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        res = self.client.get('/psj/xmllist/?party=oi&party_opt=icontains')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertXMLEqual(strip_xml(res.content),
                            strip_xml(res1.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        exlim = views.EXLIM
        views.EXLIM = 0
        res = self.client.get('/psj/xmllist/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'exlim.xhtml')
        check_html(self, res.content)
        views.EXLIM = exlim
Exemple #8
0
    def test_xmllist(self):

        res0 = '''<?xml version="1.0" encoding="utf-8"?>
<documents application="uds" created="2017-08-31T10:17:35" version="1.0" xmlns="http://{0}" xmlns:xsi="http://www.w\
3.org/2001/XMLSchema-instance" xsi:schemaLocation="{0} {1}/static/uds-1.0.xsd"><document id="82464"><publisher id="\
203040">Okresní soud Pelhřimov</publisher><ref>0 SPR 653/2009</ref><description>Rozvrh práce, změna č. 1</descripti\
on><agenda>Správa soudu</agenda><posted>2009-07-29T08:10:00</posted><files><file id="82788"><name>změna_č._1_RP_.pd\
f</name><url>{2}uds/82788/změna_č._1_RP_.pdf</url></file></files></document></documents>
'''.format(LOCAL_SUBDOMAIN, LOCAL_URL, REPO_URL)

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

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

        res = self.client.get('/uds/xmllist/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], 'text/xml; charset=utf-8')
        self.assertTrue(validate_xml(res.content, XSD))

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

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

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

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

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

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

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

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

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

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

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

        res = self.client.get('/uds/xmllist/?register=spr')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertXMLEqual(strip_xml(res.content), strip_xml(res0.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        exlim = views.EXLIM
        views.EXLIM = 0
        res = self.client.get('/uds/xmllist/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'exlim.xhtml')
        check_html(self, res.content)
        views.EXLIM = exlim
Exemple #9
0
    def test_xmllist(self):

        res0 = '''<?xml version="1.0" encoding="utf-8"?>
<decisions application="udn" created="2016-08-04T00:20:47" version="1.1" xmlns="http://{0}" xmlns:xsi="http://www.w3\
.org/2001/XMLSchema-instance" xsi:schemaLocation="http://{0} {1}/static/udn-1.0.xsd"></decisions>
'''.format(LOCAL_SUBDOMAIN, LOCAL_URL)

        res1 = '''<?xml version="1.0" encoding="utf-8"?>
<decisions application="udn" created="2016-08-04T00:20:47" version="1.1" xmlns="http://{0}" xmlns:xsi="http://www.w3\
.org/2001/XMLSchema-instance" xsi:schemaLocation="http://{0} {1}/static/udn-1.0.xsd"><decision><court id="NSS">Nejvy\
šší správní soud</court><date>2199-07-01</date><ref><senate>8</senate><register>As</register><number>158</number><ye\
ar>2015</year><page>33</page></ref><agenda>Ochrana hospodářské soutěže a veřejné zakázky</agenda><parties><party>Úřa\
d pro ochranu hospodářské soutěže</party><party>BUREAU VERITAS CZECH REPUBLIC, spol. s r.o.</party><party>Zlínský kr\
aj</party></parties><files><file type="abridged">{2}udn/0158_8As__1500033S.pdf</file></files></decision></decisions>
'''.format(LOCAL_SUBDOMAIN, LOCAL_URL, REPO_URL)

        res2 = '''<?xml version="1.0" encoding="utf-8"?>
<decisions application="udn" created="2016-08-04T00:20:47" version="1.1" xmlns="http://{0}" xmlns:xsi="http://www.w3\
.org/2001/XMLSchema-instance" xsi:schemaLocation="http://{0} {1}/static/udn-1.0.xsd"><decision><court id="NSS">Nejvy\
šší správní soud</court><date>2199-07-01</date><ref><senate>8</senate><register>As</register><number>158</number><ye\
ar>2015</year><page>33</page></ref><agenda>Ochrana hospodářské soutěže a veřejné zakázky</agenda><parties><party>Úřa\
d pro ochranu hospodářské soutěže</party><party>BUREAU VERITAS CZECH REPUBLIC, spol. s r.o.</party><party>Zlínský kr\
aj</party></parties><files><file type="abridged">{2}udn/0158_8As__1500033S.pdf</file><file type="anonymized">{2}udn/\
0067_5As__1500054_20151119130217_prevedeno.pdf</file></files></decision></decisions>
'''.format(LOCAL_SUBDOMAIN, LOCAL_URL, REPO_URL)

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

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

        res = self.client.get('/udn/xmllist/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTrue(res.has_header('content-type'))
        self.assertEqual(res['content-type'], 'text/xml; charset=utf-8')
        self.assertTrue(validate_xml(res.content, XSD))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        res = self.client.get('/udn/xmllist/?register=Ads')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertXMLEqual(strip_xml(res.content),
                            strip_xml(res0.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        res = self.client.get(
            '/udn/xmllist/?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.assertXMLEqual(strip_xml(res.content),
                            strip_xml(res1.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        models.Decision.objects.update(
            anonfilename='0067_5As__1500054_20151119130217_prevedeno.pdf')

        res = self.client.get(
            '/udn/xmllist/?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.assertXMLEqual(strip_xml(res.content),
                            strip_xml(res2.encode('utf-8')))
        self.assertTrue(validate_xml(res.content, XSD))

        exlim = views.EXLIM
        views.EXLIM = 0
        res = self.client.get('/udn/xmllist/')
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'exlim.xhtml')
        check_html(self, res.content)
        views.EXLIM = exlim
Exemple #10
0
    def test_main(self):

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

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

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

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

        res = self.client.get('/hjp/')
        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, 'hjp_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post(
            '/hjp/',
            {'rounding': '0',
             'model': 'none',
             'submit_update': 'Aktualisovat'})
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post(
            '/hjp/',
            {'rounding': '0',
             'model': 'fixed',
             'fixed_amount': 'XXX',
             'submit_update': 'Aktualisovat'})
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        self.assertEqual(res.context['err_message'], 'Chybné zadání, prosím, opravte údaje')
        check_html(self, res.content)

        res = self.client.post(
            '/hjp/',
            {'rounding': '0',
             'model': 'none',
             'submit_empty': 'Vyprázdnit'},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post(
            '/hjp/',
            {'rounding': '0',
             'model': 'none',
             'title': 'test',
             'note': 'n',
             'internal_note': 'in',
             'submit_empty': 'Vyprázdnit'},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        title = soup.select('#id_title')
        self.assertEqual(len(title), 1)
        self.assertNotIn('value', title[0])
        note = soup.select('#id_note')
        self.assertEqual(len(note), 1)
        self.assertEqual(note[0].text, '')
        internal_note = soup.select('#id_internal_note')
        self.assertEqual(len(internal_note), 1)
        self.assertEqual(internal_note[0].text, '')

        for suf in (
                ('xml', 'Uložit', 'text/xml; charset=utf-8'),
                ('pdf', 'Export do PDF', 'application/pdf'),
        ):
            with open(join(TEST_DATA_DIR, 'hjp_debt1.{}'.format(suf[0])), 'rb') as infile:
                res = self.client.post(
                    '/hjp/',
                    {'currency_0': 'EUR',
                     'rounding': '2',
                     'model': 'none',
                     'submit_load': 'Načíst',
                     'load': infile},
                    follow=True)
            self.assertEqual(res.status_code, HTTPStatus.OK)
            self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
            check_html(self, res.content, key=suf[0])
            soup = BeautifulSoup(res.content, 'html.parser')
            title = soup.select('#id_title')
            self.assertEqual(len(title), 1)
            self.assertEqual(title[0]['value'], TEST_STRING)
            note = soup.select('#id_note')
            self.assertEqual(len(note), 1)
            self.assertEqual(note[0].text, 'Poznámka')
            internal_note = soup.select('#id_internal_note')
            self.assertEqual(len(internal_note), 1)
            self.assertEqual(internal_note[0].text, 'Interní poznámka')
            currency_0 = soup.select('#id_currency_0 option[value=CZK]')
            self.assertEqual(len(currency_0), 1)
            self.assertTrue(currency_0[0].has_attr('selected'))
            rounding = soup.select('#id_rounding option[value=0]')
            self.assertEqual(len(rounding), 1)
            self.assertTrue(rounding[0].has_attr('selected'))

            res = self.client.post(
                '/hjp/',
                {'currency_0': 'OTH',
                 'currency_1': 'AUD',
                 'rounding': '2',
                 'model': 'none',
                 'title': TEST_STRING,
                 'note': 'nn',
                 'internal_note': 'in',
                 'submit_' + suf[0]: suf[1]})
            self.assertEqual(res.status_code, HTTPStatus.OK)
            self.assertIn('content-type', res)
            self.assertEqual(res['content-type'], suf[2])
            if suf[0] == 'xml':
                self.assertTrue(validate_xml(res.content, XSD))

            con = BytesIO(res.content)
            con.seek(0)

            res = self.client.post(
                '/hjp/',
                {'submit_load': 'Načíst',
                 'load': con},
                follow=True)
            con.close()
            self.assertEqual(res.status_code, HTTPStatus.OK)
            self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
            check_html(self, res.content)
            soup = BeautifulSoup(res.content, 'html.parser')
            title = soup.select('#id_title')
            self.assertEqual(len(title), 1)
            self.assertEqual(title[0]['value'], TEST_STRING)
            note = soup.select('#id_note')
            self.assertEqual(len(note), 1)
            self.assertEqual(note[0].text, 'nn')
            internal_note = soup.select('#id_internal_note')
            self.assertEqual(len(internal_note), 1)
            self.assertEqual(internal_note[0].text, 'in')
            currency_0 = soup.select('#id_currency_0 option[value=OTH]')
            self.assertEqual(len(currency_0), 1)
            self.assertTrue(currency_0[0].has_attr('selected'))
            currency_1 = soup.select('#id_currency_1')
            self.assertEqual(len(currency_1), 1)
            self.assertEqual(currency_1[0]['value'], 'AUD')
            rounding = soup.select('#id_rounding option[value=2]')
            self.assertEqual(len(rounding), 1)
            self.assertTrue(rounding[0].has_attr('selected'))

        with open(join(TEST_DATA_DIR, 'hjp_debt1.xml'), 'rb') as infile:
            res = self.client.post(
                '/hjp/',
                {'currency_0': 'EUR',
                 'rounding': '2',
                 'model': 'none',
                 'submit_load': 'Načíst',
                 'load': infile},
                follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        check_html(self, res.content)

        res = self.client.post(
            '/hjp/',
            {'currency_0': 'CZK',
             'rounding': '0',
             'model': 'per_annum',
             'pa_rate': '12,6',
             'ydconv': 'ACT/ACT',
             'title': TEST_STRING,
             'note': 'nn',
             'internal_note': 'in',
             'submit_csv': 'Export do CSV'})
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertIn('content-type', res)
        self.assertEqual(res['content-type'], 'text/csv; charset=utf-8')
        string = res.content.decode('utf-8')
        with open(join(TEST_DATA_DIR, 'hjp_debt1.csv'), 'rb') as infile:
            dat = infile.read().decode('utf-8')
        self.assertEqual(string, dat)

        with open(join(TEST_DATA_DIR, 'hjp_err_debt1.xml'), 'rb') as infile:
            res = self.client.post(
                '/hjp/',
                {'currency_0': 'CZK',
                 'rounding': '0',
                 'model': 'none',
                 'submit_load': 'Načíst',
                 'load': infile},
                follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        check_html(self, res.content)
        soup = BeautifulSoup(res.content, 'html.parser')
        button = soup.select('input[name=submit_csv]')
        self.assertEqual(len(button), 1)
        self.assertTrue(button[0].has_attr('disabled'))
        self.assertContains(res, 'Chybné datum, data nejsou k disposici')

        res = self.client.post(
            '/hjp/',
            {'currency_0': 'OTH',
             'currency_1': 'AUD',
             'rounding': '2',
             'model': 'none',
             'title': TEST_STRING,
             'note': 'nn',
             'internal_note': 'in',
             'submit_pdf': 'Export do PDF'})
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertIn('content-type', res)
        self.assertEqual(res['content-type'], 'application/pdf')

        res = self.client.post(
            '/hjp/',
            {'currency_0': 'EUR',
             'rounding': '2',
             'model': 'none',
             'submit_load': 'Načíst',
             'load': None},
            follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        self.assertEqual(res.context['err_message'], 'Nejprve zvolte soubor k načtení')
        check_html(self, res.content)

        with open(join(TEST_DATA_DIR, 'hjp_err_debt2.xml'), 'rb') as infile:
            res = self.client.post(
                '/hjp/',
                {'currency_0': 'CZK',
                 'rounding': '0',
                 'model': 'none',
                 'submit_load': 'Načíst',
                 'load': infile},
                follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        self.assertEqual(res.context['err_message'], 'Chyba při načtení souboru')
        check_html(self, res.content)

        with open(join(TEST_DATA_DIR, 'hjp_err_debt3.xml'), 'rb') as infile:
            res = self.client.post(
                '/hjp/',
                {'currency_0': 'CZK',
                 'rounding': '0',
                 'model': 'none',
                 'submit_load': 'Načíst',
                 'load': infile},
                follow=True)
        self.assertEqual(res.status_code, HTTPStatus.OK)
        self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
        self.assertEqual(res.context['err_message'], 'Chyba při načtení souboru')
        check_html(self, res.content)

        res = self.client.post(
            '/hjp/',
            {'currency_0': 'EUR',
             'rounding': '2',
             'model': 'none',
             'next': '/hjp/'})
        self.assertRedirects(res, '/hjp/')

        idx = 1
        while True:
            try:
                infile = open(join(TEST_DATA_DIR, 'hjp_debt{:d}.xml'.format(idx)), 'rb')
            except:
                self.assertGreater(idx, 1)
                break
            res = self.client.post(
                '/hjp/',
                {'currency_0': 'EUR',
                 'rounding': '2',
                 'model': 'none',
                 'submit_load': 'Načíst',
                 'load': infile},
                follow=True)
            infile.close()
            self.assertEqual(res.status_code, HTTPStatus.OK)
            self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
            dct = {'submit_pdf': 'Export do PDF'}
            form = res.context['form']
            for key in form.fields:
                val = form[key].value()
                if val:
                    dct[key] = p2c(str(val))
            soup = BeautifulSoup(res.content, 'html.parser')
            dct['currency_0'] = soup.select('#id_currency_0 option[selected]')[0]['value']
            dct['currency_1'] = dct['currency']

            res = self.client.post('/hjp/', dct)
            self.assertEqual(res.status_code, HTTPStatus.OK)
            self.assertIn('content-type', res)
            self.assertEqual(res['content-type'], 'application/pdf')
            con = BytesIO(res.content)
            con.seek(0)

            res = self.client.post(
                '/hjp/',
                {'submit_load': 'Načíst',
                 'load': con},
                follow=True)
            con.close()
            self.assertEqual(res.status_code, HTTPStatus.OK)
            self.assertTemplateUsed(res, 'hjp_mainpage.xhtml')
            idx += 1