Пример #1
0
    def setup_class(cls):
        """Init and setup the ObjectField for our fake data generation tests."""
        cls.faker = MilMoveData()
        cls.object_field = ObjectField(name="objectField")

        # Set up the ObjectField with sub-fields:
        nested_object = ObjectField(
            name="nestedObject",
            object_fields=[
                BaseAPIField(name="sentence", data_type=DataType.SENTENCE, required=True),
                ArrayField(name="emails", items_field=BaseAPIField(data_type=DataType.EMAIL), max_items=2),
            ],
        )
        object_array = ArrayField(
            name="objectArray",
            items_field=ObjectField(
                object_fields=[
                    BaseAPIField(name="integer", data_type=DataType.INTEGER, required=True),
                    BaseAPIField(name="name", data_type=DataType.FIRST_NAME),
                ]
            ),
            max_items=2,
            required=True,
        )
        cls.object_field.object_fields = []
        cls.object_field.add_fields(
            [
                nested_object,
                object_array,
                BaseAPIField(name="integer", data_type=DataType.INTEGER),
                BaseAPIField(name="sentence", data_type=DataType.SENTENCE),
                BaseAPIField(name="phone", data_type=DataType.PHONE, required=True),
            ]
        )
Пример #2
0
    def setup_class(cls):
        """Init and setup the ObjectField for our fake data generation tests."""
        cls.faker = MilMoveData()
        cls.object_field = ObjectField(name="objectField")

        cls.object_field.object_fields = []
        cls.object_field.add_fields(
            [
                BaseAPIField(name="streetAddress1", data_type=DataType.STREET_ADDRESS, required=True),
                BaseAPIField(name="city", data_type=DataType.CITY, required=True),
                BaseAPIField(name="state", data_type=DataType.STATE, required=True),
                BaseAPIField(name="postalCode", data_type=DataType.POSTAL_CODE, required=True),
            ]
        )
Пример #3
0
    def __init__(self, api_file=""):
        """
        Sets the api_file and the parser attributes up for the class.
        :param api_file: str url, optional
        """
        if api_file:
            self.api_file = api_file

        if not self.api_file:
            raise ImplementationError("There must be an API file set to use the APIParser class.")

        self.parser = ResolvingParser(self.api_file)
        self.milmove_data = MilMoveData()  # for generating fake requests
        self.processed_bodies = []  # list of APIEndpointBody objects

        self.discriminated = False  # indicates if the parser is working with the data for a discriminator
