How to use get_activities method in Airtest

Best Python code snippet using Airtest

test_state.py

Source:test_state.py Github

copy

Full Screen

...533 return activity, response_activity534 def test_add_conversation(self):535 activity, response_activity = self._get_activity(1)536 self.state.save_activity(activity)537 self.assertEqual(self.state.get_activities(), [response_activity])538 def test_add_multiple_conversations(self):539 response_activities = []540 for n in range(1, 15):541 activity, response_activity = self._get_activity(n)542 self.state.save_activity(activity)543 response_activities.append(response_activity)544 self.assertEqual(self.state.get_activities(), response_activities[-10:])545 self.assertEqual(len(self.state.get_activities()), 10)546 def test_add_multiple_conversations_with_argument(self):547 response_activities = []548 for n in range(1, 15):549 activity, response_activity = self._get_activity(n)550 self.state.save_activity(activity)551 response_activities.append(response_activity)552 self.assertEqual(self.state.get_activities(count=5), response_activities[-5:])553 self.assertEqual(len(self.state.get_activities(count=5)), 5)554 self.assertEqual(self.state.get_activities(count=15), response_activities[-15:])555 self.assertEqual(len(self.state.get_activities(count=-1)), 14)556 self.assertEqual(len(self.state.get_activities(count=100)), 14)557 def test_maximum_stored(self):558 for n in range(1, 60):559 activity, __ = self._get_activity(n)560 self.state.save_activity(activity)561 self.assertEqual(len(self.state.get_activities(count=-1)), 50)562 def test_get_conversation_id(self):563 response_activities = {}564 combined_response = []565 simple_combined_response = []566 multi = 0567 for conversation_id in ['conv1', 'conv2']:568 response_activities[conversation_id] = []569 for n in range(1, 4):570 n += multi * 3571 activity, response_activity = self._get_activity(n, conversation_id)572 self.state.save_activity(activity)573 response_activities[conversation_id].append(response_activity)574 combined_response.append(response_activity)575 simple_combined_response.append(response_activity['activity']['text'])576 multi += 1577 self.assertEqual(self.state.get_activities(), combined_response, combined_response)578 self.assertEqual(self.state.get_activities(simple=True), simple_combined_response)579 self.assertEqual(len(self.state.get_activities()), 6)580 self.assertEqual(self.state.get_activities(conversation_id='conv1'), response_activities['conv1'])581 self.assertEqual(self.state.get_activities(conversation_id='conv2'), response_activities['conv2'])582 self.assertEqual(len(self.state.get_activities(conversation_id='conv1')), 3)583 self.assertEqual(len(self.state.get_activities(conversation_id='conv2')), 3)584 def test_get_conversation_id_limit(self):585 response_activities = {}586 simple_response_activities = {}587 combined_response = []588 simple_combined_response = []589 multi = 0590 for conversation_id in ['conv1', 'conv2']:591 response_activities[conversation_id] = []592 simple_response_activities[conversation_id] = []593 for n in range(1, 31):594 n += multi * 30595 activity, response_activity = self._get_activity(n, conversation_id)596 self.state.save_activity(activity)597 response_activities[conversation_id].append(response_activity)598 simple_response_activities[conversation_id].append(response_activity['activity']['text'])599 combined_response.append(response_activity)600 simple_combined_response.append(response_activity['activity']['text'])601 multi += 1602 self.assertEqual(self.state.get_activities(), combined_response[-10:])603 self.assertEqual(self.state.get_activities(simple=True), simple_combined_response[-10:])604 self.assertEqual(len(self.state.get_activities()), 10)605 self.assertEqual(self.state.get_activities(conversation_id='conv1'), response_activities['conv1'][-10:])606 self.assertEqual(self.state.get_activities(conversation_id='conv2'), response_activities['conv2'][-10:])607 self.assertEqual(self.state.get_activities(conversation_id='conv1', simple=True), simple_response_activities['conv1'][-10:])608 self.assertEqual(self.state.get_activities(conversation_id='conv2', simple=True), simple_response_activities['conv2'][-10:])609 self.assertEqual(len(self.state.get_activities(conversation_id='conv1')), 10)610 self.assertEqual(len(self.state.get_activities(conversation_id='conv2')), 10)611 def test_get_conversation_id_alternate(self):612 response_activities = {}613 combined_response = []614 response_activities['conv1'] = []615 response_activities['conv2'] = []616 for n in range(1, 61, 2):617 multi = 0618 for conversation_id in ['conv1', 'conv2']:619 n += multi620 activity, response_activity = self._get_activity(n, conversation_id)621 self.state.save_activity(activity)622 response_activities[conversation_id].append(response_activity)623 combined_response.append(response_activity)624 multi += 1625 self.assertEqual(self.state.get_activities(), combined_response[-10:])626 self.assertEqual(len(self.state.get_activities()), 10)627 self.assertEqual(self.state.get_activities(conversation_id='conv1'), response_activities['conv1'][-10:])628 self.assertEqual(self.state.get_activities(conversation_id='conv2'), response_activities['conv2'][-10:])629 self.assertEqual(self.state.get_activities(conversation_id='conv3'), [])630 self.assertEqual(len(self.state.get_activities(conversation_id='conv1')), 10)631 self.assertEqual(len(self.state.get_activities(conversation_id='conv2')), 10)632 self.assertEqual(len(self.state.get_activities(conversation_id='conv3')), 0)633 # Test limits634 self.assertEqual(len(self.state.get_activities(count=50, conversation_id='conv2')), 25)635 self.assertEqual(len(self.state.get_activities(count=5, conversation_id='conv2')), 5)636 def test_get_conversation_id_different_types(self):637 values = ['received', 'ReplyToActivity', 'SendToConversation', 'DeleteActivity', 'CreateConversation', 'GetConversationMembers',638 'GetActivityMembers']639 get_type = self._get_type(values)640 simple_response_activities = {}641 simple_combined_response = []642 simple_response_activities['conv1'] = []643 simple_response_activities['conv2'] = []644 for n in range(1, 61, 2):645 multi = 0646 for conversation_id in ['conv1', 'conv2']:647 n += multi648 activity, response_activity = self._get_activity(n, conversation_id, type=next(get_type))649 self.state.save_activity(activity)650 if 'text' in response_activity['activity']:651 simple_response_activities[conversation_id].append(response_activity['activity']['text'])652 if 'text' in response_activity['activity']:653 simple_combined_response.append(response_activity['activity']['text'])654 multi += 1655 self.assertEqual(len(self.state.get_activities(simple=True)), 10)656 self.assertEqual(self.state.get_activities(simple=True), simple_combined_response[-10:])657 self.assertEqual(len(self.state.get_activities(conversation_id='conv1', simple=True)), 10)658 self.assertEqual(len(self.state.get_activities(conversation_id='conv2', simple=True)), 10)659 self.assertEqual(len(self.state.get_activities(conversation_id='conv3', simple=True)), 0)660 self.assertEqual(self.state.get_activities(conversation_id='conv1', simple=True), simple_response_activities['conv1'][-10:])661 self.assertEqual(self.state.get_activities(conversation_id='conv2', simple=True), simple_response_activities['conv2'][-10:])662 self.assertEqual(self.state.get_activities(conversation_id='conv3', simple=True), [])663 # Test limits664 self.assertEqual(len(self.state.get_activities(count=50, conversation_id='conv2', simple=True)), 10)665 self.assertEqual(len(self.state.get_activities(count=5, conversation_id='conv2', simple=True)), 5)666 @staticmethod667 def _get_type(values):668 position = 0669 while True:670 actual_position = position % 7671 yield values[actual_position]672 position += 1673class MongodbStateTestCase(JsonStateTestCase):674 def setUp(self):675 self.config = Config(os.getcwd() + '/microsoftbotframework/tests/test_files/mongodb_test_config.yaml')676 self._drop_database()677 self.state = MongodbState(self.config, database='testmongodbstate')678 def tearDown(self):679 # remove any name or age values...

