Beispiel #1
0
 def setUp(self):
     self.slot_9 = Slot(9, "08:00-09:00", False)
     self.slot_10 = Slot(10, "09:00-10:00", False)
     self.slot_11 = Slot(11, "10:00-11:00", False)
     self.beg_spin_class = Lesson("Spin Class", "cardio", "beginner", 55,
                                  10, self.slot_10)
     self.int_spin_class = Lesson("Spin Class", "cardio", "intermediate",
                                  55, 10, self.slot_9)
     self.adv_spin_class = Lesson("Spin Class", "cardio", "advanced", 55,
                                  10, self.slot_11)
Beispiel #2
0
def create_slot():
    """Creates a slot entity
    :return: a success message
    """
    details = json.loads(request.data)
    if details["start_time"] <= details["end_time"]:
        slot = Slot(
            doctor_id=details["doctor_id"],
            start_time=details["start_time"],
            end_time=details["end_time"]
        )

        slot.save()
        return make_response(jsonify({"message": "Slot created successfully"}), 201)
    return make_response(jsonify({"message": "Start time cannot be later than stop time"}), 400)
Beispiel #3
0
def test_create_slot(slots_defs):
    slots = Slot.create_slots(slots_defs)

    assert slots[0].name == 'name'
    assert slots[0].slot_type == 'AMAZON.Person'
    assert slots[0].prompt == 'Great thanks, please enter your name.'
    assert slots[0].utterances == ['I am {name}', 'My name is {name}']
def test_create_intent_with_amazon_slot(put_intent_response, codehook_uri,
                                        mock_context, lex, aws_lambda,
                                        monkeypatch_account):

    with Stubber(aws_lambda) as lambda_stubber, Stubber(lex) as lex_stubber:
        stub_lambda_request(lambda_stubber, codehook_uri)

        intent_builder = IntentBuilder(Mock(),
                                       mock_context,
                                       lex_sdk=lex,
                                       lambda_sdk=aws_lambda)

        plaintext = {
            "confirmation": 'some confirmation message',
            'rejection': 'rejection message',
            'conclusion': 'concluded'
        }
        stub_not_found_get_request(lex_stubber)
        slot = Slot('person', 'AMAZON.Person', 'yo', ['one', 'two'])
        intent = Intent(BOT_NAME,
                        INTENT_NAME,
                        codehook_uri,
                        UTTERANCES, [slot],
                        plaintext=plaintext,
                        max_attempts=3)

        put_request = put_intent_slot_request(intent)
        put_request.update(put_request_conclusion(plaintext))

        stub_intent_creation(lex_stubber, put_intent_response, put_request)

        intent_builder.put_intent(intent)

        lex_stubber.assert_no_pending_responses()
        lambda_stubber.assert_no_pending_responses()
Beispiel #5
0
    def get_next_n_slots(self,
                         week_config: List[List[Dict]],
                         current_time: datetime,
                         n=10):
        """
        Returns `n` available slots from the `current_time` on the basis of `week_config`. returns empty list, 
        if any slot is not abailable.
        """
        next_n_slots = []
        week_day = current_time.weekday()
        idx_week = week_day

        while True:
            if idx_week == week_day + WEEK_LEN - 1 and len(next_n_slots) == 0:
                return []
            for slot in map(
                    lambda s: Slot(parse_time(s['start_time']),
                                   parse_time(s['end_time'])),
                    week_config[idx_week % WEEK_LEN]):
                if len(next_n_slots) >= n:
                    return [slot.to_dict for slot in next_n_slots]
                slot.make(current_time +
                          datetime.timedelta(days=idx_week - week_day))
                if slot.start >= current_time:
                    next_n_slots.append(slot)
            idx_week += 1
        return [slot.to_dict for slot in next_n_slots]
    def create_intent(cls, bot_name, intent_definition):
        intent_name, codehook_arn, max_attempts = cls._extract_intent_attributes(intent_definition)
        utterances = intent_definition.get('Utterances')
        slots = Slot.create_slots(intent_definition.get('Slots'))

        max_attempts = intent_definition.get('maxAttempts') if intent_definition.get('maxAttempts') else 3
        return Intent(bot_name, intent_name, codehook_arn, utterances, slots,
                      max_attempts=max_attempts, plaintext=intent_definition.get('Plaintext'))
Beispiel #7
0
 def __init__(self, capacity):
     self.capacity = capacity
     self.freeSlots = []
     self.slots = []
     for i in range(0,capacity):
         slot = Slot(i+1)
         self.freeSlots.append(i+1)
         self.slots.append(slot)
