Пример #1
0
def lambda_handler(event, context):
    #List User
    users = zendesk.users_list().get('users', [])
    print("Listing Current ZenDesk Users")

    for user in users:
        name = user['name']
        print(name)

    #Find Most Recently Modified Active Users File from S3
    bucket_list = s3.list_objects(Bucket=bucket).get('Contents', [])
    print(bucket_list)

    for file in bucket_list:
        file_name = file['Key']

        try:
            object = s3.get_object(Bucket=bucket,Key=file_name)['Body']
            print(object)

        except Exception, e:
            print ("Error Encountered while downloading file.")
            print (e)
            exit()

        users = json.load(object)
        print(users)   

        #Create and Update User
        print("Creating and Updating Users")
        
        for user in users:
            user_name = user['DisplayName']
            user_email = user['EmailAddress']
            user_phone = user['OfficePhone']

            new_user = {
                'user': {
                    'name': user_name,
                    'email': user_email,
                    'phone': "%s%s" % (telephone_prefix, user_phone),
                }
            }

            try:
                print(new_user)
                result = zendesk.user_create_or_update(data=new_user)
                sleep(0.03)

                #Print Generated User ID
                user_id = get_id_from_url(result)
                print(user_id)
            
            except Exception, e:
                print ("Error Encountered:")
                print (e)
Пример #2
0
    def test_create_ticket(self):

        result = createTicket(config).run(
            "Example from test",
            "this ticked was generated automatically from unit test", "Youpi",
            "*****@*****.**")
        id = get_id_from_url(result)
        action = updateTicket(config)
        result = action.run(id, "Comment generated from unit test")
        print result
        self.assertTrue(result != None, "result should be defined")
Пример #3
0
def zdesk_sandbox_create_ticket(subject, description):

    zdesk_sandbox = zdesk_sandbox_connect()

    # Create
    new_ticket = {
        'ticket': {
            'requester_name': 'John Doe',
            'requester_email': '*****@*****.**',
            'subject': subject,
            'description': description,
            'tags': ['problem', 'issues'],
            'ticket_field_entries': [
                {
                    'ticket_field_id': 1,
                    'value': 'Something1'
                },
                {
                    'ticket_field_id': 2,
                    'value': '$10'
                }
            ]
        }
    }

    result = zdesk_sandbox.ticket_create(data=new_ticket)

    # Alternatively, you can get the complete response and get the location
    # yourself. This can be useful for getting other response items that are
    # not normally returned, such as result['content']['upload']['token']
    # when using zendesk.upload_create()
    #
    # result = zendesk.ticket_create(data=new_ticket, complete_response=True)
    # ticket_url = result['response']['location']
    # ticket_id = get_id_from_url(ticket_url)

    # Need ticket ID?
    from zdesk import get_id_from_url
    ticket_id = get_id_from_url(result)

    return ticket_id
Пример #4
0
def test_ticket_ops(zd):
    new_ticket = {
        'ticket': {
            'subject': 'zdesk test ticket',
            'description': 'test ticket description',
        }
    }

    # create
    result = zd.ticket_create(data=new_ticket, retval='location')

    assert islocation(result), \
        'Create ticket response is not a location string'

    # get id from url
    ticket_id = get_id_from_url(result)

    assert ticket_id.isdigit(), \
        'Returned created ticket ID is not a string of decimal digits'

    # show
    result = zd.ticket_show(id=ticket_id)

    assert isinstance(result, dict), \
        'Show ticket response is not a dict'

    # list
    result = zd.tickets_list(get_all_pages=True)

    assert isinstance(result, dict), \
        'List tickets response is not a dict'

    assert int(ticket_id) in [t['id'] for t in result['tickets']], \
        'Created ticket not present in ticket list'

    # Delete
    result = zd.ticket_delete(id=ticket_id, retval='code')

    assert isstatuscode(result), \
        'Delete ticket response is not a status code'
Пример #5
0
def test_ticket_ops(zd):
    new_ticket = {
        'ticket': {
            'subject': 'zdesk test ticket',
            'description': 'test ticket description',
        }
    }

    # create
    result = zd.ticket_create(data=new_ticket, retval='location')

    assert islocation(result), \
        'Create ticket response is not a location string'

    # get id from url
    ticket_id = get_id_from_url(result)

    assert ticket_id.isdigit(), \
        'Returned created ticket ID is not a string of decimal digits'

    # show
    result = zd.ticket_show(id=ticket_id)

    assert isinstance(result, dict), \
        'Show ticket response is not a dict'

    # list
    result = zd.tickets_list(get_all_pages=True)

    assert isinstance(result, dict), \
        'List tickets response is not a dict'

    assert int(ticket_id) in [t['id'] for t in result['tickets']], \
        'Created ticket not present in ticket list'

    # Delete
    result = zd.ticket_delete(id=ticket_id, retval='code')

    assert isstatuscode(result), \
        'Delete ticket response is not a status code'
