Exemplo n.º 1
0
 def test_5_queryvals(self):
     url = 'attribute/%s:%s/%s=%s/id,%s' % (
         self.sname_url, self.tname_url, self.cname_url,
         urlquote(u"foo ǝɯɐu%".encode('utf8')), self.cname_url)
     self.assertHttp(self.session.get(url), 200, 'application/json')
     self.assertHttp(self.session.get(url, headers={"accept": "text/csv"}),
                     200, 'text/csv')
Exemplo n.º 2
0
 def test_5_queryvals(self):
     url = 'attribute/%s:%s/%s=%s/id,%s' % (
         self.sname_url,
         self.tname_url,
         self.cname_url,
         urlquote(u"foo ǝɯɐu%".encode('utf8')),
         self.cname_url
     )
     self.assertHttp(self.session.get(url), 200, 'application/json')
     self.assertHttp(self.session.get(url, headers={"accept": "text/csv"}), 200, 'text/csv')
Exemplo n.º 3
0
 def _redact_test(self, crid, frid, fval, status=204):
     r = self.session.get(self.url('attribute', crid, None, None))
     self.assertHttp(r, 200, 'application/json')
     r1 = r.json()['snaprange']
     if frid is not None:
         r = self.session.get(self.url('attribute', frid, None, None))
         self.assertHttp(r, 200, 'application/json')
         r2 = r.json()['snaprange']
         r_from = max(r1[0], r2[0])
         r_until = min(r1[1], r2[1])
         suffix = '/%s=%s' % (frid, urlquote(json.dumps(fval)))
     else:
         r_from, r_until = r1
         suffix = ''
     self.assertHttp(common.secondary_session.delete(self.url('attribute', crid, r_from, r_until, suffix)), 403)
     self.assertHttp(self.session.delete(self.url('attribute', crid, r_from, r_until, suffix)), status)
Exemplo n.º 4
0
 def test_textfacet(self):
     for pattern in ['foo', 'bar', 'foo.*']:
         self.assertHttp(
             self.session.get('textfacet/%s' % urlquote(pattern)), 200)
Exemplo n.º 5
0
 def test_3_delete(self):
     for k in _merge(self.state1, self.state2):
         self.assertHttp(self.session.delete('%s/%s' % (self.uri, common.urlquote(k))), 204)
     self._check_bulk({})
Exemplo n.º 6
0
 def _check_each(self, state):
     for k, value in state.items():
         r = self.session.get('%s/%s' % (self.uri, common.urlquote(k)))
         self.assertHttp(r, 200, 'application/json')
         self.assertEqual(r.json(), value)
Exemplo n.º 7
0
 def _set_each(self, newstate):
     for k, value in newstate.items():
         self.assertHttp(self.session.put('%s/%s' % (self.uri, common.urlquote(k)), json=value), [201, 204])
Exemplo n.º 8
0
 def cval_url(self):
     return common.urlquote(json.dumps(self.cval))
Exemplo n.º 9
0
 def _query_url(self, value):
     return 'entity/%s:%s/payload=%s' % (_schema, self._table_name(), common.urlquote(json.dumps(value)))
Exemplo n.º 10
0
 def test_textfacet(self):
     for pattern in ['foo', 'bar', 'foo.*']:
         self.assertHttp(self.session.get('textfacet/%s' % urlquote(pattern)), 200)
Exemplo n.º 11
0
 def test_3_delete(self):
     for k in _merge(self.state1, self.state2):
         self.assertHttp(
             self.session.delete('%s/%s' % (self.uri, common.urlquote(k))),
             204)
     self._check_bulk({})
Exemplo n.º 12
0
 def _check_each(self, state):
     for k, value in state.items():
         r = self.session.get('%s/%s' % (self.uri, common.urlquote(k)))
         self.assertHttp(r, 200, 'application/json')
         self.assertEqual(r.json(), value)
Exemplo n.º 13
0
 def _set_each(self, newstate):
     for k, value in newstate.items():
         self.assertHttp(
             self.session.put('%s/%s' % (self.uri, common.urlquote(k)),
                              json=value), [201, 204])
