Exemplo n.º 1
0
class HTTPEntityTest(unittest.TestCase):
    """Test different scenarios for the HTTPEntity class.
    """

    def __init__(self, *args, **kwargs):
        """HTTPEntityTest base class constructor
        """
        super(HTTPEntityTest, self).__init__(*args, **kwargs)
        self.http_entity = HTTPEntity()

    def test_get(self):
        """Function to test the 'get' method for HTTPEntity.
        """
        self.testVector = {}
        with open("./tests/HTTPEntity/testVector_HTTPEntity.json", "r") as f:
            self.testVector = json.load(f)

        for param in self.testVector["params"]:
            result = self.http_entity.get(
                url=self.testVector["cat_url"] + "?" + param,
                headers=self.testVector["headers"])

            self.assertEqual(result.get_status_code(), 200)
            self.assertNotEqual(result.get_status_code(), 500)
            self.assertNotEqual(result.get_status_code(), 404)
            self.assertNotEqual(result.get_status_code(), 400)
            print(result.get_json())
Exemplo n.º 2
0
    def count_entity(self, query: CatalogueQuery) -> CatalogueResult:
        """Method to get the count response for entities, based on a query.

        Args:
            query (CatalogueQuery): A query object of CatalogueQuery class.
        Returns:
            cat_result (CatalogueResult): returns a CatalogueResult object.
        """
        url = self.url + "/count"
        url = url + "?" + query.get_query()
        http_entity = HTTPEntity()
        response: HTTPResponse = http_entity.get(url, self.headers)
        result_data = response.get_json()

        cat_result = CatalogueResult()
        if response.get_status_code() == 200:
            cat_result.documents = result_data["results"]
            cat_result.total_hits = result_data["totalHits"]
            cat_result.status = result_data["type"]
        return cat_result
Exemplo n.º 3
0
    def get_item(self, iid: str) -> CatalogueResult:
        """Pydoc heading.

        Args:
            argument (argument-type): argument-description
        Returns:
            returned-varaible (returned-varaible-type): return-variable-description
        """
        url = self.url + "/item"
        url = url + "?" + "id=" + iid
        http_entity = HTTPEntity()
        response: HTTPResponse = http_entity.get(url, self.headers)
        result_data = response.get_json()

        cat_result = CatalogueResult()
        if response.get_status_code() == 200:
            cat_result.documents = result_data["results"]
            cat_result.total_hits = result_data["totalHits"]
            cat_result.status = result_data["type"]
        return cat_result
Exemplo n.º 4
0
    def list_entity(self, entity_type: str) -> CatalogueResult:
        """Method to get the list response for entities, based on an entity type.

        Args:
            entity_type (String): type must be either resource,
                resourceGroup, resourceServer.
        Returns:
            cat_result (CatalogueResult): returns a CatalogueResult object.
        """
        url = self.url + "/list"
        url = url + "/" + entity_type
        http_entity = HTTPEntity()
        response: HTTPResponse = http_entity.get(url, self.headers)
        result_data = response.get_json()

        cat_result = CatalogueResult()
        if response.get_status_code() == 200:
            cat_result.documents = result_data["results"]
            cat_result.total_hits = result_data["totalHits"]
            cat_result.status = result_data["type"]
        return cat_result
Exemplo n.º 5
0
    def get_related_entity(self, iid: str, rel: str) -> CatalogueResult:
        """Method to get the relationship response for entities,
                based on their id and relation.

        Args:
            iid (String): Id of the entity.
            rel (String): Relationship attribute of the entity
                whose id is provided.
        Returns:
            cat_result (CatalogueResult): returns a CatalogueResult object.
        """
        url = self.url + "/relationship"
        url = url + "?" + "id=" + iid + "&" + "rel=" + rel
        http_entity = HTTPEntity()
        response: HTTPResponse = http_entity.get(url, self.headers)
        result_data = response.get_json()

        cat_result = CatalogueResult()
        if response.get_status_code() == 200:
            cat_result.documents = result_data["results"]
            cat_result.total_hits = result_data["totalHits"]
            cat_result.status = result_data["type"]
        return cat_result