Full Screen

Full Screen

test_db_events_get_activities.py

Source:test_db_events_get_activities.py Github

copy

Full Screen

...18 activity_name = activities[0][1]19 db.new_fav(test_email, activity_name)20 db.add_event(test_email, datetime1, datetime3, activity_name, None)21 date = datetime1.replace(hour = 0, minute = 0)22 activities = db.get_activities(date, test_email)23 24 assert len(activities) == 125 assert (activity_name, datetime1.isoformat(), datetime3.isoformat(), None) in activities26 27 @patch('src.database.db.config', side_effect=fake_config)28 def test_daily_simple(self, _):29 activities = db.all_activities()30 activity_name = activities[0][1]31 db.new_fav(test_email, activity_name)32 db.add_event(test_email, datetime1, datetime10, activity_name, 'DAILY')33 date = datetime1.replace(hour = 0, minute = 0)34 activities_day_before = db.get_activities(date - timedelta(days = 1), test_email)35 activities_same_day = db.get_activities(date, test_email)36 activities_day_after = db.get_activities(date + timedelta(days = 1), test_email)37 activities_long_after = db.get_activities(date + timedelta(days = 10000), test_email)38 39 assert len(activities_day_before) == 040 41 assert len(activities_same_day) == 142 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'DAILY') in activities_same_day43 44 assert len(activities_day_after) == 145 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'DAILY') in activities_day_after46 47 assert len(activities_long_after) == 148 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'DAILY') in activities_long_after49 50 @patch('src.database.db.config', side_effect=fake_config)51 def test_weekly_simple(self, _):52 activities = db.all_activities()53 activity_name = activities[0][1]54 db.new_fav(test_email, activity_name)55 db.add_event(test_email, datetime1, datetime10, activity_name, 'WEEKLY')56 date = datetime1.replace(hour = 0, minute = 0)57 activities_week_before = db.get_activities(date - timedelta(days = 7), test_email)58 activities_same_day = db.get_activities(date, test_email)59 activities_week_after = db.get_activities(date + timedelta(days = 7), test_email)60 activities_wrong_dow = db.get_activities(date + timedelta(days = 11), test_email)61 activities_long_after = db.get_activities(date + timedelta(days = 7*10000), test_email)62 activities_long_after_wrong_dow = db.get_activities(date + timedelta(days = 7*10000+6), test_email)63 64 assert len(activities_week_before) == 065 66 assert len(activities_wrong_dow) == 067 68 assert len(activities_same_day) == 169 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'WEEKLY') in activities_same_day70 71 assert len(activities_week_after) == 172 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'WEEKLY') in activities_week_after73 74 assert len(activities_long_after) == 175 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'WEEKLY') in activities_long_after76 77 assert len(activities_long_after_wrong_dow) == 078 79 @patch('src.database.db.config', side_effect=fake_config)80 def test_weekly_long_event(self, _):81 activities = db.all_activities()82 activity_name = activities[0][1]83 db.new_fav(test_email, activity_name)84 #Tuesday to Friday85 db.add_event(test_email, datetime1, datetime4, activity_name, 'WEEKLY')86 date = datetime1.replace(hour = 0, minute = 0)87 activities_week_before_correct = db.get_activities(date - timedelta(days = 5), test_email)88 activities_same_week_correct = db.get_activities(date + timedelta(days = 2), test_email)89 activities_same_week_wrong = db.get_activities(date + timedelta(days = 6), test_email)90 activities_long_after_correct = db.get_activities(date + timedelta(days = 7*1000 + 2), test_email)91 activities_long_after_wrong = db.get_activities(date + timedelta(days = 7*1000 + 4), test_email)92 93 assert len(activities_week_before_correct) == 094 95 assert len(activities_same_week_wrong) == 096 97 assert len(activities_long_after_wrong) == 098 99 assert len(activities_same_week_correct) == 1100 assert (activity_name, datetime1.isoformat(), datetime4.isoformat(), 'WEEKLY') in activities_same_week_correct101 102 assert len(activities_long_after_correct) == 1103 assert (activity_name, datetime1.isoformat(), datetime4.isoformat(), 'WEEKLY') in activities_long_after_correct104 105 @patch('src.database.db.config', side_effect=fake_config)106 def test_monthly_simple(self, _):107 activities = db.all_activities()108 activity_name = activities[0][1]109 db.new_fav(test_email, activity_name)110 db.add_event(test_email, datetime1, datetime10, activity_name, 'MONTHLY')111 date = datetime1.replace(hour = 0, minute = 0)112 activities_month_before = db.get_activities(date_minus_one_month(date), test_email)113 activities_same_day = db.get_activities(date, test_email)114 activities_month_after = db.get_activities(date_plus_one_month(date), test_email)115 activities_wrong_day = db.get_activities(date + timedelta(days = 11), test_email)116 activities_long_after = db.get_activities(date_plus_x_months(date, 1000), test_email)117 activities_long_after_wrong_day = db.get_activities(date_plus_x_months(date, 1000) + timedelta(days = 11), test_email)118 119 assert len(activities_month_before) == 0120 121 assert len(activities_wrong_day) == 0122 123 assert len(activities_same_day) == 1124 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'MONTHLY') in activities_same_day125 126 assert len(activities_month_after) == 1127 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'MONTHLY') in activities_month_after128 129 assert len(activities_long_after) == 1130 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'MONTHLY') in activities_long_after131 132 assert len(activities_long_after_wrong_day) == 0133 134 @patch('src.database.db.config', side_effect=fake_config)135 def test_monthly_long_event(self, _):136 activities = db.all_activities()137 activity_name = activities[0][1]138 db.new_fav(test_email, activity_name)139 #from 10.19 to 11.03140 db.add_event(test_email, datetime1, datetime11, activity_name, 'MONTHLY')141 date = datetime1.replace(hour = 0, minute = 0)142 activities_month_before_correct = db.get_activities(date_minus_one_month(date) + timedelta(days = 5), test_email)143 activities_same_month_correct = db.get_activities(date + timedelta(days = 13), test_email)144 activities_same_month_wrong = db.get_activities(date + timedelta(days = 29), test_email)145 activities_long_after_correct = db.get_activities(date_plus_x_months(date, 1000) + timedelta(days = 6), test_email)146 activities_long_after_wrong_day = db.get_activities(date_plus_x_months(date, 4000) - timedelta(days = 2), test_email)147 148 assert len(activities_month_before_correct) == 0149 150 assert len(activities_same_month_wrong) == 0151 152 assert len(activities_long_after_wrong_day) == 0153 154 assert len(activities_same_month_correct) == 1155 assert (activity_name, datetime1.isoformat(), datetime11.isoformat(), 'MONTHLY') in activities_same_month_correct156 157 assert len(activities_long_after_correct) == 1158 assert (activity_name, datetime1.isoformat(), datetime11.isoformat(), 'MONTHLY') in activities_long_after_correct159 160 @patch('src.database.db.config', side_effect=fake_config)161 def test_yearly_simple(self, _):162 activities = db.all_activities()163 activity_name = activities[0][1]164 db.new_fav(test_email, activity_name)165 db.add_event(test_email, datetime1, datetime10, activity_name, 'YEARLY')166 date = datetime1.replace(hour = 0, minute = 0)167 activities_year_before = db.get_activities(date_minus_x_years(date, 1), test_email)168 activities_same_day = db.get_activities(date, test_email)169 activities_year_after = db.get_activities(date_plus_x_years(date, 1), test_email)170 activities_wrong_day = db.get_activities(date + timedelta(days = 111), test_email)171 activities_long_after = db.get_activities(date_plus_x_years(date, 1000), test_email)172 activities_long_after_wrong_day = db.get_activities(date_plus_x_years(date, 2000) + timedelta(days = 200), test_email)173 174 assert len(activities_year_before) == 0175 176 assert len(activities_wrong_day) == 0177 178 assert len(activities_same_day) == 1179 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'YEARLY') in activities_same_day180 181 assert len(activities_year_after) == 1182 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'YEARLY') in activities_year_after183 184 assert len(activities_long_after) == 1185 assert (activity_name, datetime1.isoformat(), datetime10.isoformat(), 'YEARLY') in activities_long_after186 187 assert len(activities_long_after_wrong_day) == 0188 189 @patch('src.database.db.config', side_effect=fake_config)190 def test_yearly_long_event(self, _):191 activities = db.all_activities()192 activity_name = activities[0][1]193 db.new_fav(test_email, activity_name)194 #from 10.19 to 04.30195 db.add_event(test_email, datetime1, datetime12, activity_name, 'YEARLY')196 date = datetime1.replace(hour = 0, minute = 0)197 activities_year_before_correct = db.get_activities(date_minus_x_years(date, 1) + timedelta(days = 50), test_email)198 activities_same_year_correct = db.get_activities(date + timedelta(days = 130), test_email)199 activities_same_year_wrong = db.get_activities(date + timedelta(days = 290), test_email)200 activities_long_after_correct = db.get_activities(date_plus_x_years(date, 1000) + timedelta(days = 60), test_email)201 activities_long_after_wrong_day = db.get_activities(date_plus_x_years(date, 4000) - timedelta(days = 20), test_email)202 203 assert len(activities_year_before_correct) == 0204 205 assert len(activities_same_year_wrong) == 0206 207 assert len(activities_long_after_wrong_day) == 0208 209 assert len(activities_same_year_correct) == 1210 assert (activity_name, datetime1.isoformat(), datetime12.isoformat(), 'YEARLY') in activities_same_year_correct211 212 assert len(activities_long_after_correct) == 1...

