Example #1
0
def test_get_tickets_with_multiple_commands(ticket_app: TicketsApplication):
    with freeze_time("2012-01-14"):
        ticket = ticket_app.create_ticket(name="original name")
        ticket_id = str(ticket.id)
    with freeze_time("2012-01-15"):
        ticket_app.rename_ticket(ticket_id, "new ticket name")
        ticket_app.update_ticket_description(ticket_id,
                                             "new ticket description")

    assert tickets_as_assertable_tickets(ticket_app.get_tickets()) == [
        AssertableTicket(
            id=any_instance_of(str),
            name="new ticket name",
            description="new ticket description",
            updated_at="2012-01-15T00:00:00",
            history=[
                TicketFieldUpdated(
                    field="name",
                    old_value="original name",
                    new_value="new ticket name",
                    timestamp=datetime(year=2012, month=1, day=15),
                ),
                TicketFieldUpdated(
                    field="description",
                    old_value=None,
                    new_value="new ticket description",
                    timestamp=datetime(year=2012, month=1, day=15),
                ),
            ],
        )
    ]
Example #2
0
def test_clone_ticket_are_not_impacted_by_changes_to_the_original(
        ticket_app: TicketsApplication):
    original_ticket = ticket_app.create_ticket(
        name="Original ticket name", description="Original ticket description")
    original_ticket_id = str(original_ticket.id)

    new_ticket = ticket_app.clone_ticket(id=original_ticket_id)
    new_ticket_id = str(new_ticket.id)
    ticket_app.rename_ticket(id=original_ticket_id, name="New ticket name")

    new_ticket_reloaded = ticket_app.get_ticket(new_ticket_id)

    assert original_ticket_id != str(new_ticket.id)
    assert AssertableTicket.from_model(
        new_ticket_reloaded) == AssertableTicket(
            id=any_instance_of(str),
            name="CLONED - Original ticket name",
            description="Original ticket description",
            updated_at=any_instance_of(str),
            history=[
                TicketCloned(
                    original_ticket_id=original_ticket_id,
                    original_ticket_name="Original ticket name",
                    timestamp=any_instance_of(datetime),
                )
            ],
        )
Example #3
0
def test_get_ticket(snapshot, ticket_app: TicketsApplication,
                    graphql_context: Context):
    ticket = ticket_app.create_ticket(name="My ticket",
                                      description="My ticket description")
    ticket_app.rename_ticket(str(ticket.id), "Ticket renamed")
    ticket_app.update_ticket_description(str(ticket.id),
                                         "New ticket description")
    client = Client(schema,
                    context=graphql_context,
                    format_error=raise_original_error)
    get_ticket = """
        query ($id: ID!) {
            ticket(id: $id) {
                name
                description
                updatedAt
                history {
                    __typename
                    timestamp
                    ... on TicketFieldUpdated {
                        field
                        oldValue
                        newValue
                    }
                    ... on TicketCloned {
                        originalTicketId
                        originalTicketName
                    }
                }
            }
        }
    """

    executed = client.execute(get_ticket, variables={"id": str(ticket.id)})
    snapshot.assert_match(executed)
Example #4
0
def test_rename_ticket(ticket_app: TicketsApplication):
    ticket = ticket_app.create_ticket()
    ticket_id = str(ticket.id)
    ticket_app.rename_ticket(id=ticket_id, name="New ticket name")

    saved = ticket_app.repository[ticket_id]
    assert AssertableTicket.from_model(saved) == AssertableTicket(
        id=any_instance_of(str),
        name="New ticket name",
        description=None,
        updated_at=any_instance_of(str),
        history=[
            TicketFieldUpdated(
                field="name",
                old_value=None,
                new_value="New ticket name",
                timestamp=any_instance_of(datetime),
            )
        ],
    )
Example #5
0
def test_get_cloned_ticket(snapshot, ticket_app: TicketsApplication,
                           graphql_context: Context):
    original_ticket = ticket_app.create_ticket(
        name="My ticket", description="My ticket description")
    original_ticket_id = str(original_ticket.id)
    ticket_app.rename_ticket(original_ticket_id, "Original ticket name")
    ticket_app.update_ticket_description(original_ticket_id,
                                         "Original ticket description")
    new_ticket = ticket_app.clone_ticket(id=original_ticket_id)
    new_ticket_id = str(new_ticket.id)
    ticket_app.rename_ticket(id=new_ticket_id, name="New ticket name")

    client = Client(schema,
                    context=graphql_context,
                    format_error=raise_original_error)
    get_ticket = """
        query ($id: ID!) {
            ticket(id: $id) {
                name
                description
                updatedAt
                history {
                    __typename
                    ... on TicketFieldUpdated {
                        field
                        oldValue
                        newValue
                    }
                    ... on TicketCloned {
                        originalTicketName
                    }
                }
            }
        }
    """

    executed = client.execute(get_ticket, variables={"id": new_ticket_id})
    snapshot.assert_match(executed)