Beispiel #1
0
def get_use_case_associated_requirements(uc_id):
    """Returns a list of all the requirement IDs that are associated to the
    use case with the given ID.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).one()
        return [r.req_id for r in uc.requirements]
def update_requirement_description(req_id, description):
    """Updates the description of the requirement with the given ID.
    """
    with db.get_session() as session:
        requirement = session.query(Requirement).filter(
            Requirement.req_id == req_id).one()
        requirement.description = description
def get_use_case(uc_id):
    """Converts the given use case ID to the corresponding transfer object.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).scalar()
        session.expunge_all()
        return uc
Beispiel #4
0
def _is_uc_existing(uc_id):
    """Returns True if a use case with the given ID has already been saved,
    False otherwise.
    """
    with db.get_session() as session:
        count = session.query(UseCase).filter(UseCase.uc_id == uc_id).count()
        return count != 0
def get_source_id(source_name):
    """Converts between a source name and a source ID (possible because
    names are under a unique constraint and can be used as super-keys).
    """
    with db.get_session() as session:
        return session.query(
            Source.source_id).filter(Source.name == source_name).scalar()
def update_source_name(source_id, source_name):
    """Changes to the given source name the source with the given ID.
    """
    with db.get_session() as session:
        source = session.query(Source).filter(
            Source.source_id == source_id).one()
        source.name = source_name
def get_use_case_associated_requirements(uc_id):
    """Returns a list of all the requirement IDs that are associated to the
    use case with the given ID.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).one()
        return [r.req_id for r in uc.requirements]
def get_source_id(source_name):
    """Converts between a source name and a source ID (possible because
    names are under a unique constraint and can be used as super-keys).
    """
    with db.get_session() as session:
        return session.query(Source.source_id).filter(
                Source.name == source_name).scalar()
def update_source_name(source_id, source_name):
    """Changes to the given source name the source with the given ID.
    """
    with db.get_session() as session:
        source = session.query(Source).filter(
                Source.source_id == source_id).one()
        source.name = source_name
def _is_uc_existing(uc_id):
    """Returns True if a use case with the given ID has already been saved,
    False otherwise.
    """
    with db.get_session() as session:
        count = session.query(UseCase).filter(UseCase.uc_id == uc_id).count()
        return count != 0
def update_requirement_id(req_id, new_req_id):
    """Updates the ID of the requirement with the given ID, reflecting the
    change in the association tables if needed.
    """
    with db.get_session() as session:
        requirement = session.query(Requirement).filter(
            Requirement.req_id == req_id).one()
        requirement.req_id = new_req_id
        session.execute(
            'UPDATE UseCasesRequirements '
            'SET req_id = :new_req_id WHERE req_id = :req_id', {
                'new_req_id': new_req_id,
                'req_id': req_id
            })
        session.execute(
            'UPDATE RequirementsTests '
            'SET req_id = :new_req_id WHERE req_id = :req_id', {
                'new_req_id': new_req_id,
                'req_id': req_id
            })
        session.execute(
            'UPDATE Requirements set parent_id = :new_req_id '
            ' WHERE parent_id = :req_id', {
                'new_req_id': new_req_id,
                'req_id': req_id
            })
def update_use_case_parent_id(uc_id, parent_id):
    """Reassign the use case with the given ID to the new parent corresponding
    to the given parent ID.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).one()
        uc.parent_id = parent_id
def update_requirement_parent_id(req_id, parent_id):
    """Assigns a new parent to the requirement with the given ID.
    """
    with db.get_session() as session:
        requirement = session.query(Requirement).filter(
            Requirement.req_id == req_id).one()
        requirement.parent_id = parent_id
Beispiel #14
0
def update_use_case_parent_id(uc_id, parent_id):
    """Reassign the use case with the given ID to the new parent corresponding
    to the given parent ID.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).one()
        uc.parent_id = parent_id
def update_test_description(test_id, description):
    """Updates the description of the test with the given ID.
    """
    with db.get_session() as session:
        test = session.query(SystemTest).filter(
                SystemTest.test_id == test_id).one()
        test.description = description
Beispiel #16
0
def get_use_case(uc_id):
    """Converts the given use case ID to the corresponding transfer object.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).scalar()
        session.expunge_all()
        return uc
