Пример #1
0
def generate_working_units():
    """Create working units for testing."""
    person1, person2, person3 = generate_persons()

    return [WorkingUnit(name="project1",
                        description="My description",
                        overview_document="overview_document",
                        unit_type=UnitType.project,
                        status=UnitStatus.perfect,
                        person_responsible=person1,
                        participants=[person3]),
            WorkingUnit(name="",
                        description="",
                        overview_document="",
                        unit_type=UnitType.project,
                        status=None,
                        person_responsible=person2,
                        participants=[]),
            WorkingUnit(name="Support Unit Master",
                        description="A cool unit.",
                        overview_document="http://example.org",
                        unit_type=UnitType.support_unit,
                        status=UnitStatus.ok,
                        person_responsible=person1,
                        participants=[person2]),
            WorkingUnit(name="Another support unit",
                        description="Hello World",
                        overview_document="Hello Document",
                        person_responsible=person3,
                        unit_type=UnitType.support_unit,
                        status=UnitStatus.problems,
                        participants=[person1, person2])]
Пример #2
0
def parse_working_unit(xml, persons):
    """Parse a working unit defined by XML specification `xml`."""
    category_id = xml_text(xml_find("category-id", xml))

    if category_id == PROJECT_ID:
        unit_type = UnitType.project
    elif category_id == SUPPORT_UNIT_ID:
        unit_type = UnitType.support_unit
    else:
        return None

    if xml_text(xml_find("status", xml)) != "pending":
        return None

    subject_datas = parse_subject_datas(xml)

    overview_document = subject_datas.get(SUBJECT_DATA_OVERVIEW, "")
    storage_url = subject_datas.get(SUBJECT_DATA_STORAGE, "")
    status = subject_datas.get(SUBJECT_DATA_STATUS, None)

    if status == "we are ahead of our schedule":
        status = UnitStatus.perfect
    elif status == "we are in line with our schedule":
        status = UnitStatus.ok
    elif status == "we are behind schedule":
        status = UnitStatus.problems
    else:
        status = None

    try:
        person_responsible = persons[xml_text(xml_find("party-id", xml))]
    except KeyError:
        # TODO: write unittests for this exception
        return None

    participant_ids = [
        xml_text(xml_find("id", x)) for x in xml_find("parties", xml)
    ]

    return WorkingUnit(
        name=xml_text(xml_find("name", xml)),
        description=xml_text(xml_find("background", xml)),
        overview_document=overview_document,
        storage_url=storage_url,
        status=status,
        unit_type=unit_type,
        person_responsible=person_responsible,
        participants=[persons[x] for x in participant_ids if x in persons])