def test_expects_guest_service_to_find_guest_for_return_visitor(self):
        # Arrange
        client = pages_controller.test_client()
        endpoint = '/'
        ip_address = '127.0.0.1'
        guest = guest_fixture.guest(auth_service='ip_address',
                                    auth_service_id=ip_address)

        # Assume
        self.assertEqual(Guest.query().count(), 1)

        # g accessible when using client as context pattern:
        # http://flask.pocoo.org/docs/0.10/testing/#keeping-the-context-around
        with client as request_context:
            # Act
            response = request_context.get(
                endpoint,
                follow_redirects=False,
                environ_base={'REMOTE_ADDR': ip_address})

            # Assert
            self.assertEqual(response.status_code, 200)
            self.assertEqual(Guest.query().count(), 1)
            self.assertIsNotNone(g.uest)
            self.assertEqual(g.uest.public_id, guest.public_id)
            self.assertEqual(guest.auth_service, 'ip_address')
            self.assertEqual(guest.auth_service_id, ip_address)
Example #2
0
 def setUp(self):
     self.guest_1 = Guest("Simon Elsmie")
     self.guest_2 = Guest("Rick Sanchez")
     self.room_1 = Room(1)
     self.room_2 = Room(2)
     self.date_1 = '2021-04-06'
     self.date_2 = '2021-04-07'
     self.reservation_1 = Reservation(self.guest_1, self.room_2,
                                      self.date_1, self.date_2, "Arrival")
     self.reservation_2 = Reservation(self.guest_2, self.room_1,
                                      self.date_1, self.date_2, "Arrival")
Example #3
0
def identify_guest():
    """Returns with an App Engine user or an anonymous user.
    """
    app_engine_user = users.get_current_user()

    if app_engine_user:
        return Guest.app_engine_user(app_engine_user)

    ip_address = ip_address_from_request(request)

    if ip_address:
        return Guest.ip_address(ip_address)
    else:
        return Guest()
Example #4
0
    def test_expects_to_save_new_anonymous_guest(self):
        # Arrange
        auth_service = 'ip_address'
        auth_service_id = '127.0.0.1'

        # Act
        guest = Guest(auth_service = auth_service,
                      auth_service_id = auth_service_id)
        guest.put()

        # Assert
        self.assertIsInstance(guest, Guest)
        self.assertEqual(guest.auth_service, auth_service)
        self.assertIsNotNone(guest.key)
Example #5
0
class TestGuest(unittest.TestCase):
    def setUp(self):
        self.guest_1 = Guest("Simon Elsmie")
        self.guest_2 = Guest("Rick Sanchez")

    def test_guest_1_name(self):
        self.assertEqual("Simon Elsmie", self.guest_1.name)

    def test_guest_2_name(self):
        self.assertEqual("Rick Sanchez", self.guest_2.name)

    def test_stay_count_increase(self):
        self.guest_1.increase_stay_count()
        self.assertEqual(1, self.guest_1.stays)
def update_guest(id):
    name = request.form['name']
    stays = request.form['stays']
    preferences = request.form['preferences']
    updated_guest = Guest(name, stays, preferences, id)
    guest_repository.update(updated_guest)
    return redirect('/guests')
Example #7
0
def search(name):
    guest = None
    sql = "SELECT * FROM guests WHERE name LIKE %s"
    values = [name]
    result = run_sql(sql, values)[0]
    if result is not None:
        guest = Guest(result['name'], result['stays'], result['preferences'], result['id'])
    return guest
Example #8
0
def guest(**options):
    put = options.get('put', True)
    auth_service = options.get('auth_service', DEFAULT['auth_service'])
    auth_service_id = options.get('auth_service_id',
                                  DEFAULT['auth_service_id'])
    auth_service_name = options.get('auth_service_name')
    email = options.get('email')

    guest = Guest(auth_service=auth_service,
                  auth_service_id=auth_service_id,
                  auth_service_name=auth_service_name,
                  email=email)

    if put:
        guest.put()

    return guest
Example #9
0
def select(id):
    guest = None 
    sql = "SELECT * FROM guests WHERE id = %s"
    values =[id]
    result = run_sql(sql, values)[0]
    if result is not None:
        guest = Guest(result['name'], result['stays'], result['preferences'], result['id'])
    return guest
Example #10
0
def select_all():
    guests = []
    sql = "SELECT * FROM guests"
    results = run_sql(sql)
    for row in results:
        guest = Guest(row['name'], row['stays'], row['preferences'], row['id'])
        guests.append(guest)
    return guests
