Esempio n. 1
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),
                )
            ],
        )
Esempio n. 2
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),
                ),
            ],
        )
    ]
Esempio n. 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)
Esempio n. 4
0
def test_create_ticket(ticket_app: TicketsApplication):
    ticket = ticket_app.create_ticket()
    assert AssertableTicket.from_model(ticket) == AssertableTicket(
        id=any_instance_of(str),
        name=None,
        description=None,
        updated_at=any_instance_of(str),
        history=[],
    )
Esempio n. 5
0
def test_get_tickets_when_multiple_created(snapshot,
                                           ticket_app: TicketsApplication,
                                           graphql_context: Context):
    ticket_app.create_ticket(name="My first ticket")
    ticket_app.create_ticket(name="My second ticket")
    client = Client(schema,
                    context=graphql_context,
                    format_error=raise_original_error)
    get_tickets = """
        query {
            tickets {
                name
                description
                updatedAt
            }
        }
    """

    executed = client.execute(get_tickets, variables={})
    snapshot.assert_match(executed)
Esempio n. 6
0
def test_get_tickets_when_two_created(ticket_app: TicketsApplication):
    with freeze_time("2012-01-14"):
        ticket_app.create_ticket(name="first ticket")
    with freeze_time("2012-01-15"):
        ticket_app.create_ticket(name="second ticket")

    assert tickets_as_assertable_tickets(ticket_app.get_tickets()) == [
        AssertableTicket(
            id=any_instance_of(str),
            name="first ticket",
            description=None,
            updated_at="2012-01-14T00:00:00",
            history=[],
        ),
        AssertableTicket(
            id=any_instance_of(str),
            name="second ticket",
            description=None,
            updated_at="2012-01-15T00:00:00",
            history=[],
        ),
    ]
def test_delete_ticket(snapshot, ticket_app: TicketsApplication,
                       graphql_context: Context):
    client = Client(schema,
                    context=graphql_context,
                    format_error=raise_original_error)
    ticket = ticket_app.create_ticket(name="My ticket")

    delete_ticket = """
        mutation ($id: ID!) {
            deleteTicket(id: $id) {
                ok
            }
        }
    """
    executed = client.execute(delete_ticket, variables={"id": str(ticket.id)})

    assert executed["data"]["deleteTicket"]["ok"]
    snapshot.assert_match(get_latest_ticket_as_dict(ticket_app, ticket))
Esempio n. 8
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),
            )
        ],
    )
Esempio n. 9
0
def test_clone_ticket(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)

    assert original_ticket_id != new_ticket_id
    assert AssertableTicket.from_model(new_ticket) == 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),
            )
        ],
    )
def test_rename_ticket(snapshot, ticket_app: TicketsApplication,
                       graphql_context: Context):
    client = Client(schema,
                    context=graphql_context,
                    format_error=raise_original_error)
    ticket = ticket_app.create_ticket(name="My ticket")

    create_ticket = """
        mutation ($id: ID!, $name: String!) {
            renameTicket(id: $id, name: $name) {
                ok
            }
        }
    """
    executed = client.execute(create_ticket,
                              variables={
                                  "id": str(ticket.id),
                                  "name": "testing ticket"
                              })

    assert executed["data"]["renameTicket"]["ok"]
    snapshot.assert_match(get_latest_ticket_as_dict(ticket_app, ticket))
Esempio n. 11
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)
def test_update_ticket_description(snapshot, ticket_app: TicketsApplication,
                                   graphql_context: Context):
    client = Client(schema,
                    context=graphql_context,
                    format_error=raise_original_error)
    ticket = ticket_app.create_ticket(name="My ticket")

    create_ticket = """
        mutation ($id: ID!, $description: String!) {
            updateTicketDescription(id: $id, description: $description) {
                ok
            }
        }
    """
    executed = client.execute(
        create_ticket,
        variables={
            "id": str(ticket.id),
            "description": "updated description"
        },
    )

    assert executed["data"]["updateTicketDescription"]["ok"]
    snapshot.assert_match(get_latest_ticket_as_dict(ticket_app, ticket))
def test_clone_ticket(snapshot, ticket_app: TicketsApplication,
                      graphql_context: Context):
    client = Client(schema,
                    context=graphql_context,
                    format_error=raise_original_error)
    original_ticket = ticket_app.create_ticket(name="My ticket")
    original_ticket_id = str(original_ticket.id)

    delete_ticket = """
        mutation ($id: ID!) {
            cloneTicket(id: $id) {
                ok
                ticket {
                    name
                    description
                    history {
                        __typename
                        timestamp
                        ... on TicketFieldUpdated {
                            field
                            oldValue
                            newValue
                        }
                        ... on TicketCloned {
                            originalTicketName
                        }
                    }
                }
            }
        }
    """
    executed = client.execute(delete_ticket,
                              variables={"id": original_ticket_id})

    assert executed["data"]["cloneTicket"]["ok"]
    snapshot.assert_match(executed)
Esempio n. 14
0
def test_delete_ticket(ticket_app: TicketsApplication):
    ticket = ticket_app.create_ticket()
    ticket_id = str(ticket.id)

    ticket_app.delete_ticket(ticket_id)
    assert ticket_app.get_ticket(ticket_id) is None
Esempio n. 15
0
def test_get_tickets_with_deleted_tickets(ticket_app: TicketsApplication):
    ticket = ticket_app.create_ticket()
    ticket_id = str(ticket.id)
    ticket_app.delete_ticket(ticket_id)

    assert ticket_app.get_tickets() == []