@@ -26,14 +26,18 @@ def setUp(self):
2626 self .app = Flask ('test_app' )
2727 self .api_client = self .app .test_client ()
2828 self .router = mock .Mock ()
29+ self .module1 = mock .Mock ()
30+ self .module2 = mock .Mock ()
31+ self .modules = {'module1' : self .module1 ,
32+ 'module2' : self .module2 }
2933
30- self .api = Api (self .app , self .router )
34+ self .api = Api (self .modules , self . app , self .router )
3135
3236 def test_list_implemented_methods (self ):
3337 self .router .list_implemented_methods .return_value = ['abcd' , 'efgh' ]
3438
3539 output = self .api_client .get ('/module1/' )
36- self .router .list_implemented_methods .assert_called_with (' module1' )
40+ self .router .list_implemented_methods .assert_called_with (self . module1 )
3741
3842 assert_that (json .loads (output .data .decode (output .charset )), is_ ({
3943 "implemented_methods" : [
@@ -57,7 +61,7 @@ def test_execute_method_returns_string(self):
5761 }
5862 ))
5963
60- self .router .invoke_method .assert_called_with (module_name = ' module2' , method = 'remote_method' , params = [], env = {'variable1' : 'value1' }, callback = {})
64+ self .router .invoke_method .assert_called_with (module = self . module2 , method = 'remote_method' , params = [], env = {'variable1' : 'value1' }, callback = {})
6165 assert_that (json .loads (output .data .decode (output .charset )), is_ ('simple string' ))
6266
6367 def test_execute_method_returns_list (self ):
@@ -75,6 +79,26 @@ def test_execute_method_returns_list(self):
7579 }
7680 ))
7781
78- self .router .invoke_method .assert_called_with (module_name = ' module2' , method = 'remote_method' , params = [], env = {'variable1' : 'value1' }, callback = {})
82+ self .router .invoke_method .assert_called_with (module = self . module2 , method = 'remote_method' , params = [], env = {'variable1' : 'value1' }, callback = {})
7983 assert_that (json .loads (output .data .decode (output .charset )), is_ (['a' , 'b' , 'c' ]))
8084
85+ def test_invoking_unknown_module_returns_a_404 (self ):
86+ output = self .api_client .post ('/new_module/' ,
87+ headers = {'Content-Type' : 'application/json' },
88+ data = json .dumps (
89+ {
90+ "method" : "remote_method" ,
91+ "params" : [],
92+ "env" : {
93+ "variable1" : "value1"
94+ },
95+ "callback" : {}
96+ }
97+ ))
98+
99+ assert_that (output .status_code , is_ (404 ))
100+
101+ def test_listing_unknown_module_returns_a_404 (self ):
102+ output = self .api_client .get ('/new_module/' )
103+
104+ assert_that (output .status_code , is_ (404 ))
0 commit comments