Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def test_delete(self):
     url = self._test_url()
     create_put_wrapper(self, url, lambda url, **kw: None, headers=self._request_headers(),
         **self._request_keywords())
     
     # verifies that delete works
     request_and_verify(self, 404, url, "GET", headers=self._request_headers(),
         **self._request_keywords())
Exemplo n.º 3
0
 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")
Exemplo n.º 4
0
 def test_post_malformed_body(self):
     request_and_verify(self,
                        400,
                        self.base_url,
                        "POST",
                        headers=self._login_headers(),
                        body="hi",
                        **self._request_keywords())
Exemplo n.º 5
0
 def test_get_nonexistent(self):
     url = self._test_url()
     request_and_verify(self,
                        404,
                        url,
                        "GET",
                        headers=self._request_headers(),
                        **self._request_keywords())
Exemplo n.º 6
0
 def test_delete(self):
     url_ref = []
     keywords = {}
     def _op(url, **kw):
         url_ref.append(url)
         keywords.update(kw)
         
     body = json.dumps(self.__artifact_hash())
     _create_artifact_wrapper(self, self.base_url, self.source_url, _op, headers=self._login_headers(),
         body=body, **self._request_keywords())
     
     # verify deletion
     url = url_ref.pop()
     request_and_verify(self, 404, url, "GET", **keywords)
Exemplo n.º 7
0
    def test_delete(self):
        url = self._test_url()
        create_put_wrapper(self,
                           url,
                           lambda url, **kw: None,
                           headers=self._request_headers(),
                           **self._request_keywords())

        # verifies that delete works
        request_and_verify(self,
                           404,
                           url,
                           "GET",
                           headers=self._request_headers(),
                           **self._request_keywords())
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 def _op(url, **kw):
     response, content = request_and_verify(self, 200, url, "GET", **kw)
     artifact_hash = json.loads(content)
     missing = Hashes.missing_fields(
         artifact_hash, ('guid', 'source', 'content-type', 'modified',
                         'modified-by', 'body'))
     if missing:
         self.fail("missing artifact fields: %s" % missing)
Exemplo n.º 10
0
def _create_artifact_wrapper(test_case, base_url, source_url, operation, **kw):
    """
    handles artifact creation and deletion.
    
    params:
        operation - a method that is inject with the URL of a new artifact.
    """
    response, content = request_and_verify(test_case, 204, base_url, "POST", **kw)
    try:
        location_key = "location"
        if not location_key in response:
            test_case.fail("header '%s' not found in response" % location_key)
        artifact_url = response[location_key]
    
        operation(artifact_url, **kw)
    finally:
        request_and_verify(test_case, 204, artifact_url, "DELETE", **kw)
        request_and_verify(test_case, 204, source_url, "DELETE", **kw)
Exemplo n.º 11
0
def _create_artifact_wrapper(test_case, base_url, source_url, operation, **kw):
    """
    handles artifact creation and deletion.
    
    params:
        operation - a method that is inject with the URL of a new artifact.
    """
    response, content = request_and_verify(test_case, 204, base_url, "POST",
                                           **kw)
    try:
        location_key = "location"
        if not location_key in response:
            test_case.fail("header '%s' not found in response" % location_key)
        artifact_url = response[location_key]

        operation(artifact_url, **kw)
    finally:
        request_and_verify(test_case, 204, artifact_url, "DELETE", **kw)
        request_and_verify(test_case, 204, source_url, "DELETE", **kw)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
    def test_delete(self):
        url_ref = []
        keywords = {}

        def _op(url, **kw):
            url_ref.append(url)
            keywords.update(kw)

        body = json.dumps(self.__artifact_hash())
        _create_artifact_wrapper(self,
                                 self.base_url,
                                 self.source_url,
                                 _op,
                                 headers=self._login_headers(),
                                 body=body,
                                 **self._request_keywords())

        # verify deletion
        url = url_ref.pop()
        request_and_verify(self, 404, url, "GET", **keywords)
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
 def op(url, **kw):
     # post content again
     request_and_verify(self, 409, url, "PUT", **kw)
Exemplo n.º 16
0
 def _op(url, **kw):
     response, content = request_and_verify(self, 200, url, "GET", **kw)
     artifact_hash = json.loads(content)
     missing = Hashes.missing_fields(artifact_hash, ('guid', 'source', 'content-type', 'modified', 'modified-by', 'body'))
     if missing:
         self.fail("missing artifact fields: %s" % missing)
Exemplo n.º 17
0
 def test_get_nonexistent(self):
     url = self._build_artifact_url()
     request_and_verify(self, 404, url, "GET", headers=self._login_headers(),
         **self._request_keywords())
Exemplo n.º 18
0
 def test_post_malformed_body(self):
     request_and_verify(self, 400, self.base_url, "POST", headers=self._login_headers(),
         body="hi", **self._request_keywords())
Exemplo n.º 19
0
 def test_get_nonexistent(self):
     url = self.__feed_url(test_id(self))
     request_and_verify(self, 404, url, "GET", headers=api_login_headers())
Exemplo n.º 20
0
 def test_get_nonexistent(self):
     url = self.__feed_url(test_id(self))
     request_and_verify(self, 404, url, "GET", headers=api_login_headers())
Exemplo n.º 21
0
 def test_post_unauthorized(self):
     url = self._build_artifact_url()
     response, content = request_and_verify(self, (401, 403), self.base_url,
                                            "POST")
Exemplo n.º 22
0
 def _op(url, **kw):
     # post content again
     request_and_verify(self, 409, self.base_url, "POST", **kw)
Exemplo n.º 23
0
 def test_put_unauthorized(self):
     url = self.__feed_url(test_id(self))
     response, content = request_and_verify(self, 403, url, "PUT")
Exemplo n.º 24
0
 def test_put_unauthorized(self):
     url = self.__feed_url(test_id(self))
     response, content = request_and_verify(self, 403, url, "PUT")
Exemplo n.º 25
0
 def _op(url, **kw):
     # post content again
     request_and_verify(self, 409, self.base_url, "POST", **kw)
Exemplo n.º 26
0
 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")
Exemplo n.º 27
0
 def op(url, **kw):
     # post content again
     request_and_verify(self, 409, url, "PUT", **kw)
Exemplo n.º 28
0
 def test_post_unauthorized(self):
     url = self._build_artifact_url()
     response, content = request_and_verify(self, (401, 403), self.base_url, "POST")