def get_source(source_id):
    """Returns the source TO that corresponds to the given source ID.
    """
    with db.get_session() as session:
        source = session.query(Source).filter(
            Source.source_id == source_id).one()
        session.expunge_all()
        return source
def get_source(source_id):
    """Returns the source TO that corresponds to the given source ID.
    """
    with db.get_session() as session:
        source = session.query(Source).filter(
                Source.source_id == source_id).one()
        session.expunge_all()
        return source
def get_test(test_id):
    """Converts a test ID to the corresponding (detached) transfer object.
    """
    with db.get_session() as session:
        test = session.query(SystemTest).filter(
                SystemTest.test_id == test_id).scalar()
        session.expunge_all()
        return test
def get_top_level_use_case_ids():
    """Returns a list of all those use case IDs corresponding to items that
    have no parent (top level items).
    """
    with db.get_session() as session:
        return [uc[0] for uc in
                session.query(UseCase.uc_id).filter(
                UseCase.parent_id == None).order_by(UseCase.uc_id)]
def get_use_case_children_ids(uc_id):
    """Returns the list of use case ID corresponding to the children of the
    use case with the given ID (empty list if it has no children at all).
    """
    with db.get_session() as session:
        return [uc[0] for uc in
                session.query(UseCase.uc_id).filter(
                UseCase.parent_id == uc_id).order_by(UseCase.uc_id)]
def _is_requirement_existing(req_id):
    """Returns True if a requirement with the given ID has already been created
    and False otherwise.
    """
    with db.get_session() as session:
        count = session.query(Requirement).filter(
            Requirement.req_id == req_id).count()
        return count != 0
def update_requirement_type(req_id, req_type):
    """Updates the type of the requirement with the given ID.
    """
    assert req_type in TYPE_LIST
    with db.get_session() as session:
        requirement = session.query(Requirement).filter(
            Requirement.req_id == req_id).one()
        requirement.req_type = req_type
def update_requirement_priority(req_id, priority):
    """Updates the priority of the requirement with the given ID.
    """
    assert priority in PRIORITY_LIST
    with db.get_session() as session:
        requirement = session.query(Requirement).filter(
            Requirement.req_id == req_id).one()
        requirement.priority = priority
def get_requirement(req_id):
    """Converts a requirement ID to the given transfer object.
    """
    with db.get_session() as session:
        requirement = session.query(Requirement).filter(
            Requirement.req_id == req_id).scalar()
        session.expunge_all()
        return requirement
def get_all_uc_names_and_descriptions():
    """Returns a list of dictionaries containing the 'id' and 'description'
    keys that can be used to create a UseCaseListModel for some requirement.
    """
    with db.get_session() as session:
        return [{'id': uc[0], 'description': uc[1]}
                for uc in session.query(UseCase.uc_id,
                UseCase.description).order_by(UseCase.uc_id)]
Beispiel #27
0
def create_use_case(uc_id, description, image=None, parent_id=None):
    """Creates a new use case with the given ID, description and parent.
    """
    if parent_id and not _is_uc_existing(parent_id):
        raise Exception('Nonexistent parent')
    with db.get_session() as session:
        uc = UseCase(uc_id, description, image, parent_id)
        session.add(uc)
def create_use_case(uc_id, description, image=None, parent_id=None):
    """Creates a new use case with the given ID, description and parent.
    """
    if parent_id and not _is_uc_existing(parent_id):
        raise Exception('Nonexistent parent')
    with db.get_session() as session:
        uc = UseCase(uc_id, description, image, parent_id)
        session.add(uc)
def update_requirement_source(req_id, source_name):
    """Updates the source of the requirement with the given ID.
    """
    with db.get_session() as session:
        requirement = session.query(Requirement).filter(
            Requirement.req_id == req_id).one()
        source = session.query(Source).filter(Source.name == source_name).one()
        requirement.source = source
def delete_test(test_id):
    """Deletes the test with the given test ID, removing also all the entries
    from the association table linking tests and requirements.
    """
    with db.get_session() as session:
        session.query(SystemTest).filter(
                SystemTest.test_id == test_id).delete()
        session.execute('DELETE FROM RequirementsTests '
                'WHERE test_id = :test_id', {'test_id': test_id})