Example #11
0
def kick(update: Update, context: CallbackContext) -> None:
    if update.message.text == "I'm out !":
        update.effective_chat.kick_member(user_id=update.message.from_user.id)
    elif update.message.text == "I'm in !":
        user_id = update.message.from_user.id
        event_id = context.chat_data['event_id']
        username = update.effective_user.username
        event = Event[event_id]
        event.guests.add(Guest(uuid=user_id, event=event, username=username))
Example #12
0
    def test_expects_to_create_new_anonymous_guest(self):
        # Arrange
        ip_address = '127.0.0.1'

        # Act
        guest = Guest.ip_address(ip_address)

        # Assert
        self.assertEqual(guest.auth_service, 'ip_address')
        self.assertEqual(guest.auth_service_id, ip_address)
Example #13
0
def guests_show(guest_id=None):
    if guest_id:
        guest = Guest.read(int(guest_id))
    else:
        guest = g.uest

    if not guest:
        return render_404('Guest not found')
    else:
        return render_template('guests/show.html', guest=guest)
    def test_expects_guest_service_to_create_guest_for_first_time_visitor(
            self):
        # Arrange
        client = pages_controller.test_client()
        endpoint = '/'
        ip_address = '127.0.0.1'

        # Assume
        self.assertEqual(Guest.query().count(), 0)

        # Act
        response = client.get(endpoint,
                              follow_redirects=False,
                              environ_base={'REMOTE_ADDR': ip_address})
        new_guest = Guest.query().get()

        # Assert
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Guest.query().count(), 1)
        self.assertEqual(new_guest.auth_service, 'ip_address')
        self.assertEqual(new_guest.auth_service_id, ip_address)
    def test_expects_guest_service_to_save_guest_requests(self):
        # Arrange
        client = pages_controller.test_client()

        # Assume
        endpoint = '/'
        self.assertEqual(Guest.query().count(), 0)
        self.assertEqual(GuestRequest.query().count(), 0)

        # Act
        response = client.get(endpoint,
                              follow_redirects=False,
                              environ_base={'REMOTE_ADDR': '127.0.0.1'})
        guest = Guest.query().get()
        guest_request = GuestRequest.query().get()

        # Assert
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Guest.query().count(), 1)
        self.assertEqual(GuestRequest.query().count(), 1)
        self.assertEqual(guest_request.guest.unique_id, guest.unique_id)
Example #16
0
    def test_generate_session_id(self):
        # Arrange
        email = '*****@*****.**'
        app_engine_user_id = MockIdentityService.stub_app_engine_user(
            self, email=email)
        app_engine_user = users.get_current_user()
        guest = Guest.app_engine_user(app_engine_user)

        # Act
        session_id = guest_service.generate_session_id(guest)

        # Assert
        self.assertIsNotNone(session_id)
Example #17
0
    def test_expects_to_create_new_app_engine_guest(self):
        # Arrange
        email = '*****@*****.**'
        app_engine_user_id = MockIdentityService.stub_app_engine_user(self, email=email)
        app_engine_user = users.get_current_user()

        # Assume
        self.assertEqual(app_engine_user.user_id(), app_engine_user_id)

        # Act
        guest = Guest.app_engine_user(app_engine_user)

        # Assert
        self.assertEqual(guest.auth_service, 'app_engine')
        self.assertEqual(guest.auth_service_id, app_engine_user_id)
Example #18
0
    def test_expects_to_get_index(self):
        # Arrange
        client = guests_controller.test_client()

        # Assume
        endpoint = '/guests/'
        row_selector = 'table.guests > tbody > tr'
        self.assertEqual(Guest.query().count(), 0)

        # Act: this will create new anonymous guest
        response = client.get(endpoint, follow_redirects=False)
        html = parse_html(response.data)
        rows = html.select(row_selector) if html else None

        # Assert
        self.assertEqual(response.status_code, 200, html)
        self.assertEqual(len(rows), 1, html)
Example #19
0
def create_guest():
    name = request.form['name']
    new_guest = Guest(name)
    guest_repository.save(new_guest)
    reservation_repository.arrival_status()
    return redirect('/guests')
Example #20
0
def guests_admin_index():
    guests = Guest.s_recently_created(25)
    return render_template('guests/index.html',
                           guests=guests,
                           table='guests/_admin_table.html')
Example #21
0
 def setUp(self):
     self.guest_1 = Guest("Simon Elsmie")
     self.guest_2 = Guest("Rick Sanchez")