Best Python code snippet using locust
test_client.py
Source:test_client.py
1import unittest.mock2from pymessenger.bot import Bot3from programy.clients.restful.flask.facebook.client import FacebookBotClient4from programy.clients.restful.flask.facebook.config import FacebookConfiguration5from programytest.clients.arguments import MockArgumentParser6class MockFacebookBot(Bot):7 def __init__(self, access_token):8 pass9 def render_response(self, recipient_id, message):10 self._recipient_id = recipient_id11 self._message = message12 def send_raw(self, payload):13 self.payload = payload14class MockFacebookBotClient(FacebookBotClient):15 def __init__(self, argument_parser=None):16 FacebookBotClient.__init__(self, argument_parser)17 self.test_question = None18 self.payload = None19 def set_question(self, question):20 self.test_question = question21 def get_license_keys(self):22 self._access_token = "FACEBOOK_ACCESS_TOKEN"23 self._verify_token = "FACEBOOK_VERIFY_TOKEN"24 def ask_question(self, sessionid, question):25 if self.test_question is not None:26 return self.test_question27 return super(MockFacebookBotClient, self).ask_question(sessionid, question)28 def create_facebook_bot(self):29 return MockFacebookBot(self._access_token)30class Facebookclient_contextBotClientTests(unittest.TestCase):31 def test_facebook_client_init(self):32 arguments = MockArgumentParser()33 client = MockFacebookBotClient(arguments)34 self.assertIsNotNone(client)35 self.assertEquals("FACEBOOK_VERIFY_TOKEN", client._verify_token)36 self.assertEquals("FACEBOOK_ACCESS_TOKEN", client._access_token)37 self.assertIsInstance(client.get_client_configuration(), FacebookConfiguration)38 self.assertEquals('ProgramY AIML2.0 Facebook Client', client.get_description())39 self.assertIsInstance(client._facebook_bot, Bot)40 def test_hub_challenge(self):41 arguments = MockArgumentParser()42 client = MockFacebookBotClient(arguments)43 request = unittest.mock.Mock()44 request.args =unittest.mock.Mock()45 request.args.get.return_value = "XXZZ"46 self.assertEquals("XXZZ", client.get_hub_challenge(request))47 def test_hub_verify_token(self):48 arguments = MockArgumentParser()49 client = MockFacebookBotClient(arguments)50 request = unittest.mock.Mock()51 request.args =unittest.mock.Mock()52 request.args.get.return_value = "XXZZ"53 self.assertEquals("XXZZ", client.get_hub_verify_token(request))54 def test_verify_fb_token(self):55 arguments = MockArgumentParser()56 client = MockFacebookBotClient(arguments)57 request = unittest.mock.Mock()58 request.args =unittest.mock.Mock()59 request.args.get.return_value = "ZZZZZZ"60 client._verify_token = "XXXXXX"61 self.assertEquals("ZZZZZZ", client.verify_fb_token("XXXXXX", request))62 def test_render_response(self):63 arguments = MockArgumentParser()64 client = MockFacebookBotClient(arguments)65 client.render_response(client.create_client_context("user1"), "hello")66 self.assertIsNotNone(client._facebook_bot.payload)67 def test_return_hub_challenge(self):68 arguments = MockArgumentParser()69 client = MockFacebookBotClient(arguments)70 request = unittest.mock.Mock()71 request.args = unittest.mock.Mock()72 request.args.get.return_value = "ZZZZZZ"73 client._verify_token = "ZZZZZZ"74 self.assertEquals("ZZZZZZ", client.return_hub_challenge(request))75 def test_get_message_text(self):76 arguments = MockArgumentParser()77 client = MockFacebookBotClient(arguments)78 message = {}79 message['message'] = unittest.mock.Mock()80 message['message'].get.return_value = "Hello"81 self.assertEquals("Hello", client.get_message_text(message))82 def has_attachements(self):83 arguments = MockArgumentParser()84 client = MockFacebookBotClient(arguments)85 arguments = MockArgumentParser()86 client = MockFacebookBotClient(arguments)87 message = {}88 message['message'] = unittest.mock.Mock()89 message['message'].get.return_value = "Hello"90 self.assertEquals("Hello", client.get_message_text(message))91 def test_get_recipitent_id(self):92 arguments = MockArgumentParser()93 client = MockFacebookBotClient(arguments)94 message = {'message': {'sender': {'id': 'user1'}}}95 message['message'] = unittest.mock.Mock()96 message['message'].get.return_value = []97 self.assertTrue(client.has_attachements(message))98 def test_process_facebook_request(self):99 arguments = MockArgumentParser()100 client = MockFacebookBotClient(arguments)101 client.test_question = "Hi there"102 request = {'entry': [{'messaging': [{'message': {"text": "Hello"}, 'sender': {'id': 'user1'}}]}]}103 client.process_facebook_request(request)104 self.assertIsNotNone(client._facebook_bot.payload)105 def test_process_facebook_message(self):106 arguments = MockArgumentParser()107 client = MockFacebookBotClient(arguments)108 client.test_question = "Hi there"109 messaging = [{'message': {"text": "Hello"}, 'sender': {'id': 'user1'}}]110 client.process_facebook_message(messaging)111 self.assertIsNotNone(client._facebook_bot.payload)112 def test_handle_message(self):113 arguments = MockArgumentParser()114 client = MockFacebookBotClient(arguments)115 client.test_question = "Hi there"116 message = {'message': {"text": "Hello"}, 'sender': {'id': 'user1'}}117 client.handle_message(message)...
BUCK
Source:BUCK
1include_defs("//ReactAndroid/DEFS")2android_library(3 name = "shell",4 srcs = glob(["**/*.java"]),5 visibility = [6 "PUBLIC",7 ],8 deps = [9 react_native_dep("libraries/fresco/fresco-react-native:imagepipeline"),10 react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),11 react_native_dep("third-party/android/support/v4:lib-support-v4"),12 react_native_dep("third-party/java/infer-annotations:infer-annotations"),13 react_native_dep("third-party/java/jsr-305:jsr-305"),14 react_native_target("java/com/facebook/react:react"),15 react_native_target("java/com/facebook/react/animated:animated"),16 react_native_target("java/com/facebook/react/bridge:bridge"),17 react_native_target("java/com/facebook/react/common:common"),18 react_native_target("java/com/facebook/react/devsupport:devsupport"),19 react_native_target("java/com/facebook/react/flat:flat"),20 react_native_target("java/com/facebook/react/module/model:model"),21 react_native_target("java/com/facebook/react/modules/accessibilityinfo:accessibilityinfo"),22 react_native_target("java/com/facebook/react/modules/appstate:appstate"),23 react_native_target("java/com/facebook/react/modules/camera:camera"),24 react_native_target("java/com/facebook/react/modules/clipboard:clipboard"),25 react_native_target("java/com/facebook/react/modules/core:core"),26 react_native_target("java/com/facebook/react/modules/datepicker:datepicker"),27 react_native_target("java/com/facebook/react/modules/debug:debug"),28 react_native_target("java/com/facebook/react/modules/dialog:dialog"),29 react_native_target("java/com/facebook/react/modules/fresco:fresco"),30 react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"),31 react_native_target("java/com/facebook/react/modules/image:image"),32 react_native_target("java/com/facebook/react/modules/intent:intent"),33 react_native_target("java/com/facebook/react/modules/location:location"),34 react_native_target("java/com/facebook/react/modules/netinfo:netinfo"),35 react_native_target("java/com/facebook/react/modules/network:network"),36 react_native_target("java/com/facebook/react/modules/permissions:permissions"),37 react_native_target("java/com/facebook/react/modules/share:share"),38 react_native_target("java/com/facebook/react/modules/statusbar:statusbar"),39 react_native_target("java/com/facebook/react/modules/storage:storage"),40 react_native_target("java/com/facebook/react/modules/timepicker:timepicker"),41 react_native_target("java/com/facebook/react/modules/toast:toast"),42 react_native_target("java/com/facebook/react/modules/vibration:vibration"),43 react_native_target("java/com/facebook/react/modules/websocket:websocket"),44 react_native_target("java/com/facebook/react/uimanager:uimanager"),45 react_native_target("java/com/facebook/react/views/art:art"),46 react_native_target("java/com/facebook/react/views/drawer:drawer"),47 react_native_target("java/com/facebook/react/views/image:image"),48 react_native_target("java/com/facebook/react/views/modal:modal"),49 react_native_target("java/com/facebook/react/views/picker:picker"),50 react_native_target("java/com/facebook/react/views/progressbar:progressbar"),51 react_native_target("java/com/facebook/react/views/scroll:scroll"),52 react_native_target("java/com/facebook/react/views/slider:slider"),53 react_native_target("java/com/facebook/react/views/swiperefresh:swiperefresh"),54 react_native_target("java/com/facebook/react/views/switchview:switchview"),55 react_native_target("java/com/facebook/react/views/text:text"),56 react_native_target("java/com/facebook/react/views/text/frescosupport:frescosupport"),57 react_native_target("java/com/facebook/react/views/textinput:textinput"),58 react_native_target("java/com/facebook/react/views/toolbar:toolbar"),59 react_native_target("java/com/facebook/react/views/view:view"),60 react_native_target("java/com/facebook/react/views/viewpager:viewpager"),61 react_native_target("java/com/facebook/react/views/webview:webview"),62 react_native_target("res:shell"),63 ],...
0004_auto__del_facebookapp__del_facebookaccesstoken__del_unique_facebookacc.py
Source:0004_auto__del_facebookapp__del_facebookaccesstoken__del_unique_facebookacc.py
1# encoding: utf-82from south.db import db3from south.v2 import SchemaMigration4class Migration(SchemaMigration):5 def forwards(self, orm):6 7 # Removing unique constraint on 'FacebookAccessToken', fields ['app', 'account']8 db.delete_unique('facebook_facebookaccesstoken', ['app_id', 'account_id'])9 # Deleting model 'FacebookApp'10 db.delete_table('facebook_facebookapp')11 # Deleting model 'FacebookAccessToken'12 db.delete_table('facebook_facebookaccesstoken')13 # Deleting model 'FacebookAccount'14 db.delete_table('facebook_facebookaccount')15 def backwards(self, orm):16 17 # Adding model 'FacebookApp'18 db.create_table('facebook_facebookapp', (19 ('application_id', self.gf('django.db.models.fields.CharField')(max_length=80)),20 ('name', self.gf('django.db.models.fields.CharField')(max_length=40)),21 ('site', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['sites.Site'])),22 ('api_key', self.gf('django.db.models.fields.CharField')(max_length=80)),23 ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),24 ('application_secret', self.gf('django.db.models.fields.CharField')(max_length=80)),25 ))26 db.send_create_signal('facebook', ['FacebookApp'])27 # Adding model 'FacebookAccessToken'28 db.create_table('facebook_facebookaccesstoken', (29 ('access_token', self.gf('django.db.models.fields.CharField')(max_length=200)),30 ('account', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['facebook.FacebookAccount'])),31 ('app', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['facebook.FacebookApp'])),32 ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),33 ))34 db.send_create_signal('facebook', ['FacebookAccessToken'])35 # Adding unique constraint on 'FacebookAccessToken', fields ['app', 'account']36 db.create_unique('facebook_facebookaccesstoken', ['app_id', 'account_id'])37 # Adding model 'FacebookAccount'38 db.create_table('facebook_facebookaccount', (39 ('socialaccount_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['socialaccount.SocialAccount'], unique=True, primary_key=True)),40 ('social_id', self.gf('django.db.models.fields.CharField')(max_length=255, unique=True)),41 ('link', self.gf('django.db.models.fields.URLField')(max_length=200)),42 ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),43 ))44 db.send_create_signal('facebook', ['FacebookAccount'])45 models = {46 47 }...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!