def get_all_test_names_and_descriptions():
    """Returns a list of dictionaries containing the 'id' and 'description'
    keys corresponding to the information about all the registered tests.
    """
    with db.get_session() as session:
        return [{'id': test[0], 'description': test[1]}
                for test in
                session.query(SystemTest.test_id,
                SystemTest.description).order_by(SystemTest.test_id)]
def get_all_requirement_ids_spec(req_type, priority):
    """Returns the list of requirement IDs having the given type and priority.
    """
    with db.get_session() as session:
        return [
            r[0] for r in session.query(Requirement.req_id).filter(
                Requirement.req_type == req_type, Requirement.priority ==
                priority)
        ]
def delete_use_case(uc_id):
    """Deletes the use case with the given ID.
    """
    with db.get_session() as session:
        session.query(UseCase).filter(UseCase.uc_id == uc_id).delete()
        session.execute('UPDATE UseCases SET parent_id = NULL '
                'WHERE parent_id = :uc_id', {'uc_id': uc_id})
        session.execute('DELETE FROM UseCasesRequirements '
                'WHERE uc_id = :uc_id', {'uc_id': uc_id})
Beispiel #34
0
def get_top_level_use_case_ids():
    """Returns a list of all those use case IDs corresponding to items that
    have no parent (top level items).
    """
    with db.get_session() as session:
        return [
            uc[0] for uc in session.query(UseCase.uc_id).filter(
                UseCase.parent_id == None).order_by(UseCase.uc_id)
        ]
Beispiel #35
0
def get_use_case_children_ids(uc_id):
    """Returns the list of use case ID corresponding to the children of the
    use case with the given ID (empty list if it has no children at all).
    """
    with db.get_session() as session:
        return [
            uc[0] for uc in session.query(UseCase.uc_id).filter(
                UseCase.parent_id == uc_id).order_by(UseCase.uc_id)
        ]
def get_top_level_requirement_ids():
    """Returns the list of all those IDs that correspond to top-level
    requirements, i.e. requirements having no parent.
    """
    with db.get_session() as session:
        return [
            req[0] for req in session.query(Requirement.req_id).filter(
                Requirement.parent_id == None).order_by(Requirement.req_id)
        ]
def get_requirement_children_ids(req_id):
    """Returns a list of IDs corresponding to the children of the requirement
    with the given ID.
    """
    with db.get_session() as session:
        return [
            req[0] for req in session.query(Requirement.req_id).filter(
                Requirement.parent_id == req_id).order_by(Requirement.req_id)
        ]
def get_all_requirement_names_and_descriptions():
    """Returns a list of dictionaries containing the 'id' and 'description'
    keys corresponding to all the requirements that have been created.
    """
    with db.get_session() as session:
        return [{
            'id': req[0],
            'description': req[1]
        } for req in session.query(Requirement.req_id, Requirement.description
                                   ).order_by(Requirement.req_id)]
Beispiel #39
0
def get_all_uc_names_and_descriptions():
    """Returns a list of dictionaries containing the 'id' and 'description'
    keys that can be used to create a UseCaseListModel for some requirement.
    """
    with db.get_session() as session:
        return [{
            'id': uc[0],
            'description': uc[1]
        } for uc in session.query(UseCase.uc_id, UseCase.description).order_by(
            UseCase.uc_id)]
Beispiel #40
0
def delete_use_case(uc_id):
    """Deletes the use case with the given ID.
    """
    with db.get_session() as session:
        session.query(UseCase).filter(UseCase.uc_id == uc_id).delete()
        session.execute(
            'UPDATE UseCases SET parent_id = NULL '
            'WHERE parent_id = :uc_id', {'uc_id': uc_id})
        session.execute(
            'DELETE FROM UseCasesRequirements '
            'WHERE uc_id = :uc_id', {'uc_id': uc_id})
def update_test_id(test_id, new_test_id):
    """Updates the ID of a system test. It raises IntegrityError if the
    provided new ID conflicts with the one some other already existing test.
    """
    with db.get_session() as session:
        test = session.query(SystemTest).filter(
                SystemTest.test_id == test_id).one()
        test.test_id = new_test_id
        session.execute('UPDATE RequirementsTests '
                'SET test_id = :new_test_id WHERE test_id = :test_id',
                {'new_test_id': new_test_id, 'test_id': test_id})
