示例#1
0
def test_user_search_returns_data_only_for_the_requested_search_value():
    UserFactory()
    UserFactory()
    user = UserFactory()

    search = Search(search_term='_id', search_value=user._id)
    qs = search.search_users()

    assert len(qs) == 1
    assert qs[0]._id == user._id
    assert qs[0].url == user.url
    assert qs[0].external_id == user.external_id
    assert qs[0].name == user.name
    assert qs[0].alias == user.alias
    assert qs[0].created_at == user.created_at
    assert qs[0].active == user.active
    assert qs[0].verified == user.verified
    assert qs[0].shared == user.shared
    assert qs[0].locale == user.locale
    assert qs[0].timezone == user.timezone
    assert qs[0].last_login_at == user.last_login_at
    assert qs[0].email == user.email
    assert qs[0].phone == user.phone
    assert qs[0].signature == user.signature
    assert qs[0].organization_id == user.organization_id
    assert qs[0].tags == user.tags
    assert qs[0].suspended == user.suspended
    assert qs[0].role == user.role
    assert qs[0].submitted_tickets.count() == 0
    assert qs[0].assigned_tickets.count() == 0
def test_search_organizations(capsys):
    organization = OrganizationFactory()
    UserFactory(organization_id=organization)
    TicketFactory(organization_id=organization)

    controller = AppController()
    controller.search_term = '_id'
    controller.search_value = organization._id
    controller.search = Search(controller.search_term, controller.search_value)
    controller.search_organizations()

    captured = capsys.readouterr()

    assert (
        f'Searching organizations for {controller.search_term} with a value of {controller.search_value}'
    ) in captured.out

    assert '_id' in captured.out
    assert 'url' in captured.out
    assert 'name' in captured.out
    assert 'domain_names' in captured.out
    assert 'created_at' in captured.out
    assert 'details' in captured.out
    assert 'shared_tickets' in captured.out
    assert 'tags' in captured.out
    assert 'user_id' in captured.out
    assert 'user_name' in captured.out
    assert 'ticket_id' in captured.out
    assert 'ticket_subject' in captured.out
示例#3
0
def test_user_search_is_case_insensitive():
    UserFactory(role='admin')

    search = Search(search_term='role', search_value='ADMIN')
    qs = search.search_users()

    assert len(qs) == 1
    assert qs[0].role == 'admin'
示例#4
0
def test_user_search_returns_data_partially_matching_requested_search_value():
    UserFactory(role='admin')

    search = Search(search_term='role', search_value='adm')
    qs = search.search_users()

    assert len(qs) == 1
    assert qs[0].role == 'admin'
示例#5
0
def test_user_search_using_foreign_key_organization_id_as_search_term():
    user = UserFactory()

    search = Search(search_term='organization_id', search_value=user.organization_id._id)
    qs = search.search_users()

    assert len(qs) == 1
    assert qs[0].organization_id._id == user.organization_id._id
示例#6
0
def test_user_search_returns_ticket_objects_assigned_to_user():
    user = UserFactory()
    for _ in range(3):
        TicketFactory(assignee_id=user)

    search = Search(search_term='_id', search_value=user._id)
    qs = search.search_users()

    assert len(qs) == 1
    assert qs[0]._id == user._id
    assert qs[0].assigned_tickets.count() == 3
示例#7
0
def test_user_search_returns_all_data_matching_requested_search_value():
    for _ in range(3):
        UserFactory(role='admin')

    search = Search(search_term='role', search_value='admin')
    qs = search.search_users()

    assert len(qs) == 3
    assert qs[0].role == 'admin'
    assert qs[1].role == 'admin'
    assert qs[2].role == 'admin'
示例#8
0
def test_user_search_does_not_return_tickets_when_no_tickets_are_submitted_by_user():
    user = UserFactory()
    for _ in range(3):
        TicketFactory()

    search = Search(search_term='_id', search_value=user._id)
    qs = search.search_users()

    assert len(qs) == 1
    assert qs[0]._id == user._id
    assert qs[0].submitted_tickets.count() == 0
示例#9
0
def test_organization_search_does_not_return_user_and_ticket_objects_when_not_linked():
    organization = OrganizationFactory()
    for _ in range(2):
        UserFactory()
    for _ in range(3):
        TicketFactory()

    search = Search(search_term='_id', search_value=organization._id)
    qs = search.search_organizations()

    assert len(qs) == 1
    assert qs[0]._id == organization._id
    assert qs[0].users.count() == 0
    assert qs[0].tickets.count() == 0
示例#10
0
def test_search_users(capsys):
    user = UserFactory()
    TicketFactory(assignee_id=user)
    TicketFactory(submitter_id=user)

    controller = AppController()
    controller.search_term = '_id'
    controller.search_value = user._id
    controller.search = Search(controller.search_term, controller.search_value)
    controller.search_users()

    captured = capsys.readouterr()

    assert (
        f'Searching users for {controller.search_term} with a value of {controller.search_value}'
    ) in captured.out

    assert '_id' in captured.out
    assert 'url' in captured.out
    assert 'external_id' in captured.out
    assert 'name' in captured.out
    assert 'alias' in captured.out
    assert 'created_at' in captured.out
    assert 'active' in captured.out
    assert 'verified' in captured.out
    assert 'shared' in captured.out
    assert 'locale' in captured.out
    assert 'timezone' in captured.out
    assert 'last_login_at' in captured.out
    assert 'email' in captured.out
    assert 'phone' in captured.out
    assert 'signature' in captured.out
    assert 'organization_id' in captured.out
    assert 'orgnaization_name' in captured.out
    assert 'tags' in captured.out
    assert 'suspended' in captured.out
    assert 'role' in captured.out
    assert 'submitted_ticket_id' in captured.out
    assert 'submitted_ticket_subject' in captured.out
    assert 'assigned_ticket_id' in captured.out
    assert 'assigned_ticket_subject' in captured.out
示例#11
0
def test_user_search_for_no_matching_data():
    user = UserFactory()
    search = Search(search_term='_id', search_value=user._id+1)
    qs = search.search_users()
    assert len(qs) == 0