예제 #1
0
 def appointment_confirm(self, service_id, service_name, service_qp_id, appointment_id,
                         first_name, last_name, email, phone, date_of_birth):
     url = self._format_url(self.APPOINTMENT_CONFIRM_URL,
                            appointment_id=appointment_id)
     data = {
         'captcha': '',
         'custom': json.dumps({
             'peopleServices': [{
                 'publicId': service_id,
                 'qpId': service_qp_id,
                 'adult': 1,
                 'name': service_name,
                 'child': 0,
             }],
             'totalCost': 0,
             'createdByUser': '******',
             'customSlotLength': 15,
         }),
         'customer': {
             'dateOfBirth': date_of_birth,
             'dob': '',
             'email': email,
             'externalId': '',
             'firstName': first_name,
             'lastName': last_name,
             'phone': phone,
         },
         'languageCode': 'en',
         'notes': '',
         'notificationType': '',
         'title': 'Qmatic Web Booking',
     }
     return self._post(url, data)
예제 #2
0
def event(date_search_output):
    return {
        'Records': [{
            'Sns': {
                'Message': json.dumps(date_search_output),
            },
        }],
    }
예제 #3
0
파일: test_book.py 프로젝트: mchestr/pycbc
def test_handler_existing_appointment(
        appointment_reserve_stub, appointment_check_multiple_fail_stub,
        appointment_confirm_stub, appointments_search_stub,
        appointment_cancel_stub, configuration_stub, appointment_confirm_json,
        event):
    output = book.handler(event, None)
    assert output == d(statusCode=200,
                       body=json.dumps(appointment_confirm_json))
예제 #4
0
 def appointment_reserve(self, service_id, service_name, service_qp_id, branch_id, date, time):
     url = self._format_url(self.APPOINTMENT_RESERVE_URL, time=time, branch_id=branch_id, date=date)
     data = {
         'custom': json.dumps({
             'peopleServices': [{
                 'publicId': service_id,
                 'qpId': service_qp_id,
                 'adult': 1,
                 'name': service_name,
                 'child': 0,
             }]
         }),
         'services': [{
             'publicId': service_id,
         }],
     }
     return self._post(url, data, customSlotLength=15)
예제 #5
0
파일: config.py 프로젝트: mchestr/pycbc
def load(event):
    event_override = event.get('config', d())
    env_prefix = event_override.get(
        'env_prefix', os.getenv('ENV_PREFIX', 'PYCBC_'))
    s3_bucket = event_override.get(
        's3_bucket', os.getenv(f'{env_prefix}S3_BUCKET', 'pycbc'))
    s3_filename = event_override.get(
        's3_filename',
        os.getenv(f'{env_prefix}S3_FILENAME', 'pycbc-config.yaml')
    )
    return json.loads(json.dumps(reduce(
        _merge,
        [
            deepcopy(_DEFAULTS),
            _from_s3(s3_bucket, s3_filename),
            _from_env(env_prefix),
            event_override,
            {'s3_bucket': s3_bucket, 's3_filename': s3_filename}
        ])
    ))
예제 #6
0
def handler(event, context):
    config = load(event)
    logging.config.dictConfig(config.logging)

    try:
        query_params = event['queryStringParameters']
        query_token = query_params.pop('token')

        payload = token.decrypt(config.encrypt_key, query_token, ttl=3600)
    except InvalidToken:
        return {
            'statusCode': 400,
            'body': 'token expired',
        }
    except Exception as exc:
        log.exception(exc)
        return {
            'statusCode': 401,
            'body': 'UNAUTHORIZED',
        }
    log.info(f'Payload: {payload}')

    branch = d(branch_id=query_params['branch_id'],
               date=query_params['date'],
               time=query_params['time'])
    try:
        reservation = reserve(payload.service, branch, payload.user)
        return {
            'statusCode': 200,
            'body': json.dumps(reservation),
        }
    except Exception as exc:
        log.exception(exc)
        return {
            'statusCode': 500,
            'body': 'failed to book appointment',
        }
예제 #7
0
def test_publish(email, mock_sns):
    sns.publish('test', {})
    mock_sns.publish.assert_called_once_with(
        TopicArn='test',
        Message=json.dumps({}),
    )
예제 #8
0
파일: test_json.py 프로젝트: mchestr/pycbc
def test_dumps():
    assert json.dumps({'test': 1}) == '{"test":1}'
예제 #9
0
파일: test_book.py 프로젝트: mchestr/pycbc
def test_handler(appointment_reserve_stub, appointment_check_multiple_stub,
                 appointment_confirm_stub, configuration_stub, event,
                 appointment_confirm_json):
    output = book.handler(event, None)
    assert output == d(statusCode=200,
                       body=json.dumps(appointment_confirm_json))