def update_use_case_id(uc_id, new_uc_id):
    """Updates the use case ID to a new value, raising IntegrityError if the
    operation cannot be performed due to primary key conflicts.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).one()
        uc.uc_id = new_uc_id
        session.execute('UPDATE UseCasesRequirements '
                'SET uc_id = :new_uc_id WHERE uc_id = :uc_id',
                {'new_uc_id': new_uc_id, 'uc_id': uc_id})
        session.execute('UPDATE UseCases set parent_id = :new_uc_id '
                ' WHERE parent_id = :uc_id', {'new_uc_id': new_uc_id,
                'uc_id': uc_id})
def create_requirement(req_id,
                       description,
                       req_type,
                       priority,
                       source_id,
                       parent_id=None):
    """Creates a new requirement with the information provided.
    """
    if parent_id and not _is_requirement_existing(parent_id):
        raise Exception('Nonexistent parent')
    with db.get_session() as session:
        requirement = Requirement(req_id, description, req_type, priority,
                                  source_id, parent_id)
        session.add(requirement)
def update_use_case_associations(uc_id, newly_associated_requirements):
    """Updates the association between use case and requirement starting from
    the ID of the base use case and a list of IDs of the requirements involved.
    It determines which entries must be added to and which must be removed from
    the association table and updates its content accordingly.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).one()
        newly_associated_requirements = set(newly_associated_requirements)
        associated_requirements = set([req.req_id for req in uc.requirements])
        # determines entries to be added
        ids_to_add = newly_associated_requirements - associated_requirements
        for req_id in ids_to_add:
            req = session.query(Requirement).filter(
                    Requirement.req_id == req_id).one()
            uc.requirements.append(req)
        # determines entries to be removed
        ids_to_remove = associated_requirements - newly_associated_requirements
        for req_id in ids_to_remove:
            req = session.query(Requirement).filter(
                    Requirement.req_id == req_id).one()
            uc.requirements.remove(req)
def update_test_associations(test_id, newly_associated_requirements):
    """Updates the association between tests and requirement starting from the
    ID of the base test and a list of IDs of the requirements involved. It
    determines which entries must be added to and which must be removed from
    the association table and updates its content accordingly.
    """
    with db.get_session() as session:
        test = session.query(SystemTest).filter(
                SystemTest.test_id == test_id).one()
        newly_associated_requirements = set(newly_associated_requirements)
        associated_requirements = set([req.req_id
                for req in test.requirements])
        # determines entries to add
        ids_to_add = newly_associated_requirements - associated_requirements
        for req_id in ids_to_add:
            req = session.query(Requirement).filter(
                    Requirement.req_id == req_id).one()
            test.requirements.append(req)
        # determines entries to remove
        ids_to_remove = associated_requirements - newly_associated_requirements
        for req_id in ids_to_remove:
            req = session.query(Requirement).filter(
                    Requirement.req_id == req_id).one()
            test.requirements.remove(req)
def get_all_use_case_ids():
    """Returns a list of all the registered use case IDs.
    """
    with db.get_session() as session:
        return [e[0] for e in session.query(UseCase.uc_id)]
def get_all_source_ids():
    """Returns a list of all the source IDs that are used in the system.
    """
    with db.get_session() as session:
        return [s[0] for s in session.query(Source.source_id)]
def delete_source(source_id):
    """Deletes the requirement source with the given ID.
    """
    with db.get_session() as session:
        session.query(Source).filter(Source.source_id == source_id).delete()
def get_all_test_ids():
    """Returns a list of the IDsof all tests.
    """
    with db.get_session() as session:
        return [t[0] for t in session.query(SystemTest.test_id)]
def create_source(source_name):
    """Creates a new requirement source with the given name.
    """
    with db.get_session() as session:
        source = Source(source_name)
        session.add(source)
def update_use_case_description(uc_id, description):
    """Updates the description of the use case with the given ID.
    """
    with db.get_session() as session:
        uc = session.query(UseCase).filter(UseCase.uc_id == uc_id).one()
        uc.description = description
def create_test(test_id, description):
    """Creates a new system test with the given ID and description.
    """
    with db.get_session() as session:
        test = SystemTest(test_id, description)
        session.add(test)
def get_all_source_names():
    """Returns a list of all the names of the sources used in the system.
    """
    with db.get_session() as session:
        return [s[0] for s in session.query(Source.name)]