Full Screen

Full Screen

test_activity.py

Source:test_activity.py Github

copy

Full Screen

...28 organization=org)29 Session.add(project2)30 self.flush()31 32 act = activity.get_activities(organization=org)33 34 assert len(act) == 235 assert act[0].type == activity.NewProject.TYPE36 assert act[0].project == project237 assert act[0].get_message()38 assert act[1].type == activity.NewProject.TYPE39 assert act[1].project == project40 assert act[1].get_message()41 42 act = activity.get_activities(project=project)43 assert len(act) == 144 assert act[0].type == activity.NewProject.TYPE45 assert act[0].project == project46 assert act[0].get_message()47 48 act = activity.get_activities(user=normal)49 assert len(act) == 150 assert act[0].type == activity.NewProject.TYPE51 assert act[0].project == project52 assert act[0].get_message()53 54 def test_project_add_change(self):55 56 u = fh.create_user()57 org = fh.create_organization(subdomain=u'one')58 orguser = org.attach_user(u)59 self.flush()60 project = p.Project(name=u"foobar",61 creator=u,62 description=u"description",63 organization=org)64 Session.add(project)65 66 filepath = file_path('ffcc00.gif')67 change = project.add_change(u, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change")68 self.flush()69 70 act = activity.get_activities(organization=org)71 assert len(act) == 272 assert act[0].type == activity.NewFile.TYPE73 assert act[0].get_message()74 75 filepath = file_path('ffcc00.gif')76 change = project.add_change(u, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change")77 self.flush()78 79 act = activity.get_activities(organization=org)80 assert len(act) == 381 assert act[0].type == activity.NewVersion.TYPE82 assert act[0].get_message()83 84 comment = change.add_comment(u, "This is a comment")85 self.flush()86 87 reply = change.add_comment(u, "This is a reply", in_reply_to=comment)88 self.flush()89 90 act = activity.get_activities(organization=org)91 assert len(act) == 592 assert act[0].type == activity.NewReply.TYPE93 assert act[0].get_message()94 assert act[1].type == activity.NewComment.TYPE95 assert act[1].get_message()96 97 comment.set_completion_status(u, STATUS_COMPLETED)98 self.flush()99 comment.set_completion_status(u, STATUS_OPEN)100 self.flush()101 102 act = activity.get_activities(organization=org)103 assert len(act) == 7104 assert act[0].type == activity.CommentComplete.TYPE105 assert 'uncompleted' in act[0].get_message()106 assert act[1].type == activity.CommentComplete.TYPE...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful