Beispiel #1
0
    def test_all_users_in_campus_with_location_with_campus_for_response_with_inserted_data(
            self):
        c1 = Campus(latitude=12.32434, longitude=56.4324, name='Some Campus1')
        self.test_db.session.add(c1)
        self.test_db.session.commit()

        i_c1 = Campus.query.filter_by(latitude=c1.latitude,
                                      longitude=c1.longitude,
                                      name=c1.name).first()

        l1 = Location(latitude=12.32434, longitude=56.4324, campus_id=i_c1.id)
        self.test_db.session.add(l1)
        self.test_db.session.commit()

        i_l1 = Location.query.filter_by(latitude=l1.latitude,
                                        longitude=l1.longitude).first()

        u1 = User(first_name='user1',
                  last_name='last1',
                  username='******',
                  password='******',
                  location_id=i_l1.id)
        u2 = User(first_name='user2',
                  last_name='last2',
                  username='******',
                  password='******')
        self.test_db.session.add(u1)
        self.test_db.session.add(u2)
        self.test_db.session.commit()
        result = self.app.get('/api/users?campusId=' + str(i_c1.id))
        dict_val = json.loads(result.data)

        self.assertEqual(result.status_code, 200)
        self.assertEqual(len(dict_val["items"]), 1)
        self.assertEqual(dict_val["items"][0]["firstName"], u1.first_name)
        self.assertIsNotNone(dict_val["items"][0]["location"])
        self.assertEqual(dict_val["items"][0]["location"]["latitude"],
                         l1.latitude)
        self.assertIsNotNone(dict_val["items"][0]["location"]["campus"])
        self.assertIsNotNone(
            dict_val["items"][0]["location"]["campus"]["name"], c1.name)
        self.assertEqual(dict_val["success"], True)
    def test_should_return_processed_data_for_valid_auth_and_data_input_in_action_view_meetings(
            self):
        now = datetime.now()
        e1 = Event(title='Event 9s',
                   description='Some desc 9',
                   event_start=now,
                   event_end=now)
        e2 = Event(title='Event 12',
                   description='Some desc 12',
                   event_start=now,
                   event_end=now)
        u1 = User(first_name='User12',
                  last_name='Last53',
                  username='******',
                  password='******')
        self.test_db.session.add(e1)
        self.test_db.session.add(e2)
        self.test_db.session.add(u1)
        self.test_db.session.commit()
        e_id = e1.id
        u_id = u1.id

        ep1 = EventParticipant(event_id=e_id, participant_id=u_id)
        self.test_db.session.add(ep1)
        self.test_db.session.commit()

        payload_data = {
            'result': {
                'parameters': {
                    'some-param': 'some-value'
                },
                'fulfillment': {
                    'speech': 'Hi Ana! Nice to meet you!'
                },
                'contexts': [{
                    'name': 'auth',
                    'parameters': {
                        'token': 'uname31'
                    }
                }],
                'action': 'view-meetings-request'
            }
        }
        result = self.app.post('/api/ai/fulfillment',
                               content_type='application/json',
                               data=json.dumps(payload_data))
        dict_val = json.loads(result.data)
        self.assertEqual(result.status_code, 200)
        # print(dict_val)
        self.assertEqual(
            dict_val['speech'],
            (e1.title + ' From: ' + dstr(now) + ' Till: ' + dstr(now)))
    def test_should_return_processed_data_for_valid_and_data_input_in_action_schedule_meeting(
            self):

        u1 = User(first_name='user2',
                  last_name='last2',
                  username='******',
                  password='******')
        l1 = Location(latitude=15.32434, longitude=57.432, name='loc1')
        self.test_db.session.add(u1)
        self.test_db.session.add(l1)
        self.test_db.session.commit()

        u1_id = u1.id

        payload_data = {
            'result': {
                'parameters': {
                    'campus-location': 'loc1',
                    'office-user': '******',
                    'date': '2017-09-08',
                    'time': '13:30:00'
                },
                'fulfillment': {
                    'speech': 'Hi Ana! Nice to meet you!'
                },
                'contexts': [{
                    'name': 'auth',
                    'parameters': {
                        'token': 'uname2'
                    }
                }],
                'action': 'schedule-meeting-request'
            }
        }
        result = self.app.post('/api/ai/fulfillment',
                               content_type='application/json',
                               data=json.dumps(payload_data))
        dict_val = json.loads(result.data)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(
            dict_val['speech'],
            'Added!' + payload_data['result']['fulfillment']['speech'])
        self.assertEqual(
            dict_val['displayText'],
            'Added!' + payload_data['result']['fulfillment']['speech'])
        meetings = Event.query.all()
        self.assertEqual(len(meetings), 1)
        self.assertEqual(meetings[0].title,
                         'user2\'s meeting with user2 at loc1')
        self.assertEqual(len(meetings[0].event_participants), 1)
        self.assertEqual(meetings[0].event_participants[0].participant_id,
                         u1_id)
