Beispiel #1
0
    def test_get_all_library_cnet_ids_from_directory_two_staff(self):
        xml_string = """<?xml version="1.0" encoding="UTF-8"?>
        <responseData>
          <response>Success</response>
          <totalResults>1</totalResults>
          <organizations>
            <organization>
              <name>Library</name>
              <type>Division</type>
              <departments>
                <department>
                  <name>Digital Services</name>
                  <resources>
                    <directoryURL>https://directory.uchicago.edu/organizations/575?type=departments</directoryURL>
                    <xmlURL>https://directory.uchicago.edu/api/v2/departments/575</xmlURL>
                  </resources>
                </department>
              </departments>
              <members>
                <member>
                  <name>Scooter McDanger</name>
                  <displayName>Scooter McDanger</displayName>
                  <cnetid>danger</cnetid>
                  <chicagoid>12345678L</chicagoid>
                  <title>Programmer/Analyst</title>
                  <email>[email protected]</email>
                  <phone>(773) 702-1234</phone>
                  <facultyExchange>JRL 220</facultyExchange>
                  <resources>
                    <directoryURL>https://directory.uchicago.edu/individuals/12345678L</directoryURL>
                    <xmlURL>https://directory.uchicago.edu/api/v2/individuals/12345678L</xmlURL>
                  </resources>
                </member>
                <member>
                  <name>Margaret Lovelee</name>
                  <displayName>Margaret Lovelee</displayName>
                  <cnetid>lovelee</cnetid>
                  <chicagoid>12345678L</chicagoid>
                  <title>Programmer/Analyst</title>
                  <email>[email protected]</email>
                  <phone>(773) 702-1234</phone>
                  <facultyExchange>JRL 220</facultyExchange>
                  <resources>
                    <directoryURL>https://directory.uchicago.edu/individuals/12345678L</directoryURL>
                    <xmlURL>https://directory.uchicago.edu/api/v2/individuals/12345678L</xmlURL>
                  </resources>
                </member>
              </members>
              <resources>
                <directoryURL>https://directory.uchicago.edu/organizations/16?type=divisions</directoryURL>
                <xmlURL>https://directory.uchicago.edu/api/v2/divisions/16</xmlURL>
              </resources>
            </organization>
          </organizations>
        </responseData>
        """

        cnetids = get_all_library_cnetids_from_directory(xml_string)

        self.assertEqual(set(cnetids), set(('lovelee', 'danger')))
