How to use session_start method in Slash

Best Python code snippet using slash

test_plugin_dependency.py

Source:test_plugin_dependency.py Github

copy

Full Screen

...11 @maybe_decorate(slash.plugins.needs('p'), not needs_decorate_method)12 @autoname13 class NeedsPlugin(PluginInterface):14 @maybe_decorate(slash.plugins.needs('p'), needs_decorate_method)15 def session_start(self):16 checkpoint2()17 @slash.plugins.active # pylint: disable=abstract-method, unused-variable18 @maybe_decorate(slash.plugins.provides('p'), not provides_decorate_method)19 @autoname20 class ProvidesPlugin(PluginInterface):21 @maybe_decorate(slash.plugins.provides('p'), provides_decorate_method)22 def session_start(self):23 checkpoint1()24 slash.hooks.session_start() # pylint: disable=no-member25 assert checkpoint1.timestamp < checkpoint2.timestamp26def test_provides_globally_needs_globally(checkpoint1, checkpoint2):27 '''28 Plugin A: Provides x at class level29 Plugin B: Needs x at class level30 '''31 @slash.plugins.provides('x')32 class PluginA(slash.plugins.interface.PluginInterface):33 def get_name(self):34 return 'plugin a'35 def session_start(self):36 checkpoint1()37 def test_start(self):38 pass39 @slash.plugins.needs('x')40 class PluginB(slash.plugins.interface.PluginInterface):41 def get_name(self):42 return 'plugin b'43 def session_start(self):44 checkpoint2()45 def error_added(self, result, error): # pylint: disable=unused-argument46 pass47 for plugin_cls in [PluginA, PluginB]:48 slash.plugins.manager.install(plugin_cls(), activate_later=True)49 slash.plugins.manager.activate_pending_plugins()50 slash.hooks.session_start() # pylint: disable=no-member51 assert checkpoint1.timestamp < checkpoint2.timestamp52 slash.plugins.manager.deactivate('plugin a')53 with pytest.raises(CannotResolveDependencies) as caught:54 slash.hooks.session_start() # pylint: disable=no-member55 assert caught.value.unmet_dependencies == set(['x'])56def test_provides_globally_needs_specific_hook(checkpoint1, checkpoint2):57 '''58 Plugin A: Provides x at class level59 Plugin B: Needs x for specific hook60 '''61 @slash.plugins.provides('x')62 class PluginA(slash.plugins.interface.PluginInterface):63 def get_name(self):64 return 'plugin a'65 def session_start(self):66 checkpoint1()67 def test_start(self):68 pass69 class PluginB(slash.plugins.interface.PluginInterface):70 def get_name(self):71 return 'plugin b'72 @slash.plugins.needs('x')73 def session_start(self):74 checkpoint2()75 def error_added(self, result, error): # pylint: disable=unused-argument76 pass77 for plugin_cls in [PluginA, PluginB]:78 slash.plugins.manager.install(plugin_cls(), activate_later=True)79 slash.plugins.manager.activate_pending_plugins()80 slash.hooks.session_start() # pylint: disable=no-member81 assert checkpoint1.timestamp < checkpoint2.timestamp82 slash.plugins.manager.deactivate('plugin a')83 with pytest.raises(CannotResolveDependencies) as caught:84 slash.hooks.session_start() # pylint: disable=no-member85 assert caught.value.unmet_dependencies == set(['x'])86def test_provides_globally_needs_specific_hook_which_does_not_exist_at_a(checkpoint2):87 '''88 Plugin A: Provides x at class level89 Plugin B: Needs x for specific hook, this hook does not definied in A90 Expectations:91 Should work in the empty sense92 all non-needing hooks should work, even when missing from A, the specific hook needs to happen in A before B.93 '''94 @slash.plugins.provides('x')95 class PluginA(slash.plugins.interface.PluginInterface):96 def get_name(self):97 return 'plugin a'98 def test_start(self):99 pass100 class PluginB(slash.plugins.interface.PluginInterface):101 def get_name(self):102 return 'plugin b'103 @slash.plugins.needs('x')104 def session_start(self):105 checkpoint2()106 def error_added(self, result, error): # pylint: disable=unused-argument107 pass108 for plugin_cls in [PluginA, PluginB]:109 slash.plugins.manager.install(plugin_cls(), activate_later=True)110 slash.plugins.manager.activate_pending_plugins()111 slash.hooks.session_start() # pylint: disable=no-member112 assert checkpoint2.called113 slash.plugins.manager.deactivate('plugin a')114 with pytest.raises(CannotResolveDependencies) as caught:115 slash.hooks.session_start() # pylint: disable=no-member116 assert caught.value.unmet_dependencies == set(['x'])117def test_provides_specific_hook_needs_globally(checkpoint1, checkpoint2):118 '''119 Plugin A: Provides x on a specific hook120 Plugin B: Needs x at class level121 Expectations:122 This case should fail, because logically the other hooks don't have anyone to provide X for them123 '''124 class PluginA(slash.plugins.interface.PluginInterface):125 def get_name(self):126 return 'plugin a'127 @slash.plugins.provides('x')128 def session_start(self):129 checkpoint1()130 def test_start(self):131 pass132 @slash.plugins.needs('x')133 class PluginB(slash.plugins.interface.PluginInterface):134 def get_name(self):135 return 'plugin b'136 def session_start(self):137 checkpoint2()138 def error_added(self, result, error): # pylint: disable=unused-argument139 pass140 for plugin_cls in [PluginA, PluginB]:141 slash.plugins.manager.install(plugin_cls(), activate_later=True)142 slash.plugins.manager.activate_pending_plugins()143 slash.hooks.session_start() # pylint: disable=no-member144 with pytest.raises(CannotResolveDependencies) as caught:145 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member146 assert caught.value.unmet_dependencies == set(['x'])147def test_provides_specific_hook_needs_globally_with_this_hook_only(checkpoint1, checkpoint2):148 '''149 Plugin A: Provides x on a specific hook150 Plugin B: Needs x at class level, but only has one hook (the one provided by A)151 '''152 class PluginA(slash.plugins.interface.PluginInterface):153 def get_name(self):154 return 'plugin a'155 @slash.plugins.provides('x')156 def session_start(self):157 checkpoint1()158 def test_start(self):159 pass160 @slash.plugins.needs('x')161 class PluginB(slash.plugins.interface.PluginInterface):162 def get_name(self):163 return 'plugin b'164 def session_start(self):165 checkpoint2()166 for plugin_cls in [PluginA, PluginB]:167 slash.plugins.manager.install(plugin_cls(), activate_later=True)168 slash.plugins.manager.activate_pending_plugins()169 slash.hooks.session_start() # pylint: disable=no-member170 assert checkpoint1.timestamp < checkpoint2.timestamp171 slash.plugins.manager.deactivate('plugin a')172 with pytest.raises(CannotResolveDependencies) as caught:173 slash.hooks.session_start() # pylint: disable=no-member174 assert caught.value.unmet_dependencies == set(['x'])175@pytest.mark.parametrize('needs_parent_level', [True, False])176@pytest.mark.parametrize('provides_parent_level', [True, False])177def test_provides_needs_with_inheritence_on_class_level(checkpoint, checkpoint1, checkpoint2, needs_parent_level, provides_parent_level):178 '''179 Plugin A: Provides x in class level (by it self or by inheritence)180 Plugin b: Needs x in class level (by it self or by inheritence)181 '''182 # pylint: disable=abstract-method183 @maybe_decorate(slash.plugins.provides('x'), provides_parent_level)184 class PluginAParent(slash.plugins.interface.PluginInterface):185 def test_start(self):186 pass187 @maybe_decorate(slash.plugins.provides('x'), not provides_parent_level)188 class PluginA(PluginAParent):189 def get_name(self):190 return 'plugin a'191 def session_start(self):192 checkpoint1()193 @maybe_decorate(slash.plugins.needs('x'), needs_parent_level)194 class PluginBParent(slash.plugins.interface.PluginInterface):195 def error_added(self, result, error): # pylint: disable=unused-argument196 checkpoint()197 @maybe_decorate(slash.plugins.needs('x'), not needs_parent_level)198 class PluginB(PluginBParent):199 def get_name(self):200 return 'plugin b'201 def session_start(self):202 checkpoint2()203 for plugin_cls in [PluginA, PluginB]:204 slash.plugins.manager.install(plugin_cls(), activate_later=True)205 slash.plugins.manager.activate_pending_plugins()206 # session_start hook should be provided the PluginA.session_start method207 slash.hooks.session_start() # pylint: disable=no-member208 assert checkpoint1.timestamp < checkpoint2.timestamp209 # error_added hook should be provided by empty registration of pluginA210 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member211 assert checkpoint.called212 slash.plugins.manager.deactivate('plugin a')213 with pytest.raises(CannotResolveDependencies) as caught:214 slash.hooks.session_start() # pylint: disable=no-member215 assert caught.value.unmet_dependencies == set(['x'])216 with pytest.raises(CannotResolveDependencies) as caught:217 slash.hooks.error_added() # pylint: disable=no-member218 assert caught.value.unmet_dependencies == set(['x'])219 # Ensure only hooks required by PluginB fails220 slash.hooks.test_end() # pylint: disable=no-member221def test_provides_needs_in_both_inheritence_levels(checkpoint, checkpoint1, checkpoint2):222 # pylint: disable=abstract-method223 @slash.plugins.provides('x')224 class PluginAParent(slash.plugins.interface.PluginInterface):225 def test_start(self):226 pass227 @slash.plugins.provides('y')228 class PluginA(PluginAParent):229 def get_name(self):230 return 'plugin a'231 def session_start(self):232 checkpoint1()233 @slash.plugins.needs('x')234 class PluginBParent(slash.plugins.interface.PluginInterface):235 def error_added(self, result, error): # pylint: disable=unused-argument236 checkpoint()237 @slash.plugins.needs('y')238 class PluginB(PluginBParent):239 def get_name(self):240 return 'plugin b'241 def session_start(self):242 checkpoint2()243 for plugin_cls in [PluginA, PluginB]:244 slash.plugins.manager.install(plugin_cls(), activate_later=True)245 slash.plugins.manager.activate_pending_plugins()246 # session_start hook should be provided the PluginA.session_start method247 slash.hooks.session_start() # pylint: disable=no-member248 assert checkpoint1.timestamp < checkpoint2.timestamp249 # error_added hook should be provided by empty registration of pluginA250 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member251 assert checkpoint.called252 slash.plugins.manager.deactivate('plugin a')253 with pytest.raises(CannotResolveDependencies) as caught:254 slash.hooks.session_start() # pylint: disable=no-member255 assert caught.value.unmet_dependencies == set(['x', 'y'])256 with pytest.raises(CannotResolveDependencies) as caught:257 slash.hooks.error_added() # pylint: disable=no-member258 assert caught.value.unmet_dependencies == set(['x', 'y'])259 # Ensure only hooks required by PluginB fails260 slash.hooks.test_end() # pylint: disable=no-member261def test_provides_needs_with_inheritence_on_method_level(checkpoint):262 '''263 Plugin A: Provides x in method level (by it self or by inheritence) to test_start & session_start264 Plugin b: Needs x in method level (by it self or by inheritence) on test_start & session_start265 '''266 # pylint: disable=abstract-method267 session_start_a = Checkpoint()268 session_start_b = Checkpoint()269 test_start_a = Checkpoint()270 test_start_b = Checkpoint()271 class PluginAParent(slash.plugins.interface.PluginInterface):272 @slash.plugins.provides('x')273 def test_start(self):274 test_start_a()275 class PluginA(PluginAParent):276 def get_name(self):277 return 'plugin a'278 @slash.plugins.provides('x')279 def session_start(self):280 session_start_a()281 class PluginBParent(slash.plugins.interface.PluginInterface):282 @slash.plugins.needs('x')283 def session_start(self):284 session_start_b()285 def error_added(self, result, error): # pylint: disable=unused-argument286 checkpoint()287 class PluginB(PluginBParent):288 def get_name(self):289 return 'plugin b'290 @slash.plugins.needs('x')291 def test_start(self):292 test_start_b()293 for plugin_cls in [PluginA, PluginB]:294 slash.plugins.manager.install(plugin_cls(), activate_later=True)295 slash.plugins.manager.activate_pending_plugins()296 slash.hooks.session_start() # pylint: disable=no-member297 assert session_start_a.timestamp < session_start_b.timestamp298 slash.hooks.test_start() # pylint: disable=no-member299 assert test_start_a.timestamp < test_start_b.timestamp300 # error_added hook should not need anything301 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member302 assert checkpoint.called303 slash.plugins.manager.deactivate('plugin a')304 with pytest.raises(CannotResolveDependencies) as caught:305 slash.hooks.session_start() # pylint: disable=no-member306 assert caught.value.unmet_dependencies == set(['x'])307 with pytest.raises(CannotResolveDependencies) as caught:308 slash.hooks.test_start() # pylint: disable=no-member309 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member310 assert caught.value.unmet_dependencies == set(['x'])311def test_provides_needs_with_child_overrides():312 # pylint: disable=line-too-long313 '''314 | Hook Name | Plugin A | Plugin B |315 |---------------+-------------------------------------------------------------------------+------------------------------------------------------------------------|316 | session_start | Child Provides x in method level, overrides parent's empty registration | Needs x (Parent) & y (Child) in class level |317 | test_start | Child Provides x in method level, overrides parent's real registration | Needs x (Parent) & y (Child) in class level |318 | error_added | x is not provided, overrides parent's real registration | Needs x (Parent) & y (Child) in class level |319 | test_end | x is not provided, overrides parent's empty registration | Needs x (Parent) & y (Child) in class level |320 | session_end | Parent provides x, child provides y - both in class level | Needs x (Parent) & y (Child) in class level, z in (child) method level |321 '''322 # pylint: disable=abstract-method323 session_start_a = Checkpoint()324 session_start_b = Checkpoint()325 test_start_a = Checkpoint()326 test_start_b = Checkpoint()327 @slash.plugins.provides('x')328 class PluginAParent(slash.plugins.interface.PluginInterface):329 def test_start(self):330 test_start_a()331 def error_added(self, result, error): # pylint: disable=unused-argument332 pass333 def session_end(self):334 pass335 @slash.plugins.provides('y')336 class PluginA(PluginAParent):337 def get_name(self):338 return 'plugin a'339 @slash.plugins.provides('x')340 def session_start(self):341 # Overrides empty registration of PluginAParent342 session_start_a()343 @slash.plugins.provides('x')344 def test_start(self):345 # Overrides "real" registration of PluginAParent346 test_start_a()347 def error_added(self, result, error): # pylint: disable=unused-argument348 # Overrides "real" registration of PluginAParent349 pass350 def test_end(self):351 # Overrides empty registration of PluginAParent352 pass353 @slash.plugins.needs('x')354 class PluginBParent(slash.plugins.interface.PluginInterface):355 def session_start(self):356 session_start_b()357 def error_added(self, result, error): # pylint: disable=unused-argument358 pass359 def test_start(self):360 test_start_b()361 def test_end(self):362 pass363 @slash.plugins.needs('y')364 class PluginB(PluginBParent):365 def get_name(self):366 return 'plugin b'367 @slash.plugins.needs('z')368 def session_end(self):369 pass370 for plugin_cls in [PluginA, PluginB]:371 slash.plugins.manager.install(plugin_cls(), activate_later=True)372 slash.plugins.manager.activate_pending_plugins()373 slash.hooks.session_start() # pylint: disable=no-member374 assert session_start_a.timestamp < session_start_b.timestamp375 slash.hooks.test_start() # pylint: disable=no-member376 assert test_start_a.timestamp < test_start_b.timestamp377 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member378 slash.hooks.test_end() # pylint: disable=no-member379 with pytest.raises(CannotResolveDependencies) as caught:380 slash.hooks.session_end() # pylint: disable=no-member381 assert caught.value.unmet_dependencies == set(['z'])382 slash.plugins.manager.deactivate('plugin a')383 with pytest.raises(CannotResolveDependencies) as caught:384 slash.hooks.session_start() # pylint: disable=no-member385 assert caught.value.unmet_dependencies == set(['x', 'y'])386 with pytest.raises(CannotResolveDependencies) as caught:387 slash.hooks.test_start() # pylint: disable=no-member388 assert caught.value.unmet_dependencies == set(['x', 'y'])389 with pytest.raises(CannotResolveDependencies) as caught:390 slash.hooks.error_added(result=None, error=None) # pylint: disable=no-member391 assert caught.value.unmet_dependencies == set(['x', 'y'])392 with pytest.raises(CannotResolveDependencies) as caught:393 slash.hooks.test_end() # pylint: disable=no-member394 assert caught.value.unmet_dependencies == set(['x', 'y'])395 with pytest.raises(CannotResolveDependencies) as caught:396 slash.hooks.session_end() # pylint: disable=no-member397 assert caught.value.unmet_dependencies == set(['x', 'y', 'z'])398def autoname(plugin):...

