def handle(self, *args, **options):
        # Note, you shold load the test fixture into your db after a flush
        # It is not performed in this management command for you because
        # we don't want to accidentally delete important data
        json_data = open(os.path.join(os.path.dirname(__file__),
                                      '../../../data/testing_data/endpoint_testing_data.json'))
        endpoints = json.load(json_data)
        json_data.close()

        # We now have our endpoints. For each endpoint, we will perform the request
        # and then update the dictionary. After, we will serialize it to JSON and
        # print it to the screen, suitable for redirection directly back into the
        # endpoint_testing_data.json file
        c = Client()
        for endpoint in endpoints:
            url = endpoint.get('url', None)
            method = endpoint.get('method', None)
            request_object = endpoint.get('request_object', None)
            status_code = endpoint.get('status_code', None)

            response = None
            if method == "POST":
                response = c.post(url, content_type='application/json', data=json.dumps(request_object), format='json')
            elif method == "GET":
                response = c.get(url, format='json')

            if response.status_code is not status_code:
                raise Exception("Status code mismatch!")

            endpoint["response_object"] = response.data

        print(json.dumps(endpoints, indent=4, cls=DjangoJSONEncoder))
コード例 #2
0
def test_endpoints(endpoint_data, client):
    json_data = open(os.path.join(os.path.dirname(__file__), "../../data/testing_data/endpoint_testing_data.json"))
    endpoints = json.load(json_data)
    json_data.close()
    logger = logging.getLogger("console")

    # TESTING TODO: fix this hand-rolled parametrization?

    for endpoint in endpoints:
        url = endpoint.get("url", None)

        # Skip v1 endpoint that got rewritten
        if url == "/api/v1/awards/autocomplete/":
            continue

        method = endpoint.get("method", None)
        request_object = endpoint.get("request_object", None)
        response_object = endpoint.get("response_object", None)
        status_code = endpoint.get("status_code", None)
        logger.info("Running endpoint test: \n\t" + method + " " + url + "\n\t" + endpoint.get("name", "Unnamed"))

        response = None
        if method == "POST":
            response = client.post(url, content_type="application/json", data=json.dumps(request_object), format="json")
        elif method == "GET":
            response = client.get(url, format="json")

        # Check if the status code is correct
        assert response.status_code == status_code
        # Check if the response object is correct
        # We use a special equivalence check because the response object can
        # be a multi-tiered nest of lists and objects, and can also be OrderedDicts
        # and ResultLists, which don't play nice with the native equality checks
        # TESTING TODO: I bet I can beat this
        assert evaluate_equivalence(response_object, response.data)
コード例 #3
0
    def handle(self, *args, **options):
        # Note, you shold load the test fixture into your db after a flush
        # It is not performed in this management command for you because
        # we don't want to accidentally delete important data
        json_data = open(
            os.path.join(os.path.dirname(__file__), "../../../data/testing_data/endpoint_testing_data.json")
        )
        endpoints = json.load(json_data)
        json_data.close()

        # We now have our endpoints. For each endpoint, we will perform the request
        # and then update the dictionary. After, we will serialize it to JSON and
        # print it to the screen, suitable for redirection directly back into the
        # endpoint_testing_data.json file
        c = Client()
        for endpoint in endpoints:
            url = endpoint.get("url", None)
            method = endpoint.get("method", None)
            request_object = endpoint.get("request_object", None)
            status_code = endpoint.get("status_code", None)

            response = None
            if method == "POST":
                response = c.post(url, content_type="application/json", data=json.dumps(request_object), format="json")
            elif method == "GET":
                response = c.get(url, format="json")

            if response.status_code is not status_code:
                raise Exception("Status code mismatch!")

            endpoint["response_object"] = response.data

        print(json.dumps(endpoints, indent=4, cls=DjangoJSONEncoder))
コード例 #4
0
    def __init__(self):
        json_data = open(
            os.path.join(os.path.dirname(__file__),
                         '../../tests/etl_test_data.json'))
        self.db_responses = json.load(json_data)
        json_data.close()

        self.results = None
コード例 #5
0
def test_endpoints(endpoint_data, client):
    json_data = open(
        os.path.join(
            os.path.dirname(__file__),
            '../../data/testing_data/endpoint_testing_data.json'))
    endpoints = json.load(json_data)
    json_data.close()
    logger = logging.getLogger('console')

    # TESTING TODO: fix this hand-rolled parameterization?

    for endpoint in endpoints:
        url = endpoint.get('url', None)
        method = endpoint.get('method', None)
        request_object = endpoint.get('request_object', None)
        response_object = endpoint.get('response_object', None)
        status_code = endpoint.get('status_code', None)
        logger.info("Running endpoint test: \n\t" + method + " " + url +
                    "\n\t" + endpoint.get('name', "Unnamed"))

        response = None
        if method == "POST":
            response = client.post(
                url,
                content_type='application/json',
                data=json.dumps(request_object),
                format='json')
        elif method == "GET":
            response = client.get(url, format='json')

        # Check if the status code is correct
        assert response.status_code == status_code
        # Check if the response object is correct
        # We use a special equivalence check because the response object can
        # be a multi-tiered nest of lists and objects, and can also be OrderedDicts
        # and ResultLists, which don't play nice with the native equality checks
        # TESTING TODO: I bet I can beat this
        assert evaluateEquivalence(response_object, response.data)