def test_validate_intent_slots(validate_slot, intent_defs):
    intent_def = intent_defs[0]
    del intent_def['Slots']

    intent = Intent.create_intent('botname', intent_def)
    intent.slots = [Slot('a', 'b', 'c', [])]
    intent.validate_intent()

    validate_slot.assert_called_once()
Beispiel #9
0
def select_all():
    slots = []
    sql = "SELECT * FROM slots"
    results = run_sql(sql)

    for row in results:
        slot = Slot(row['slot_num'], row['time_stamp'], row['turbo_slot'],
                    row['id'])
        slots.append(slot)
    return slots
Beispiel #10
0
def select(id):
    result = None
    sql = "SELECT * FROM slots WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        slot = Slot(result['slot_num'], result['time_stamp'],
                    result['turbo_slot'], result['id'])
    return slot
Beispiel #11
0
    def __init__(self, size):
        """
        :param size: No of parking lots in total
        Desc: Creates n no of slots based on the size given
        """
        slots = {}
        for i in range(1, size + 1):
            slots[i] = Slot(slot_number=i)

        self.slots = slots
        self.totalSlots = size
        self.occupied_slots_count = 0
Beispiel #12
0
    def test_allow_park_car(self):
        # Arrange
        car = Car('KA-01-HH-1234', 'White')
        s = EntryService()
        s.InitializeParkingLot(6)
        s.lotHandler.IsCarParked = MagicMock(return_value=False)
        s.lotHandler.IsLotFull = MagicMock(return_value=False)
        s.lotHandler.GetNearestSlot = MagicMock(return_value=1)
        s.lotHandler.IsSlotAvailable = MagicMock(return_value=True)

        slot = Slot(1)
        s.lotHandler.FillSlot = MagicMock(return_value=slot)

        # Act
        status = s.allow(car)

        # Assert
        self.assertEqual(status, 'Allocated slot number: {0}'.format(1))
Beispiel #13
0
def get_slot():
    """
    :return: A list of objects of all the slots available
    """
    slots = Slot.get_all()
    if slots:
        get_results = []
        for slot in slots:
            slot_object = {
                "doctor_id": slot.doctor_id,
                "slot_id": slot.id,
                "start_time": slot.start_time,
                "end_time": slot.end_time
            }
            get_results.append(slot_object)

        return make_response(jsonify({"slots": get_results})), 200
    else:
        return make_response(jsonify({"message": "No slots found"}), 404)
Beispiel #14
0
# delete all tables

slot_repository.delete_all()
member_repository.delete_all()
lesson_repository.delete_all()

# pre-population/seeding goes here:

# CREATE TABLE slots (
#     id SERIAL PRIMARY KEY,
#     slot_num INT,
#     time_stamp VARCHAR(255),
#     turbo_slot BOOLEAN
# );

slot_1 = Slot(1, "00:00-01:00", False)
slot_repository.save(slot_1)
slot_2 = Slot(2, "01:00-02:00", False)
slot_repository.save(slot_2)
slot_3 = Slot(3, "02:00-03:00", False)
slot_repository.save(slot_3)
slot_4 = Slot(4, "03:00-04:00", False)
slot_repository.save(slot_4)
slot_5 = Slot(5, "04:00-05:00", False)
slot_repository.save(slot_5)
slot_6 = Slot(6, "05:00-06:00", False)
slot_repository.save(slot_6)
slot_7 = Slot(7, "06:00-07:00", False)
slot_repository.save(slot_7)
slot_8 = Slot(8, "07:00-08:00", False)
slot_repository.save(slot_8)
Beispiel #15
0
 def setUp(self):
     self.slot_1 = Slot(1, "00:00-01:00", False)
Beispiel #16
0
def test_validate_slot_fails(invalid_slots_defs):
    with pytest.raises(Exception) as excinfo:
        slots = Slot.create_slots(invalid_slots_defs)
        slots[0].validate_slot()

    assert "Utterances missing in slot" in str(excinfo.value)
def create_slot(queue_id):
    queue = Queue.query.filter_by(id=queue_id).first()
    slot = Slot(queue=queue)
    db.session.add(slot)
    db.session.commit()
    return str(slot.id)
Beispiel #18
0
def test_validate_utterance_contains_slotname():
    utterance = 'does not contain slot'
    with pytest.raises(Exception) as excinfo:
        Slot('pizza', 'type', 'aprompt', [utterance]).validate_slot()

    assert "does not contain pizza" in str(excinfo.value)