Beispiel #4
0
    def test_all_users_without_location_for_response_with_inserted_data(self):
        u1 = User(first_name='user1',
                  last_name='last1',
                  username='******',
                  password='******')
        u2 = User(first_name='user2',
                  last_name='last2',
                  username='******',
                  password='******')
        self.test_db.session.add(u1)
        self.test_db.session.add(u2)
        self.test_db.session.commit()

        result = self.app.get('/api/users')
        dict_val = json.loads(result.data)

        self.assertEqual(result.status_code, 200)
        self.assertEqual(len(dict_val["items"]), 2)
        self.assertEqual(dict_val["items"][0]["firstName"], u1.first_name)
        self.assertIsNone(dict_val["items"][0]["location"])
        self.assertEqual(dict_val["items"][1]["lastName"], u2.last_name)
        self.assertIsNone(dict_val["items"][1]["location"])
        self.assertEqual(dict_val["success"], True)
    def test_should_redirect_to_action_view_person_info_for_action_view_person_location_info(
            self):
        l1 = Location(latitude=22.32434,
                      longitude=86.4324,
                      name="New user loc1221")
        self.test_db.session.add(l1)
        self.test_db.session.commit()

        u1 = User(first_name='User22',
                  last_name='Last32',
                  username='******',
                  password='******',
                  location_id=l1.id)
        self.test_db.session.add(u1)
        self.test_db.session.commit()
        payload_data = {
            'result': {
                'parameters': {
                    'office-user': '******'
                },
                'fulfillment': {
                    'speech': 'Some message for view-person-info-request!'
                },
                'contexts': [],
                'action': 'view-person-location-request'
            }
        }
        result = self.app.post('/api/ai/fulfillment',
                               content_type='application/json',
                               data=json.dumps(payload_data))
        dict_val = json.loads(result.data)
        self.assertEqual(result.status_code, 200)
        # print(dict_val)
        self.assertEqual(dict_val['speech'],
                         'User: User22 Last32 is located at New user loc1221')
        self.assertEqual(
            dict_val['data']['web']['parameters']['location']['name'], l1.name)
        self.assertEqual(
            dict_val['data']['web']['parameters']['location']['latitude'],
            l1.latitude)
        self.assertEqual(dict_val['parameters']['location']['name'], l1.name)
        self.assertEqual(dict_val['parameters']['location']['latitude'],
                         l1.latitude)
Beispiel #6
0
    def test_add_event_with_valid_data_with_location_partially_valid_participants(
            self):
        u1 = User(first_name='User1',
                  last_name='Last3',
                  username='******',
                  password='******')
        l1 = Location(name='loc2',
                      latitude=62.64654,
                      longitude=63.54465,
                      campus_id=0)
        self.test_db.session.add(u1)
        self.test_db.session.add(l1)
        self.test_db.session.commit()
        u_id = u1.id
        l_id = l1.id
        now = datetime.now()
        later = (now + timedelta(hours=1))
        data = {
            'title': 'Event 5',
            'description': 'Some event 5',
            'eventStart': now.timestamp() * 1e3,
            'eventEnd': later.timestamp() * 1e3,
            'participantIds': '%r,%r' % (u_id, 3),
            'locationId': l_id
        }
        result = self.app.post('/api/events', data=data)
        self.assertEqual(result.status_code, 200)
        dict_val = json.loads(result.data)
        self.assertEqual(dict_val["item"]["title"], data['title'])
        self.assertEqual(dict_val["item"]["eventStart"], data['eventStart'])
        self.assertEqual(dict_val["item"]["location"]["latitude"], l1.latitude)
        self.assertEqual(dict_val["success"], True)
        events = Event.query.all()
        self.assertEqual(len(events), 1)
        self.assertEqual(events[0].event_start, now)
        self.assertEqual(events[0].description, data['description'])
        self.assertEqual(events[0].event_end, later)

        event_participants = EventParticipant.query.filter_by(
            event_id=events[0].id).all()
        self.assertEqual(len(event_participants), 1)
        self.assertEqual(event_participants[0].participant_id, u_id)
    def test_should_return_not_process_data_for_invalid_data_for_no_location_in_action_route_to_location_info(
            self):

        l1 = Location(latitude=12.32434, longitude=56.4324, name="loc332")
        self.test_db.session.add(l1)
        self.test_db.session.commit()

        l1_id = l1.id
        u1 = User(first_name='User22',
                  last_name='Last32',
                  username='******',
                  password='******',
                  location_id=l1_id)
        self.test_db.session.add(u1)
        self.test_db.session.commit()

        payload_data = {
            'result': {
                'parameters': {
                    'campus-location': 'loc255'
                },
                'fulfillment': {
                    'speech': 'Some message for route-to-location-request!'
                },
                'contexts': [{
                    'name': 'auth',
                    'parameters': {
                        'token': 'uname39'
                    }
                }],
                'action': 'route-to-location-request'
            }
        }
        result = self.app.post('/api/ai/fulfillment',
                               content_type='application/json',
                               data=json.dumps(payload_data))
        dict_val = json.loads(result.data)
        self.assertEqual(result.status_code, 200)
        # print(dict_val)
        str_resp = 'Not a valid Location'
        self.assertEqual(dict_val['speech'], str_resp)
