diff --git a/src/runtime/rest/api.org b/src/runtime/rest/api.org index 0af8d63..b0a2256 100755 --- a/src/runtime/rest/api.org +++ b/src/runtime/rest/api.org @@ -624,6 +624,37 @@ def get_lab(): msg = {"status": "failure", "msg": err_str} return jsonify(msg) + + elif 'keyword_lab_name' in request.args: + keyword = request.args['keyword_lab_name'] + try: + labs = SystemInterface.get_labs_by_keyword_lab_name(keyword) + return jsonify_list(labs) + except TypeError as e: + err_str = str(e) + msg = {"status": "failure", + "msg": err_str } + return jsonify(msg) + + except StateError as e: + err_str = str(e) + msg = {"status": "failure", + "msg": err_str} + return jsonify(msg) + + except NotFoundError as e: + err_str = str(e) + msg = {"status": "failure", + "status code": 404, + "msg": err_str} + return jsonify(msg) + + except Exception as e: + err_str = str(e) + msg = {"status": "failure", + "msg": err_str} + return jsonify(msg) + else: try: labs = SystemInterface.get_labs() @@ -731,6 +762,16 @@ class TestGetLab(TestCase): response = self.client.post("/developers", data=json.dumps(payload), headers=headers) + payload = {'hosting_status': 'hosted', + 'hosted_url': 'http://cse14-iiith.vlabs.ac.in', + 'hosted_on': 'cloud', + 'key': KEY} + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/hostinginfos", data=json.dumps(payload), + headers=headers) + payload = {'lab_name': 'Data Structures', 'lab_id': 'cse01', 'overview' : 'overview', @@ -740,7 +781,8 @@ class TestGetLab(TestCase): 'assets': ['vlabs.ac.in/images/static/logo.png'], 'key': KEY, 'experiments': ['exp1'], - 'developers': ['abc@gmail.com'] + 'developers': ['abc@gmail.com'], + 'hosting_infos':['http://cse14-iiith.vlabs.ac.in'] } headers = {'Content-Type': 'application/json'} @@ -748,16 +790,6 @@ class TestGetLab(TestCase): response = self.client.post("/labs", data=json.dumps(payload), headers=headers) - payload = {'hosting_status': 'hosted', - 'hosted_url': 'http://cse14-iiith.vlabs.ac.in', - 'hosted_on': 'cloud', - 'key': KEY} - - headers = {'Content-Type': 'application/json'} - - response = self.client.post("/hostinginfos", data=json.dumps(payload), - headers=headers) - response = self.client.get("/labs", headers=headers) self.assertEqual(response.status_code, 200) @@ -1279,6 +1311,115 @@ class TestGetLabsbyAsset(TestCase): #+END_SRC +**** TestGetLabbyLabNameKeyword +#+NAME: test_get_lab_by_labname_keyword +#+BEGIN_SRC python +class TestGetLabbyLabNameKeyWord(TestCase): + TESTING = True + def create_app(self): + app = create_app(config) + return app + + def setUp(self): + db.create_all() + + def tearDown(self): + db.session.remove() + db.drop_all() + + def test_get_lab_by_labname_keyword(self): + print "test_get_lab_by_labname_keyword_in_rest" + + payload = {'inst_name': 'IIT Kanpur', + 'inst_id': 'IITK', + 'key': KEY} + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/institutes", data=json.dumps(payload), + headers=headers) + + payload = {'integration_level': 4, + 'key': KEY} + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/integrationstatuss", data=json.dumps(payload), + headers=headers) + + payload = {'dis_name': 'Computer Science', + 'dis_id': 'CSE', + 'key': KEY} + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/disciplines", data=json.dumps(payload), + headers=headers) + + payload = {'asset_type': 'Image', + 'path': 'vlabs.ac.in/images/static/logo.png', + 'key': KEY} + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/assets", data=json.dumps(payload), + headers=headers) + + payload = {'exp_name': 'arrays', + 'exp_id': 'exp1', + 'overview' : 'overview', + 'sections': [], + 'key': KEY} + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/experiments", data=json.dumps(payload), + headers=headers) + + payload = {'hosting_status': 'hosted', + 'hosted_url': 'http://cse14-iiith.vlabs.ac.in', + 'hosted_on': 'cloud', + 'key': KEY} + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/hostinginfos", data=json.dumps(payload), + headers=headers) + + + payload = {'name': 'Prof. Dharamaja', + 'email': 'abc@gmail.com', + 'key': KEY} + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/developers", data=json.dumps(payload), + headers=headers) + + payload = {'lab_name': 'Data Structures', + 'lab_id': 'cse01', + 'overview' : 'overview', + 'inst_id': 'IITK', + 'integration_level': 4, + 'dis_id': 'CSE', + 'assets': ['vlabs.ac.in/images/static/logo.png'], + 'key': KEY, + 'experiments': ['exp1'], + 'developers': ['abc@gmail.com'], + 'hosted_url': 'http://cse14-iiith.vlabs.ac.in' + } + + headers = {'Content-Type': 'application/json'} + + response = self.client.post("/labs", data=json.dumps(payload), + headers=headers) + + + response = self.client.get("/labs?keyword_lab_name=data", headers=headers) + self.assertEqual(response.status_code, 200) + +#+END_SRC + ** Add Lab *** API Designs @@ -7196,6 +7337,7 @@ if __name__ == '__main__': <> <> <> +<> <> <> <> diff --git a/src/runtime/system/system-interface.org b/src/runtime/system/system-interface.org index 34f0660..ec395ec 100755 --- a/src/runtime/system/system-interface.org +++ b/src/runtime/system/system-interface.org @@ -1023,10 +1023,10 @@ class TestAddIntegrationStatus(TestCase): raise err #+end_src -*** TestGetLabs - #+NAME: test_class_get_labs +*** TestGetLabsByKeywordLabName + #+NAME: test_class_get_labs_by_keyword_lab_name #+BEGIN_SRC python -class TestGetLabs(TestCase): +class TestGetLabsByLabName(TestCase): TESTING = True def create_app(self): app = create_app(config) @@ -1121,7 +1121,7 @@ class TestGetLabs(TestCase): 'hosted_url': 'http://cse14-iiith.vlabs.ac.in' } - data_dict1 = {'lab_name': "Automata", + data_dict1 = {'lab_name': "Automata data", 'lab_id': 'DFA', 'key': KEY, 'overview': 'overview', @@ -1138,7 +1138,162 @@ class TestGetLabs(TestCase): lab1 = SystemInterface.add_lab(data_dict) lab2 = SystemInterface.add_lab(data_dict1) - labs_list = SystemInterface.get_labs() + labs_list = SystemInterface.get_labs_by_keyword_lab_name("data") + + self.assertEqual(labs_list[0].get("lab_name"), data_dict['lab_name']) + self.assertEqual(labs_list[1].get("lab_name"), data_dict1['lab_name']) + self.assertEqual(labs_list[0].get("lab_id"), + data_dict['lab_id']) + self.assertEqual(labs_list[1].get("lab_id"), + data_dict1['lab_id']) + + #+END_SRC + + +** Get Labs by Keyword Lab Name +#+NAME: class_get_labs_by_keyword_lab_name +#+begin_src python + @staticmethod + def get_labs_by_keyword_lab_name(keyword): + lab_cls = System.delegate.entities['lab'] + try: + current_app.logger.debug("getting labs") + labs = lab_cls.get_all() + lab_dict_list = [] + labs_match_list=[] + for lab in labs: + lab_x = lab.to_client() + if keyword.lower() in (lab_x['lab_name']).lower(): + labs_match_list.append(lab_x) + + current_app.logger.debug("got labs") + return labs_match_list + + except (ArityError, TypeError, NotAuthorizedError, StateError) as err: + current_app.logger.error("Exception = %s" % str(err)) + raise err + + except Exception as err: + current_app.logger.error("Exception = %s" % str(err)) + raise err +#+end_src + +*** TestGetLabsByKeywordLabName + #+NAME: test_class_get_labs_by_keyword_lab_name + #+BEGIN_SRC python +class TestGetLabs(TestCase): + TESTING = True + def create_app(self): + app = create_app(config) + return app + + def setUp(self): + db.create_all() + + def tearDown(self): + db.session.remove() + db.drop_all() + + def test_get_labs_by_keyword_lab_in_system_interface(self): + print "test_get_labs_by_keyword_lab_name_in_system_interface" + + data_dict = { + 'key': KEY, + 'exp_name': 'arrays', + 'exp_id': 'exp123', + 'overview': 'overview', + 'sections': [] + } + + experiment = SystemInterface.add_experiment(data_dict) + + data_dict = { + 'key' : KEY, + 'integration_level': 4 + } + + integrationstatus = SystemInterface.add_integrationstatus(data_dict) + + data_dict = { + 'key' : KEY, + 'inst_name': 'IIT Kanpur', + 'inst_id': 'IITK' + } + + institute = SystemInterface.add_institute(data_dict) + + data_dict = { + 'key' : KEY, + 'dis_name': 'computer science', + 'dis_id': 'CSE' + } + + discipline = SystemInterface.add_discipline(data_dict) + + data_dict = { + 'key' : KEY, + 'asset_type': 'Image', + 'path': 'vlabs.ac.in/images/static/logo.png' + } + + asset1 = SystemInterface.add_asset(data_dict) + + data_dict = { + 'key' : KEY, + 'asset_type': 'Image', + 'path': 'vlabs.ac.in/images/static/icon.png', + } + + asset2 = SystemInterface.add_asset(data_dict) + + data_dict = { + 'key' : KEY, + 'name': 'Prof. Dharamaja', + 'email': 'abc@gmail.com' + } + + developer = SystemInterface.add_developer(data_dict) + + data_dict = { + 'key' : KEY, + 'hosting_status': 'hosted', + 'hosted_url': 'http://cse14-iiith.vlabs.ac.in', + 'hosted_on': 'cloud' + } + + hostinginfo = SystemInterface.add_hostinginfo(data_dict) + + data_dict = {'lab_name': 'data structure', + 'lab_id': 'cse01', + 'key': KEY, + 'overview': 'overview', + 'inst_id': 'IITK', + 'dis_id': 'CSE', + 'assets': ['vlabs.ac.in/images/static/logo.png'], + 'experiments': ['exp123'], + 'integration_level': 4, + 'developers': ['abc@gmail.com'], + 'hosted_url': 'http://cse14-iiith.vlabs.ac.in' + } + + data_dict1 = {'lab_name': "data Automata", + 'lab_id': 'DFA', + 'key': KEY, + 'overview': 'overview', + 'inst_id': 'IITK', + 'dis_id': 'CSE', + 'assets': ['vlabs.ac.in/images/static/icon.png'], + 'experiments': ['exp123'], + 'integration_level': 4, + 'developers': ['abc@gmail.com'], + 'hosted_url': 'http://cse14-iiith.vlabs.ac.in' + } + + + lab1 = SystemInterface.add_lab(data_dict) + lab2 = SystemInterface.add_lab(data_dict1) + + labs_list = SystemInterface.get_labs_by_keyword_lab_name("data") self.assertEqual(labs_list[0].get("lab_name"), data_dict['lab_name']) self.assertEqual(labs_list[1].get("lab_name"), data_dict1['lab_name']) @@ -5000,6 +5155,8 @@ if __name__ == '__main__': <> <> <> +<> + <> <> <> @@ -5095,6 +5252,7 @@ if __name__ == '__main__': <> <> <> +<> <> <>