Beispiel #1
0
    def testFindBestProviderForBooking(self):
        testCategory = u'physiotherapy'
        testLocation = u'montreal-west'

        # create provider
        p = Provider()
        p.terms_agreement = True
        p.status = 'client_enabled'
        p.first_name = 'Best-Test'
        p.last_name = 'Phys-Io'
        p.category = testCategory
        p.location = testLocation
        p.vanity_url = 'physio_guy'
        pkey = p.put()
        # add a provider's schedule (Thursday Morning)
        s = Schedule()
        s.day = 'thursday'
        s.start_time = 8
        s.end_time = 12
        s.provider = p.key
        s.put()
        # create provider with no schedule
        p = Provider()
        p.first_name = 'NoSchedule'
        p.last_name = 'Phys-Io'
        p.category = testCategory
        p.location = testLocation
        pkey2 = p.put()
        # 2 providers in db
        self.assertEqual(2,
                         Provider.query().count(), '2 providers in datastore')
        # create booking
        b = Booking()
        b.request_category = testCategory
        b.request_location = testLocation
        b.request_datetime = datetime.strptime('2012-04-26 10', '%Y-%m-%d %H')
        b.put()
        # test the matching
        brs = db_search.provider_search(b)
        logging.info('best provider:' + str(brs))
        # assert
        self.assertIsNotNone(brs, 'provider should not be None')
        self.assertEqual(pkey, brs[0].provider.key,
                         'provider keys should be equal')