def test_create(self): new_record = { u'type': u'channel', u'lowerFreq': 20e6, u'upperFreq': 20e6, } d = testutil.http_post_json(reactor, self.__url('/'), {'new': new_record}) def proceed((response, data)): if response.code >= 300: print data self.assertEqual(response.code, http.CREATED) url = 'ONLYONE'.join(response.headers.getRawHeaders('Location')) self.assertEqual(url, self.__url('/3')) # URL of new entry def check((read_response, read_data)): j = json.loads(read_data) self.assertEqual(j[u'records'][u'3'], db.normalize_record(new_record)) return testutil.http_get(reactor, self.__url('/')).addCallback(check) d.addCallback(proceed) return d
def test_update_good(self): new_data = { u'type': u'channel', u'lowerFreq': 20e6, u'upperFreq': 20e6, u'label': u'modified', } index = u'1' modified = dict(self.response_json[u'records']) modified[index] = db.normalize_record(new_data) d = testutil.http_post_json( reactor, self.__url('/' + str(index)), { 'old': self.response_json[u'records'][index], 'new': new_data }) def proceed((response, data)): if response.code >= 300: print data self.assertEqual(response.code, http.NO_CONTENT) def check((read_response, read_data)): j = json.loads(read_data) self.assertEqual(j[u'records'], modified) return testutil.http_get(reactor, self.__url('/')).addCallback(check) d.addCallback(proceed) return d
def test_create(self): new_record = { u'type': u'channel', u'lowerFreq': 20e6, u'upperFreq': 20e6, } response, data = yield testutil.http_post_json(reactor, self.__url('/'), { 'new': new_record }) if response.code >= 300: print(data) self.assertEqual(response.code, http.CREATED) url = 'ONLYONE'.join(response.headers.getRawHeaders('Location')) self.assertEqual(url, self.__url('/3')) # URL of new entry _read_response, read_data = yield testutil.http_get(reactor, self.__url('/')) j = json.loads(read_data) self.assertEqual(j[u'records'][u'3'], db.normalize_record(new_record))
def test_update_good(self): new_data = { u'type': u'channel', u'lowerFreq': 20e6, u'upperFreq': 20e6, u'label': u'modified', } index = u'1' modified = dict(self.response_json[u'records']) modified[index] = db.normalize_record(new_data) response, data = yield testutil.http_post_json(reactor, self.__url('/' + str(index)), { 'old': self.response_json[u'records'][index], 'new': new_data }) if response.code >= 300: print(data) self.assertEqual(response.code, http.NO_CONTENT) _read_response, read_data = yield testutil.http_get(reactor, self.__url('/')) j = json.loads(read_data) self.assertEqual(j[u'records'], modified)