def test_put(self): def op(url, **kw): response, content = request_and_verify(self, 200, url, "GET", **kw) feed_hash = json.loads(content) missing = Hashes.missing_fields(feed_hash, ("url", "source", "active")) if missing: self.fail("missing fields: %s" % missing) url = self.__feed_url(test_id(self)) source_name = self.test_id feed = self.__feed_hash() body = json.dumps(feed) headers = api_login_headers() try: create_put_wrapper(self, url, op, headers=headers, body=body) finally: # hack to delete source for feed request_and_verify(self, 204, "%s/%s" % (self.base_sources_url, source_name), "DELETE", headers=headers)
def setUp(self): if not host: self.fail("host must be provided.") self.host = host self.base_feeds_url = "%s%s/feeds" % (host, PRIVATE_API_PREFIX) self.base_sources_url = "%s%s/sources" % (host, PRIVATE_API_PREFIX) self.test_id = test_id(self)
def test_put_malformed_body(self): url = self.__feed_url(test_id(self)) request_and_verify(self, 400, url, "PUT", headers=api_login_headers(), body="hi")
def _test_put_duplicate(self): feed = self.__feed_hash() request_body = json.dumps(feed) def op(url, **kw): # post content again request_and_verify(self, 409, url, "PUT", **kw) url = self.__feed_url(test_id(self)) create_put_wrapper(self, url, op, headers=api_login_headers(), body=request_body)
def test_put_existing_source(self): source_name = test_id(self) source_url = "%s/%s" % (self.base_sources_url, source_name) def source_op(url, **kw): feed = self.__feed_hash() body = json.dumps(feed) feed_url = self.__feed_url(source_name) create_put_wrapper(self, feed_url, lambda url, **kw: True, body=body, **kw) create_put_wrapper(self, source_url, source_op, headers=api_login_headers())
def test_post_duplicate(self): artifact = {'source': _source, 'content-type': 'text/plain', 'body': test_id(self) } request_body = json.dumps(artifact) def _op(url, **kw): # post content again request_and_verify(self, 409, self.base_url, "POST", **kw) _create_artifact_wrapper(self, self.base_url, self.source_url, _op, headers=self._login_headers(), body=request_body, **self._request_keywords())
def test_post_duplicate(self): artifact = { 'source': _source, 'content-type': 'text/plain', 'body': test_id(self) } request_body = json.dumps(artifact) def _op(url, **kw): # post content again request_and_verify(self, 409, self.base_url, "POST", **kw) _create_artifact_wrapper(self, self.base_url, self.source_url, _op, headers=self._login_headers(), body=request_body, **self._request_keywords())
def _build_artifact_url(self): return "%s/%s" % (self.base_url, test_id(self))
def test_put_unauthorized(self): url = self.__feed_url(test_id(self)) response, content = request_and_verify(self, 403, url, "PUT")
def test_get_nonexistent(self): url = self.__feed_url(test_id(self)) request_and_verify(self, 404, url, "GET", headers=api_login_headers())
def setUp(self): if not host: self.fail("host must be provided.") self.base_url = self._base_url() self.test_id = test_id(self)
def __artifact_hash(self): return {'source': _source, 'content-type': 'text/plain', 'body': test_id(self) }
def setUp(self): self.moxer = Mox() self.test_id = test_helper.test_id(self)
def __artifact_hash(self): return { 'source': _source, 'content-type': 'text/plain', 'body': test_id(self) }