Beispiel #8
0
    def test_no_users_in_campus_with_location_no_campus_for_response_with_inserted_data(
            self):
        l1 = Location(latitude=12.32434, longitude=56.4324)
        self.test_db.session.add(l1)
        self.test_db.session.commit()

        i_l1 = Location.query.filter_by(latitude=l1.latitude,
                                        longitude=l1.longitude).first()

        u1 = User(first_name='user1',
                  last_name='last1',
                  username='******',
                  password='******',
                  location_id=i_l1.id)
        self.test_db.session.add(u1)
        self.test_db.session.commit()
        result = self.app.get('/api/users?campusId=1')
        dict_val = json.loads(result.data)

        self.assertEqual(result.status_code, 200)
        self.assertEqual(len(dict_val["items"]), 0)
        self.assertEqual(dict_val["success"], True)
Beispiel #9
0
    def test_add_event_participants_for_response_with_inserted_data(self):
        now = datetime.now()
        e1 = Event(title='Event 1',
                   description='Some desc 1',
                   event_start=now,
                   event_end=now)
        u1 = User(first_name='User1',
                  last_name='Last3',
                  username='******',
                  password='******')

        self.test_db.session.add(e1)
        self.test_db.session.add(u1)
        self.test_db.session.commit()
        e_id = e1.id
        data = {'participants': '%r,%r' % (e_id, 12)}
        result = self.app.post('/api/events/%r' % (e1.id), data=data)
        dict_val = json.loads(result.data)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(dict_val["item"], 1)
        self.assertEqual(dict_val["success"], True)
        eps = EventParticipant.query.filter_by(event_id=e_id).all()
        self.assertEqual(len(eps), 1)
        self.assertEqual(eps[0].participant.username, 'uname131')
    def test_should_return_processed_data_for_valid_data_for_location_and_campus_diff_campus_in_action_route_to_location_info(
            self):
        c1 = Campus(latitude=12.32434, longitude=56.4324, name='Some Campus1')
        self.test_db.session.add(c1)
        self.test_db.session.commit()

        c1_id = c1.id

        l1 = Location(latitude=12.32434,
                      longitude=56.4324,
                      name="loc332",
                      campus_id=c1_id)
        l2 = Location(latitude=22.32434, longitude=95.4324, name="loc255")
        self.test_db.session.add(l1)
        self.test_db.session.add(l2)
        self.test_db.session.commit()

        l1_id = l1.id
        l2_id = l2.id

        u1 = User(first_name='User22',
                  last_name='Last32',
                  username='******',
                  password='******',
                  location_id=l1_id)
        self.test_db.session.add(u1)
        self.test_db.session.commit()

        payload_data = {
            'result': {
                'parameters': {
                    'campus-location': 'loc255'
                },
                'fulfillment': {
                    'speech': 'Some message for route-to-location-request!'
                },
                'contexts': [{
                    'name': 'auth',
                    'parameters': {
                        'token': 'uname39'
                    }
                }],
                'action': 'route-to-location-request'
            }
        }
        result = self.app.post('/api/ai/fulfillment',
                               content_type='application/json',
                               data=json.dumps(payload_data))
        dict_val = json.loads(result.data)
        self.assertEqual(result.status_code, 200)
        # print(dict_val)
        str_resp = 'You are not in the same campus to View Routes!'
        self.assertEqual(dict_val['speech'], str_resp)
        self.assertEqual(
            dict_val['data']['web']['parameters']['fromLocation']['name'],
            'loc332')
        self.assertEqual(
            dict_val['data']['web']['parameters']['fromLocation']['latitude'],
            12.32434)
        self.assertEqual(
            dict_val['data']['web']['parameters']['toLocation']['name'],
            'loc255')
        self.assertEqual(
            dict_val['data']['web']['parameters']['toLocation']['longitude'],
            95.4324)
        self.assertEqual(dict_val['parameters']['fromLocation']['name'],
                         'loc332')
        self.assertEqual(dict_val['parameters']['fromLocation']['latitude'],
                         12.32434)
        self.assertEqual(dict_val['parameters']['toLocation']['name'],
                         'loc255')
        self.assertEqual(dict_val['parameters']['toLocation']['longitude'],
                         95.4324)
        self.assertEqual(dict_val['parameters']['noRoute'], 'true')