Full Screen

Full Screen

test_session.py

Source:test_session.py Github

copy

Full Screen

1import datetime2import pytest3from dynamo.entities import Session, itemToSession # pylint: disable=wrong-import-position4# The unique visitor ID5visitor_id = '171a0329-f8b2-499c-867d-1942384ddd5f'6# The time when the session began7session_start = '2021-02-10T11:27:43.262Z'8# The number of seconds the average page was on9avg_time = 2.82610# The length of the session11total_time = 8.47812def test_default_init():13 session = Session( session_start, visitor_id, avg_time, total_time )14 assert session.sessionStart == datetime.datetime.strptime(15 session_start, '%Y-%m-%dT%H:%M:%S.%fZ'16 )17 assert session.id == visitor_id18 assert session.avgTime == avg_time19 assert session.totalTime == total_time20def test_datetime_init():21 session = Session(22 datetime.datetime.strptime(23 session_start, '%Y-%m-%dT%H:%M:%S.%fZ'24 ), 25 visitor_id, avg_time, total_time26 )27 assert session.sessionStart == datetime.datetime.strptime(28 session_start, '%Y-%m-%dT%H:%M:%S.%fZ'29 )30 assert session.id == visitor_id31 assert session.avgTime == avg_time32 assert session.totalTime == total_time33def test_key():34 session = Session(35 session_start, visitor_id, avg_time, total_time36 )37 assert session.key() == {38 'PK': { 'S': f'VISITOR#{ visitor_id }' },39 'SK': { 'S': f'SESSION#{ session_start }' }40 }41def test_pk():42 session = Session(43 session_start, visitor_id, avg_time, total_time44 )45 assert session.pk() == { 'S': f'VISITOR#{ visitor_id }' }46def test_gsi2():47 session = Session(48 session_start, visitor_id, avg_time, total_time49 )50 assert session.gsi2() == {51 'GSI2PK': { 'S': f'SESSION#{ visitor_id }#{ session_start }' },52 'GSI2SK': { 'S': '#SESSION' }53 }54def test_gsi2pk():55 session = Session(56 session_start, visitor_id, avg_time, total_time57 )58 assert session.gsi2pk() == {59 'S': f'SESSION#{ visitor_id }#{ session_start }'60 }61def test_toItem():62 session = Session(63 session_start, visitor_id, avg_time, total_time64 )65 assert session.toItem() == {66 'PK': { 'S': f'VISITOR#{ visitor_id }' },67 'SK': { 'S': f'SESSION#{ session_start }' },68 'GSI2PK': { 'S': f'SESSION#{ visitor_id }#{ session_start }' },69 'GSI2SK': { 'S': '#SESSION' },70 'Type': { 'S': 'session' },71 'AverageTime': { 'N': str( avg_time ) },72 'TotalTime': { 'N': str( total_time ) }73 }74def test_repr():75 session = Session(76 session_start, visitor_id, avg_time, total_time77 )78 assert repr( session ) == f'{ visitor_id } - { total_time }'79def test_itemToSession():80 session = Session(81 session_start, visitor_id, avg_time, total_time82 )83 newSession = itemToSession( session.toItem() )84 assert newSession.sessionStart == session.sessionStart85 assert newSession.id == session.id86 assert newSession.avgTime == session.avgTime87 assert newSession.totalTime == session.totalTime88def test_itemToSession_exception():89 with pytest.raises( Exception ) as e:90 assert itemToSession( {} )...

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 Slash 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