Esempio n. 1
0
    def test_get_list_null_no_listings(self):

        # Building a new property to store
        password = '******'
        email = str(uuid.uuid4()) + '@gmail.com'
        new_user = User(password=password, id=email)

        # Storing the initial property for this test
        session = Session()
        try:
            session.add(new_user)
            session.commit()
        except:
            session.rollback()

        # Run the transaction
        event = {
            'verb': 'GetBookingList',
            'mya_property_id': 'Test1MyaPropertyID',
            'ota_property_id': email,
            'ota_booking_version': None,
            "ota_property_password": password,
            'shared_secret': SHARED_SECRET
        }
        result = index.router(event, None)

        # Validate the API call
        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')
        body = json.loads(result['body'])
        self.assertFalse('errors' in body)
        self.assertEqual(body['success'], True)
        self.assertEqual(len(body['Bookings']), 0)
Esempio n. 2
0
    def test_get_list_happy_path(self):

        # Building a new property to store
        password = '******'
        email = str(uuid.uuid4()) + '@gmail.com'
        new_user = User(password=password, id=email)

        # Storing the initial property for this test
        session = Session()
        try:
            session.add(new_user)
            session.commit()
        except:
            session.rollback()

        new_customer = Customer(email=email, first_name='John', last_name='Doe')
        session.add(new_customer)
        session.commit()

        # Storing a few new bookings for this test
        count = 1
        try:
            while count < 4:
                dttm = datetime.now() + timedelta(hours=(-1 * count))
                new_booking = Booking(id=str(uuid.uuid4()), user_id=new_user.id, dttm=dttm)
                new_booking.customers.append(new_customer)
                session.add(new_booking)
                count = count + 1
            session.commit()
        except:
            print(traceback.format_exc())
            session.rollback()

        # Run the transaction
        event = {
            'verb': 'GetBookingList',
            'mya_property_id': 'Test1MyaPropertyID',
            'ota_property_id': email,
            'ota_booking_version': (datetime.now() + timedelta(hours=-2)).strftime('%Y-%m-%d %H:%M:%S'),
            "ota_property_password": password,
            'shared_secret': SHARED_SECRET
        }
        result = index.router(event, None)

        # Validate the API call
        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')
        body = json.loads(result['body'])
        self.assertFalse('errors' in body)
        self.assertEqual(body['success'], True)
        self.assertEqual(len(body['Bookings']), 2)
    def test_missing_property_id(self):

        event = {
            "verb": "HealthCheck",
            "ota_property_id": "",
            "shared_secret": SHARED_SECRET
        }

        result = index.router(event, None)

        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')

        body = json.loads(result['body'])
        self.assertTrue('errors' in body)
        self.assertEqual(body['success'], False)
    def test_bad_health_response(self):

        event = {
            "verb": "HealthCheck",
            "mya_property_id": "",
            "ota_property_id": "",
            "shared_secret": 'wrong password'
        }

        result = index.router(event, None)

        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')

        body = json.loads(result['body'])
        self.assertEqual(len(body['errors']), 1)
        self.assertEqual(body['success'], False)
    def test_health_response_body(self):

        body = {
            "verb": "HealthCheck",
            "mya_property_id": "",
            "ota_property_id": "",
            "shared_secret": SHARED_SECRET
        }
        event = {'body': json.dumps(body)}

        result = index.router(event, None)

        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')

        body = json.loads(result['body'])
        self.assertFalse('errors' in body)
        self.assertEqual(body['success'], True)
    def test_missing_shared_secret(self):

        body = {
            "verb": "HealthCheck",
            "mya_property_id": "",
            "ota_property_id": ""
        }
        event = {'body': json.dumps(body)}

        result = index.router(event, None)

        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')

        body = json.loads(result['body'])
        self.assertTrue('errors' in body)
        self.assertEqual(len(body['errors']), 1)
        self.assertEqual(body['success'], False)
