1- # Copyright 2016 Internap.
1+ # Copyright 2016 Internap
22#
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
1616
1717from flexmock import flexmock , flexmock_teardown
1818
19- from ubersmith_remote_module_server import _remote_executor
20- from ubersmith_remote_module_server ._remote_executor import RemoteExecutor
19+ from tests import mock_ubersmith_client , mock_ubersmith_api
20+ from ubersmith_remote_module_server import remote
21+ from ubersmith_remote_module_server .exceptions import NoRequestContext , NamedArgumentsOnly
2122from ubersmith_remote_module_server .objects import RequestContext
22- from . import mock_ubersmith_client , mock_ubersmith_api
23+ from ubersmith_remote_module_server .remote import RemoteExecutor , ubersmith , \
24+ ConfiguredRequestContext
25+
26+
27+ class UbersmithCoreTest (unittest .TestCase ):
28+ def test_raises_when_out_of_context (self ):
29+ remote_executor_mock = flexmock ()
30+ flexmock (remote ).should_receive ('RemoteExecutor' ).and_return (remote_executor_mock )
31+ with self .assertRaises (NoRequestContext ):
32+ ubersmith .test ()
33+
34+ def test_raises_when_args (self ):
35+ remote_executor_mock = flexmock ()
36+ flexmock (remote ).should_receive ('RemoteExecutor' ).and_return (remote_executor_mock )
37+ with self .assertRaises (NamedArgumentsOnly ):
38+ ubersmith .test ('hello' )
39+
40+ def test_calls_executor_with_context_when_called (self ):
41+ remote_executor_mock = flexmock ()
42+ flexmock (remote ).should_receive ('RemoteExecutor' ). \
43+ with_args (context = 'context' ).and_return (remote_executor_mock ).once ()
44+ remote_executor_mock .should_receive ('invoke_global' ).with_args ('test' , args = {}).once ()
45+
46+ with ConfiguredRequestContext (context = 'context' ):
47+ ubersmith .test ()
48+
49+ def tearDown (self ):
50+ flexmock_teardown ()
51+ super (UbersmithCoreTest , self ).tearDown ()
2352
2453
2554class RemoteExecutorTest (unittest .TestCase ):
2655 def test_invoke_global_from_device_module (self ):
2756 ubersmith_client = mock_ubersmith_client ()
2857 ubersmith_api = mock_ubersmith_api ()
2958
30- flexmock (_remote_executor ).should_receive ('ubersmith_client' ).and_return (ubersmith_client )
59+ flexmock (remote ).should_receive ('ubersmith_client' ).and_return (ubersmith_client )
3160
3261 ubersmith_client .api .should_receive ('init' )\
3362 .with_args (url = 'http://ubersmith.example/url' ,
@@ -50,7 +79,7 @@ def test_invoke_global_from_service_module(self):
5079 ubersmith_client = mock_ubersmith_client ()
5180 ubersmith_api = mock_ubersmith_api ()
5281
53- flexmock (_remote_executor ).should_receive ('ubersmith_client' ).and_return (ubersmith_client )
82+ flexmock (remote ).should_receive ('ubersmith_client' ).and_return (ubersmith_client )
5483
5584 ubersmith_client .api .should_receive ('init' )\
5685 .with_args (url = 'http://ubersmith.example/url' ,
@@ -74,5 +103,3 @@ def test_invoke_global_from_service_module(self):
74103 def tearDown (self ):
75104 flexmock_teardown ()
76105 super (RemoteExecutorTest , self ).tearDown ()
77-
78-
0 commit comments