def test_tref_ticket_created_with_field(env):
    target = create_ticket(env)
    ticket = Ticket(env)
    ticket["summary"] = u"has %s field" % TICKETREF
    ticket[TICKETREF] = u"%s" % target.id
    ticket.insert()  # called TicketRefsPlugin.ticket_created()
    assert ticket.exists
    target = Ticket(env, target.id)
    assert target[TICKETREF] == u"%s" % ticket.id
def test_tref_ticket_created_with_desc(env):
    target = create_ticket(env)
    ticket = Ticket(env)
    ticket["summary"] = u"reference in description"
    ticket["description"] = "refs #%s" % target.id
    ticket.insert()  # called TicketRefsPlugin.ticket_created()
    assert ticket.exists
    target = Ticket(env, target.id)
    assert target[TICKETREF] == u"%s" % ticket.id
def test_tref_validate_ticket(env, tref, value, expected_msg):
    ticket = create_ticket(env)
    ticket[TICKETREF] = value
    expected_field = env.config.get("ticket-custom", "ticketref.label")
    for field, msg in tref.validate_ticket(None, ticket):
        assert expected_field == field and expected_msg == msg
        break
    else:
        assert False
def test_tref_validate_ticket_with_own_id(env, tref):
    ticket = create_ticket(env)
    ticket[TICKETREF] = u"%s" % ticket.id
    expected_field = env.config.get("ticket-custom", "ticketref.label")
    expected_msg = "Ticket %s is this ticket ID, remove it." % ticket.id
    for field, msg in tref.validate_ticket(None, ticket):
        assert expected_field == field and expected_msg == msg
        break
    else:
        assert False
def test_tref_has_ticket_refs(env, tref):
    ticket = create_ticket(env)
    assert not tref.has_ticket_refs(ticket)
    ticket[TICKETREF] = u"1"
    assert tref.has_ticket_refs(ticket)