Esempio n. 7
0
    def test_get_room_types_happy_path(self):

        # Building a new property to store
        password = '******'
        email = str(uuid.uuid4()) + '@example.com'
        new_user = User(password=password, id=email)

        # Storing the initial property for this test
        session = Session()
        session.add(new_user)
        session.commit()

        # Storing a few new room types for this test
        count = 1
        while count < 4:
            new_room_type = RoomType(id=str(uuid.uuid4()), user_id=email, title='Title ' + str(count),
                                     detail='Detail ' + str(count), dorm=False, occupancy=count)
            session.add(new_room_type)
            count = count + 1
        session.commit()

        # Run the transaction
        event = {
            "verb": "GetRoomTypes",
            "mya_property_id": "Test1MyaPropertyID",
            "ota_property_id": email,
            "ota_property_password": password,
            "shared_secret": SHARED_SECRET
        }

        result = index.router(event, None)

        # Validate the API call
        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')
        body = json.loads(result['body'])
        print(result['body'])
        self.assertFalse('errors' in body)
        self.assertEqual(body['success'], True)
        self.assertEqual(len(body['Rooms']), 3)
    def test_setup_property_happy_path(self):

        # Building a new property to store
        password = '******'
        email = str(uuid.uuid4()) + '@example.com'
        new_user = User(password=password, id=email)

        # Storing the initial property for this test
        session = Session()
        try:
            session.add(new_user)
            session.commit()
        except:
            session.rollback()

        # Run the transaction
        event = {
            "verb": "SetupProperty",
            "mya_property_id": "Test1MyaPropertyID",
            "ota_property_id": email,
            "ota_property_password": password,
            "shared_secret": SHARED_SECRET
        }

        result = index.router(event, None)

        # Validate the API call
        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')

        body = json.loads(result['body'])
        self.assertFalse('errors' in body)
        self.assertEqual(body['success'], True)
        self.assertEqual(body['ota_property_id'], email)

        # Validate the database content
        session = Session()
        for user in session.query(User).filter(User.id == new_user.id):
            self.assertTrue(user.validate_pw(event['ota_property_password']), "Passwords do not match")
            self.assertEqual(user.myallocator_id, 'Test1MyaPropertyID')
    def test_get_booking_happy_path(self):

        # Building a new property to store
        password = '******'
        email = str(uuid.uuid4()) + '@gmail.com'
        new_user = User(password=password, id=email)

        # Storing the initial user for this test
        session = Session()
        session.add(new_user)
        session.commit()

        # Building a room type
        new_room_type = RoomType(id=str(uuid.uuid4()), user_id=new_user.id, title='Title',
                                 detail='Detail', dorm=False, occupancy=1)

        # Storing the initial room type
        session.add(new_room_type)
        session.commit()

        # Storing a new booking for this test
        dttm = datetime.now() + timedelta(hours=-1)
        booking_id = str(uuid.uuid4())
        new_customer = Customer(email=booking_id+'@gmail.com', first_name='John', last_name='Doe')
        session.add(new_customer)
        session.commit()
        new_booking = Booking(id=booking_id, user_id=new_user.id, dttm=dttm)
        new_booking.customers.append(new_customer)
        session.add(new_booking)
        session.commit()

        count = 1
        try:
            while count < 4:
                dt = date.today() + timedelta(days=30+(1 * count))
                new_booked_room = BookingRoom(dt=dt, rate=32.25, rate_id='',
                                              booking=new_booking, room_type=new_room_type)
                session.add(new_booked_room)
                count = count + 1
            session.commit()
        except:
            session.rollback()

        # Run the transaction
        event = {
            'verb': 'GetBookingId',
            'mya_property_id': 'Test1MyaPropertyID',
            'ota_property_id': email,
            'booking_id': new_booking.id,
            "ota_property_password": password,
            'shared_secret': SHARED_SECRET
        }
        result = index.router(event, None)

        # Validate the API call
        self.assertEqual(result['statusCode'], 200)
        self.assertEqual(result['headers']['Content-Type'], 'application/json')
        body = json.loads(result['body'])

        self.assertFalse('errors' in body)
        self.assertEqual(body['success'], True)
        self.assertEqual(len(body['Booking']['Customers']), 1)
        self.assertEqual(len(body['Booking']['Rooms']), 1)
        self.assertEqual(len(body['Booking']['Rooms'][0]['DayRates']), 3)
        self.assertEqual(body['Booking']['TotalPrice'], 96.75)