def test_sequences(seq):
    seqname = "foo"
    assert not seq.exists(seqname)

    # Create and check values
    seq.create(seqname)
    assert seq.exists(seqname)
    assert seq.next_value(seqname) == 1
    assert seq.next_value(seqname) == 2

    # Delete sequence
    seq.delete(seqname)
    assert not seq.exists(seqname)

    # Create new seq with same name
    # after previously deleted it
    seq.create(seqname)
    assert seq.next_value(seqname) == 1

    # Alter sequence
    seq.alter(seqname, 4)
    assert seq.next_value(seqname) == 5

    # Delete after alter
    seq.delete(seqname)
    assert not seq.exists(seqname)
def test_unique_reference_per_project(seq, refmodels):
    refmodels.Reference.objects.all().delete()

    project = factories.ProjectFactory.create()
    seqname = refmodels.make_sequence_name(project)

    assert seqname == "references_project{0}".format(project.id)
    assert seq.exists(seqname)

    assert refmodels.make_unique_reference_id(project, create=True) == 1
    assert refmodels.make_unique_reference_id(project, create=True) == 2

    project.delete()
    assert not seq.exists(seqname)
Ejemplo n.º 3
0
def store_issue(project, data):
    validator = validators.IssueExportValidator(data=data, context={"project": project})

    if "type" not in data and project.default_issue_type:
        data["type"] = project.default_issue_type.name

    if "status" not in data and project.default_issue_status:
        data["status"] = project.default_issue_status.name

    if "priority" not in data and project.default_priority:
        data["priority"] = project.default_priority.name

    if "severity" not in data and project.default_severity:
        data["severity"] = project.default_severity.name

    if validator.is_valid():
        validator.object.project = project
        if validator.object.owner is None:
            validator.object.owner = validator.object.project.owner
        validator.object._importing = True
        validator.object._not_notify = True

        validator.save()
        validator.save_watchers()

        if validator.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, validator.object.ref)
        else:
            validator.object.ref, _ = refs.make_reference(validator.object, project)
            validator.object.save()

        for attachment in data.get("attachments", []):
            _store_attachment(project, validator.object, attachment)

        history_entries = data.get("history", [])
        statuses = {s.name: s.id for s in project.issue_statuses.all()}
        for history in history_entries:
            _store_history(project, validator.object, history, statuses)

        if not history_entries:
            take_snapshot(validator.object, user=validator.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = validator.object.project.issuecustomattributes.all().values('id', 'name')
            custom_attributes_values = \
                _use_id_instead_name_as_key_in_custom_attributes_values(custom_attributes,
                                                                        custom_attributes_values)
            _store_custom_attributes_values(validator.object, custom_attributes_values,
                                            "issue",
                                            validators.IssueCustomAttributesValuesExportValidator)

        return validator

    add_errors("issues", validator.errors)
    return None
Ejemplo n.º 4
0
def store_user_story(project, data):
    if "status" not in data and project.default_us_status:
        data["status"] = project.default_us_status.name

    us_data = {key: value for key, value in data.items() if key not in
               ["role_points", "custom_attributes_values", 'generated_from_task', 'generated_from_issue']}

    validator = validators.UserStoryExportValidator(data=us_data, context={"project": project})

    if validator.is_valid():
        validator.object.project = project
        if validator.object.owner is None:
            validator.object.owner = validator.object.project.owner
        validator.object._importing = True
        validator.object._not_notify = True

        validator.save()
        validator.save_watchers()

        if validator.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, validator.object.ref)
        else:
            validator.object.ref, _ = refs.make_reference(validator.object, project)
            validator.object.save()

        for us_attachment in data.get("attachments", []):
            _store_attachment(project, validator.object, us_attachment)

        for role_point in data.get("role_points", []):
            _store_role_point(project, validator.object, role_point)

        history_entries = data.get("history", [])
        statuses = {s.name: s.id for s in project.us_statuses.all()}
        for history in history_entries:
            _store_history(project, validator.object, history, statuses)

        if not history_entries:
            take_snapshot(validator.object, user=validator.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = validator.object.project.userstorycustomattributes.all().values('id', 'name')
            custom_attributes_values = \
                _use_id_instead_name_as_key_in_custom_attributes_values(custom_attributes,
                                                                        custom_attributes_values)

            _store_custom_attributes_values(validator.object, custom_attributes_values,
                                            "user_story",
                                            validators.UserStoryCustomAttributesValuesExportValidator)

        return validator

    add_errors("user_stories", validator.errors)
    return None