Beispiel #2
0
    def test_individual_xml_validates(self):
        dtd = etree.DTD(StringIO("""
        <!ELEMENT responseData    (response, totalResults, individuals)>
        <!ELEMENT response        (#PCDATA)>
        <!ELEMENT totalResults    (#PCDATA)>
        <!ELEMENT individuals     (individual+)>
        <!ELEMENT individual      (name, displayName, cnetid, chicagoid, contacts, resources)>
        <!ELEMENT name            (#PCDATA)>
        <!ELEMENT displayName     (#PCDATA)>
        <!ELEMENT cnetid          (#PCDATA)>
        <!ELEMENT chicagoid       (#PCDATA)>
        <!ELEMENT contacts        (contact)>
        <!ELEMENT contact         (title, division, department, subDepartment, email, phone, facultyExchange)>
        <!ELEMENT title           (#PCDATA)>
        <!ELEMENT division        (name, resources)>
        <!ELEMENT resources       (directoryURL, xmlURL)>
        <!ELEMENT directoryURL    (#PCDATA)>
        <!ELEMENT xmlURL          (#PCDATA)>
        <!ELEMENT department      (name, resources)>
        <!ELEMENT subDepartment   (name, resources)>
        <!ELEMENT email           (#PCDATA)>
        <!ELEMENT phone           (#PCDATA)>
        <!ELEMENT facultyExchange (#PCDATA)>
        """))

        cnetids = get_all_library_cnetids_from_directory()
        root = etree.XML(get_xml_from_directory_api('https://directory.uchicago.edu/api/v2/individuals/' + cnetids[0] + '.xml'))
        self.assertEqual(dtd.validate(root), True)
    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement this 
        method. It may return a Unicode string which will be printed to 
        stdout. More: https://docs.djangoproject.com/en/1.8/howto/custom
        -management-commands/#django.core.management.BaseCommand.handle
        """

        # api staff, wagtail staff
        api_staff = set(get_all_library_cnetids_from_directory())
        wag_staff = set(get_all_library_cnetids_from_wagtail())

        output = []

        '''
        # JEJ
        print(
        get_individual_info_from_directory('amybuckland')
        )
        import sys
        sys.exit()
        '''

        missing_in_api = wag_staff.difference(api_staff)
        if missing_in_api:
            output.append("THE FOLLOWING STAFF APPEAR IN WAGTAIL, BUT NOT IN THE UNIVERSITY'S API:")
            output = output + list(missing_in_api)
            # if this happens, go into the user object and mark is_active False. 

        missing_in_wagtail = api_staff.difference(wag_staff)
        if missing_in_wagtail:
            output.append("THE FOLLOWING STAFF APPEAR IN THE UNIVERSITY'S API, BUT NOT IN WAGTAIL:")
            output = output + list(missing_in_wagtail)
            # if this happens, report that a new user needs to be created.

        for s in sorted(list(api_staff.intersection(wag_staff))):
            xml_string = xml_string = get_xml_from_directory_api('https://directory.uchicago.edu/api/v2/individuals/' + s + '.xml')
            api = get_individual_info_from_directory(xml_string)
            wag = get_individual_info_from_wagtail(s)

            if not api['officialName'] == wag['officialName']:
                output.append(s + "'s officialName is " + api['officialName'] + ", not " + wag['officialName'])

            if not api['displayName'] == wag['displayName']:
                output.append(s + "'s displayName is " + api['displayName'] + ", not " + wag['displayName'])
                # In the user management command, change the following things in the User object:
                # (note- in the User object, username = cnetid)
                # prompt a human for first_name, last_name.
                # In the StaffPage object,
                # check displayName and officialName.

            diffs = api['title_department_subdepartments'].difference(wag['title_department_subdepartments'])
            if diffs:
                output.append("THE FOLLOWING VCARDS APPEAR FOR " + s + " IN THE UNIVERSITY'S API, BUT NOT IN WAGTAIL:")
                for d in diffs:
                    output.append(d)

            diffs = wag['title_department_subdepartments'].difference(api['title_department_subdepartments'])
            if diffs:
                output.append("THE FOLLOWING VCARDS APPEAR FOR " + s + " IN WAGTAIL, BUT NOT IN THE UNIVERSITY'S API:")
                for d in diffs:
                    output.append(d)

        return "\n".join(output)
    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement this 
        method. It may return a Unicode string which will be printed to 
        stdout. More: https://docs.djangoproject.com/en/1.8/howto/custom
        -management-commands/#django.core.management.BaseCommand.handle
        """

        # api staff, wagtail staff
        api_staff = set(get_all_library_cnetids_from_directory())
        wag_staff = set(get_all_library_cnetids_from_wagtail())

        output = []
        '''
        # JEJ
        print(
        get_individual_info_from_directory('amybuckland')
        )
        import sys
        sys.exit()
        '''

        missing_in_api = wag_staff.difference(api_staff)
        if missing_in_api:
            output.append(
                "THE FOLLOWING STAFF APPEAR IN WAGTAIL, BUT NOT IN THE UNIVERSITY'S API:"
            )
            output = output + list(missing_in_api)
            # if this happens, go into the user object and mark is_active False.

        missing_in_wagtail = api_staff.difference(wag_staff)
        if missing_in_wagtail:
            output.append(
                "THE FOLLOWING STAFF APPEAR IN THE UNIVERSITY'S API, BUT NOT IN WAGTAIL:"
            )
            output = output + list(missing_in_wagtail)
            # if this happens, report that a new user needs to be created.

        for s in sorted(list(api_staff.intersection(wag_staff))):
            xml_string = xml_string = get_xml_from_directory_api(
                'https://directory.uchicago.edu/api/v2/individuals/' + s +
                '.xml')
            api = get_individual_info_from_directory(xml_string)
            wag = get_individual_info_from_wagtail(s)

            if not api['officialName'] == wag['officialName']:
                output.append(s + "'s officialName is " + api['officialName'] +
                              ", not " + wag['officialName'])

            if not api['displayName'] == wag['displayName']:
                output.append(s + "'s displayName is " + api['displayName'] +
                              ", not " + wag['displayName'])
                # In the user management command, change the following things in the User object:
                # (note- in the User object, username = cnetid)
                # prompt a human for first_name, last_name.
                # In the StaffPage object,
                # check displayName and officialName.

            diffs = api['title_department_subdepartments'].difference(
                wag['title_department_subdepartments'])
            if diffs:
                output.append("THE FOLLOWING VCARDS APPEAR FOR " + s +
                              " IN THE UNIVERSITY'S API, BUT NOT IN WAGTAIL:")
                for d in diffs:
                    output.append(d)

            diffs = wag['title_department_subdepartments'].difference(
                api['title_department_subdepartments'])
            if diffs:
                output.append("THE FOLLOWING VCARDS APPEAR FOR " + s +
                              " IN WAGTAIL, BUT NOT IN THE UNIVERSITY'S API:")
                for d in diffs:
                    output.append(d)

        return "\n".join(output)