Пример #6
0
# will be what is returned.
# Create a ticket and get its URL.
result = zendesk.ticket_create(data=new_ticket)

# Alternatively, you can get the complete response and get the location
# yourself. This can be useful for getting other response items that are
# not normally returned, such as result['content']['upload']['token']
# when using zendesk.upload_create()
#
# result = zendesk.ticket_create(data=new_ticket, complete_response=True)
# ticket_url = result['response']['location']
# ticket_id = get_id_from_url(ticket_url)

# Need ticket ID?
from zdesk import get_id_from_url
ticket_id = get_id_from_url(result)

# Show
zendesk.ticket_show(id=ticket_id)

# Ticket comments and uploads / attachments
commentbody = "Attaching example Python file"

# must be in the examples directory when executing so this file can be found
fname = 'example.py'

with open(fname, 'rb') as fp:
    fdata = fp.read()

# MIME types can be detected with the magic module:
# import magic
Пример #7
0
# will be what is returned.
# Create a ticket and get its URL.
result = zendesk.ticket_create(data=new_ticket)

# Alternatively, you can get the complete response and get the location
# yourself. This can be useful for getting other response items that are
# not normally returned, such as result['content']['upload']['token']
# when using zendesk.upload_create()
#
#result = zendesk.ticket_create(data=new_ticket, complete_response=True)
#ticket_url = result['response']['location']
#ticket_id = get_id_from_url(ticket_url)

# Need ticket ID?
from zdesk import get_id_from_url
ticket_id = get_id_from_url(result)

# Show
zendesk.ticket_show(id=ticket_id)

# Ticket comments and uploads / attachments
commentbody = "Attaching example Python file"

# must be in the examples directory when executing so this file can be found
fname = '__init__.py'

with open(fname, 'rb') as fp:
    fdata = fp.read()

# MIME types can be detected with the magic module:
#import magic
Пример #8
0
def test_raw_query(zd):
    new_ticket = {
        'ticket': {
            'subject': 'zdesk raw_query ticket',
            'description': 'test ticket description',
            'tags': ['raw_query_test'],
        }
    }

    # create
    result = zd.ticket_create(data=new_ticket, retval='location')

    assert islocation(result), \
        'Create raw_query_test ticket response is not a location string'

    # get id from url
    ticket_id = get_id_from_url(result)

    assert ticket_id.isdigit(), \
        'Returned created raw_query_test ticket ID is not a string of decimal digits'

    response_query = zd.ticket_show(id=ticket_id, include='comment_count')
    response_raw = zd.ticket_show(id=ticket_id,
                                  raw_query='?include=comment_count',
                                  retval ='content')

    assert 'comment_count' in response_query['ticket'], \
        'query failed to include comment_count'
    
    assert 'comment_count' in response_raw['ticket'], \
        'raw_query failed to include comment_count'
    
    #    response_query = zd.search(query='tags:raw_query_test', retval='content')
    #
    #    # It can take a bit to populate the search index
    #    while len(response_query['results']) == 0:
    #        time.sleep(4)
    #        response_query = zd.search(query='tags:raw_query_test',
    #                                   retval='content')
    #
    #    response_raw = zd.search(raw_query='?query=tags:raw_query_test',
    #                             retval='content')
    #
    #    # It can take a bit to populate the search index
    #    while len(response_raw['results']) == 0:
    #        time.sleep(4)
    #        response_raw = zd.search(raw_query='?query=tags:raw_query_test',
    #                                 retval='content')
    #
    #    assert response_query['results'][0]['id'] == int(ticket_id), \
    #        'query search returned incorrect ticket'
    #
    #    assert response_raw['results'][0]['id'] == int(ticket_id), \
    #        'raw_query search returned incorrect ticket'
    #
    #    assert len(response_query['results']) == len(response_raw['results']), \
    #        'raw_query search contained different number of results' 
    #
    #    assert response_query['results'][0]['id'] == response_raw['results'][0]['id'], \
    #        'raw_query search returned different tickets' 

    # Delete
    result = zd.ticket_delete(id=ticket_id, retval='code')

    assert isstatuscode(result), \
        'Delete ticket raw_query_test response is not a status code string'