Exemplo n.º 14
0
 def setUpClass(cls):
     cls.utf8 = cls.identifier.encode('utf8')
     assert len(cls.utf8) == 63
     cls.urlcoded = urlquote(cls.utf8)
Exemplo n.º 15
0
 def setUpClass(cls):
     cls.utf8 = cls.identifier.encode('utf8')
     assert len(cls.utf8) == 63
     cls.urlcoded = urlquote(cls.utf8)
Exemplo n.º 16
0
 def _query_url(self, value):
     return 'entity/%s:%s/payload=%s' % (_schema, self._table_name(), common.urlquote(json.dumps(value)))
Exemplo n.º 17
0
 def cval_url(self):
     return common.urlquote(str(self.cval))
Exemplo n.º 18
0
# -*- coding: utf-8 -*-
Exemplo n.º 19
0
class Unicode(common.ErmrestTest):
    sname = u"ɐɯǝɥɔs%"
    tname = u"ǝlqɐʇ%"
    cname = u"ǝɯɐu%"

    sname_url = urlquote(sname.encode('utf8'))
    tname_url = urlquote(tname.encode('utf8'))
    cname_url = urlquote(cname.encode('utf8'))

    defs = [{
        "schema_name": sname
    }, {
        "schema_name":
        sname,
        "table_name":
        tname,
        "column_definitions": [{
            "type": {
                "typename": "int8"
            },
            "name": "id",
            "nullok": False
        }, {
            "type": {
                "typename": "text"
            },
            "name": cname
        }],
        "keys": [{
            "unique_columns": ["id"]
        }]
    }]

    def test_1_create(self):
        self.assertHttp(self.session.post('schema', json=self.defs), 201)

    def test_2_introspect(self):
        self.assertHttp(self.session.get('schema/%s' % self.sname_url), 200,
                        'application/json')
        self.assertHttp(
            self.session.get('schema/%s/table/%s' %
                             (self.sname_url, self.tname_url)), 200,
            'application/json')
        self.assertHttp(
            self.session.get('schema/%s/table/%s/column/%s' %
                             (self.sname_url, self.tname_url, self.cname_url)),
            200, 'application/json')

    def test_3_csv(self):
        self.assertHttp(
            self.session.post('entity/%s:%s' %
                              (self.sname_url, self.tname_url),
                              data=u"""id,ǝɯɐu%
1,foo 1
2,foo 2
3,bar 1
4,baz 1
6,foo ǝɯɐu%
""".encode('utf8'),
                              headers={"content-type": "text/csv"}), 200)

    def test_4_json(self):
        self.assertHttp(
            self.session.post('entity/%s:%s' %
                              (self.sname_url, self.tname_url),
                              json=[
                                  {
                                      "id": 5,
                                      self.cname: "baz 2"
                                  },
                                  {
                                      "id": 7,
                                      self.cname: u"foo ǝɯɐu% 2"
                                  },
                              ]), 200)

    def test_5_queryvals(self):
        url = 'attribute/%s:%s/%s=%s/id,%s' % (
            self.sname_url, self.tname_url, self.cname_url,
            urlquote(u"foo ǝɯɐu%".encode('utf8')), self.cname_url)
        self.assertHttp(self.session.get(url), 200, 'application/json')
        self.assertHttp(self.session.get(url, headers={"accept": "text/csv"}),
                        200, 'text/csv')

    def test_6_download(self):
        r = self.session.get('entity/%s:%s?download=%s' %
                             (self.sname_url, self.tname_url, self.tname_url))
        self.assertHttp(r, 200)
        self.assertRegexpMatches(
            r.headers.get('content-disposition'),
            "attachment; filename[*]=UTF-8''%s.*" % self.tname_url)

    def test_7_badcsv(self):
        for hdr in [u"id,%s" % self.cname, u"id,%s" % self.tname]:
            for row in [u"10", self.tname, u"10,10,%s" % self.tname]:
                self.assertHttp(
                    self.session.post(
                        'entity/%s:%s' % (self.sname_url, self.tname_url),
                        data=(u"%s\n%s" % (hdr, row)).encode('utf8'),
                        headers={"content-type": "text/csv"}), [400, 409])