Пример #4
0
    def onboard_customer(self) -> None:
        """
        Goes through the basic on-boarding flow for a customer.

        We're going to be re-using the same endpoint for several requests in this workflow.
        Because of that, we won't use the api fake data generator because we would end up having
        to delete a lot of the data it gave back in order to simulate the step-by-step process
        that on-boarding actually takes. Instead, we'll use the lower-level `MilMoveData` which is
        what the api fake data generate uses internally because it gives us more control. It's
        essentially a wrapper around faker, but we'll still use it to remain more consistent in
        the faker helper functions we use for different data types.

        Another thing to note is that because we'll be hitting a lot of endpoints in this load test,
        we'll pass task_name values to the logging functions whenever we hit an endpoint to make it
        easier to see in the logs what is happening.
        """
        user = self.get_user_info()

        if user is None:
            return  # get_user_info will log the error

        service_member_id = user["service_member"]["id"]

        milmove_faker = MilMoveData()

        # First let's create the profile.
        payload = {
            "id": service_member_id,
            "affiliation": "ARMY",
            "edipi": "1234567890",
            "rank": "E_1",
        }

        sm_url, sm_request_kwargs = self.request_preparer.prep_internal_request(
            endpoint=f"/service_members/{service_member_id}",
            endpoint_name="/service_members/{serviceMemberId}",
        )

        with self.rest(method="PATCH",
                       url=sm_url,
                       data=json.dumps(payload),
                       **sm_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "create_user_profile"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code != HTTPStatus.OK:
                resp.failure("Unable to create customer profile.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Now we can add name info. The url and request_kwargs will actually be the same, so we only
        # need to prepare the payload.

        suffix = random.choice([
            milmove_faker.get_fake_data_for_type(data_type=DataType.SUFFIX), ""
        ])

        payload = {
            "id":
            service_member_id,
            "first_name":
            milmove_faker.get_fake_data_for_type(
                data_type=DataType.FIRST_NAME),
            "middle_name":
            milmove_faker.get_fake_data_for_type(
                data_type=DataType.MIDDLE_NAME),
            "last_name":
            milmove_faker.get_fake_data_for_type(data_type=DataType.LAST_NAME),
            "suffix":
            suffix,
        }

        with self.rest(method="PATCH",
                       url=sm_url,
                       data=json.dumps(payload),
                       **sm_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "add_name_info"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code != HTTPStatus.OK:
                resp.failure("Unable to add customer name.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Now we can add contact info. Again, url and request_kwargs will be the same, so only need
        # a payload.

        payload = {
            "id":
            service_member_id,
            "telephone":
            milmove_faker.get_fake_data_for_type(data_type=DataType.PHONE),
            "secondary_telephone":
            milmove_faker.get_fake_data_for_type(data_type=DataType.PHONE),
            "personal_email":
            milmove_faker.get_fake_data_for_type(data_type=DataType.EMAIL),
            "email_is_preferred":
            milmove_faker.get_fake_data_for_type(data_type=DataType.BOOLEAN),
            "phone_is_preferred":
            milmove_faker.get_fake_data_for_type(data_type=DataType.BOOLEAN),
        }

        with self.rest(method="PATCH",
                       url=sm_url,
                       data=json.dumps(payload),
                       **sm_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "add_contact_info"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code != HTTPStatus.OK:
                resp.failure("Unable to add customer contact info.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Next we need a duty location

        duty_location_url, duty_location_request_kwargs = self.request_preparer.prep_internal_request(
            endpoint="/duty_locations?search=fort")

        with self.rest(method="GET",
                       url=duty_location_url,
                       **duty_location_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "search_duty_locations"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code == HTTPStatus.OK:
                duty_locations: JSONArray = resp.js
            else:
                resp.failure("Unable to find duty locations.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Don't care too much about which one for this load test, so just grabbing the first one.
        origin_duty_location = duty_locations[0]

        payload = {
            "id": service_member_id,
            "current_location_id": origin_duty_location["id"]
        }

        with self.rest(method="PATCH",
                       url=sm_url,
                       data=json.dumps(payload),
                       **sm_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "add_current_duty_location"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code != HTTPStatus.OK:
                resp.failure("Unable to add current duty location.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Next we'll input the current mailing address. We could use a fully random one, or base it
        # in part on where the duty location is, which we'll do.

        # First, we'll get the address of the duty location.
        address_url, address_request_kwargs = self.request_preparer.prep_internal_request(
            endpoint=f"/addresses/{origin_duty_location['address_id']}",
            endpoint_name="/addresses/{addressId}",
        )

        with self.rest(method="GET", url=address_url,
                       **address_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "get_duty_location_address"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code == HTTPStatus.OK:
                duty_location_address: JSONObject = resp.js
            else:
                resp.failure("Unable to find duty location address.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Zip code is validated as part of on-boarding.

        zip_code_url, zip_code_request_kwargs = self.request_preparer.prep_internal_request(
            endpoint=
            f"/rate_engine_postal_codes/{duty_location_address['postalCode']}?postal_code_type=origin",
            endpoint_name="/rate_engine_postal_codes/{postal_code}",
        )

        with self.rest(method="GET",
                       url=zip_code_url,
                       **zip_code_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "validate_zip_code"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code != HTTPStatus.OK:
                resp.failure("Unable to validate zip code.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Now we can add the current mailing address.

        payload = {
            "id": service_member_id,
            "residential_address": {
                "streetAddress1":
                milmove_faker.get_fake_data_for_type(
                    data_type=DataType.STREET_ADDRESS),
                "city":
                duty_location_address["city"],
                "state":
                duty_location_address["state"],
                "postalCode":
                duty_location_address["postalCode"],
            },
        }

        with self.rest(method="PATCH",
                       url=sm_url,
                       data=json.dumps(payload),
                       **sm_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "add_current_mailing_address"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code != HTTPStatus.OK:
                resp.failure("Unable to add current mailing address.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Next is the backup mailing address

        # We'll use mostly the same address as the current one, just changing out the street address
        payload["residential_address"][
            "streetAddress1"] = milmove_faker.get_fake_data_for_type(
                data_type=DataType.STREET_ADDRESS)

        with self.rest(method="PATCH",
                       url=sm_url,
                       data=json.dumps(payload),
                       **sm_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "add_backup_mailing_address"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code != HTTPStatus.OK:
                resp.failure("Unable to add backup mailing address.")

                log_response_failure(response=resp, task_name=task_name)

                return

        # Finally, we'll add the backup contact information.

        backup_contact_url, backup_contact_request_kwargs = self.request_preparer.prep_internal_request(
            endpoint=f"/service_members/{service_member_id}/backup_contacts",
            endpoint_name="/service_members/{serviceMemberId}/backup_contacts",
        )

        backup_contact_name = f"{milmove_faker.get_fake_data_for_type(data_type=DataType.FIRST_NAME)} {milmove_faker.get_fake_data_for_type(data_type=DataType.LAST_NAME)}"

        payload = {
            "name":
            backup_contact_name,
            "email":
            milmove_faker.get_fake_data_for_type(data_type=DataType.EMAIL),
            "telephone":
            milmove_faker.get_fake_data_for_type(data_type=DataType.PHONE),
            "permission":
            "NONE",
        }

        with self.rest(method="POST",
                       url=backup_contact_url,
                       data=json.dumps(payload),
                       **backup_contact_request_kwargs) as resp:
            resp: RestResponseContextManager

            task_name = "add_backup_contact"

            log_response_info(response=resp, task_name=task_name)

            if resp.status_code != HTTPStatus.CREATED:
                resp.failure("Unable to add backup contact info.")

                log_response_failure(response=resp, task_name=task_name)

                return
 def setup_class(cls):
     """Initialize the MilMoveData that will be tested."""
     cls.data = MilMoveData()
Пример #6
0
 def setup_class(cls):
     """Initialize the ObjectField that will be tested."""
     cls.object_field = ObjectField(name="objectField")
     cls.faker = MilMoveData()
Пример #7
0
 def setup_class(cls):
     """Initialize the ArrayField that will be tested."""
     items_field = BaseAPIField(data_type=DataType.PHONE, name="phoneNumber")
     cls.array_field = ArrayField(name="phoneNumbers", min_items=1, max_items=5, items_field=items_field)
     cls.faker = MilMoveData()
Пример #8
0
 def setup_class(cls):
     """Initialize the EnumField that will be tested."""
     cls.options = ["PERMANENT_CHANGE_OF_STATION", "RETIREMENT", "SEPARATION", "GHC", "NTS"]
     cls.enum_field = EnumField(name="ordersType", options=cls.options)
     cls.faker = MilMoveData()
Пример #9
0
 def setup_class(cls):
     """Initialize the BaseAPIField that will be tested."""
     cls.field = BaseAPIField(DataType.STREET_ADDRESS, name="streetAddress")
     cls.faker = MilMoveData()