def handle(self, *args, **options):
        client = get_client()
        services = {}

        soup = client.get_web_service_meta_data()
        for webservice in soup.find_all("webservice"):
            name = webservice.find("name").text.strip()
            if webservice.attrs["type"] == CREATE_CASE_TYPE:
                services[name] = webservice

        self.stdout.write(
            self.style.NOTICE("Listed CreateCase type web services:"))
        for service_name in services.keys():
            self.stdout.write(f"- {service_name}")

        definition = input("Which one? ")

        service = services[definition]

        fields = []
        for xml_field in service.find_all("field"):
            fields.append((
                xml_field.find("name").text,
                xml_field.attrs["schema-name"],
                xml_field.attrs["data-type"],
            ))

        self.stdout.write(
            tabulate(fields,
                     headers=["Name", "SchemaName", "data-type"],
                     tablefmt="github"))

        self.stdout.write(self.style.SUCCESS("Done"))
    def handle(self, *args, **options):
        client = get_client()

        soup = client.get_web_service_meta_data()

        found_service_names = set(
            [
                webservice.find("name").text.strip()
                for webservice in soup.find_all("webservice")
            ]
        )

        expected_create_case_services = set(
            [
                settings.RESPOND_COMPLAINTS_WEBSERVICE,
                settings.RESPOND_FOI_WEBSERVICE,
                settings.RESPOND_SAR_WEBSERVICE,
                settings.RESPOND_COMMENTS_WEBSERVICE,
                settings.RESPOND_COMPLIMENTS_WEBSERVICE,
                settings.RESPOND_DISCLOSURES_WEBSERVICE,
            ]
        )
        found_create_case_services = found_service_names & expected_create_case_services
        other_found_services = found_service_names - expected_create_case_services

        self.stdout.write(self.style.NOTICE("All API-defined create case services:"))
        for service_name in found_create_case_services:
            self.stdout.write(f"- {service_name}")

        self.stdout.write(self.style.NOTICE("Other API-reported web services:"))
        for service_name in other_found_services:
            self.stdout.write(f"- {service_name}")
        self.stdout.write(self.style.SUCCESS("Done"))
 def process_form_submission(self, form):
     case_xml = form.get_xml_string()
     client = get_client()
     response = client.create_case(form.webservice, case_xml)
     soup = BeautifulSoup(response.content, "xml")
     if response.status_code != 200:
         reverse_schema_mapping = {
             v: k
             for k, v in form.field_schema_name_mapping.items()
         }
         for error in soup.find_all("failure"):
             if ("schemaName" in error.attrs and error.attrs["schemaName"]
                     in reverse_schema_mapping):
                 form.add_error(
                     reverse_schema_mapping[error.attrs["schemaName"]],
                     error.text)
             elif ("type" in error.attrs
                   and error.attrs["type"] == ATTACHMENT_FAILURE_ERROR):
                 form.add_error(ATTACHMENT_SCHEMA_NAME, error.text)
             else:
                 form.add_error(None, error.text)
         return form, None
     else:
         case_reference = get_case_reference(soup)
         return form, case_reference
 def test_exceptions_on_submission(self):
     responses.add(
         responses.POST,
         settings.RESPOND_API_BASE_URL + "case.svc/TestCreateComplaints",
         body=requests.RequestException(),
     )
     client = get_client()
     with self.assertRaises(RespondClientException):
         client.create_case("TestCreateComplaints", self.post_xml)
 def test_normal_submission(self):
     responses.add(
         responses.POST,
         settings.RESPOND_API_BASE_URL + "case.svc/TestCreateComplaints",
         body="success",
     )
     client = get_client()
     try:
         client.create_case("TestCreateComplaints", self.post_xml)
     except RespondClientException:
         self.fail("client.create_case failed unexpectedly")
    def handle(self, *args, **options):
        client = get_client()

        soup = client.get_fields()

        fields = []
        for field in soup.find_all("field"):
            schema_name = field.attrs["schema-name"]
            options = {"required": field.attrs["mandatory"] == "true"}
            fields.append((schema_name, options))

        self.stdout.write(
            tabulate(fields,
                     headers=["SchemaName", "Options"],
                     tablefmt="github"))

        self.stdout.write(self.style.SUCCESS("Done"))
Ejemplo n.º 7
0
 def _get_client(self):
     with open(
             pathlib.Path(__file__).parent / "fixtures/getservices.xml",
             "r") as f:
         services_xml = f.read()
     responses.add(
         responses.GET,
         settings.RESPOND_API_BASE_URL + "metadata.svc/getservices",
         services_xml,
         status=200,
         content_type="text/xml",
     )
     with open(
             pathlib.Path(__file__).parent / "fixtures/getfields.xml",
             "r") as f:
         fields_xml = f.read()
     responses.add(
         responses.GET,
         settings.RESPOND_API_BASE_URL +
         "metadata.svc/Fields/TestGetFieldsComplaints",
         fields_xml,
         status=200,
         content_type="text/xml",
     )
     with open(
             pathlib.Path(__file__).parent / "fixtures/getcategories.xml",
             "r") as f:
         categories_xml = f.read()
     responses.add(
         responses.GET,
         settings.RESPOND_API_BASE_URL +
         "metadata.svc/Categories/TestGetCategoryComplaints",
         categories_xml,
         status=200,
         content_type="text/xml",
     )
     return get_client()
Ejemplo n.º 8
0
    def handle(self, *args, **options):
        client = get_client()

        soup = client.get_categories()
        fields = []
        for field in soup.find_all("field"):
            schema_name = field.attrs["schema-name"]
            choices = [
                self.get_option_label(schema_name, o)
                for o in field.find_all("option")
                if o.attrs["available"] == "true"
            ]
            for i, (k, v) in enumerate(choices):
                if i == 0:
                    field_name = schema_name
                else:
                    field_name = ""
                fields.append((field_name, k, v))

        self.stdout.write(
            tabulate(fields, headers=["SchemaName", "key", "value"], tablefmt="github")
        )

        self.stdout.write(self.style.SUCCESS("Done"))
 def test_creating_client(self):
     try:
         get_client()
     except Exception:
         self.fail("Creating test client failed unexpectedly")