From 87135a1ec2f5fce5195ddd20474f576ae3a27b29 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 22 Jun 2015 23:28:21 +0300 Subject: [PATCH 1/4] added Doc path --- templates/API_Doc/api_doc_index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/API_Doc/api_doc_index.html b/templates/API_Doc/api_doc_index.html index 6e88ea7..ff55e84 100644 --- a/templates/API_Doc/api_doc_index.html +++ b/templates/API_Doc/api_doc_index.html @@ -60,6 +60,8 @@
  • Users Related API
  • Campuses Related API
  • Courses Related API
  • +
  • Projects Related API
  • +
  • Tasks Related API
  • Validation Related API
  • From 0460d9b6662d7f85d2ce53889c110c16a609ef35 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Tue, 23 Jun 2015 00:10:39 +0300 Subject: [PATCH 2/4] added function: getAllFutureTasks --- SE_API/TaskRoutes.py | 62 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 769e25b..5f163dd 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -137,8 +137,6 @@ def create_task(token): db.put(component) db.save - - return created() @@ -204,6 +202,66 @@ def getAllTasks(courseName): return no_content() +@task_routes.route('/api/tasks/getAllFutureTasks/', methods=["GET"]) +@auto.doc() +def getAllFutureTasks(courseName): + """ + >This Call will return an array of all Future Tasks in a course, ordered by date +
    + Route Parameters
    + - name: 'course name' +
    +
    + Payload
    + - NONE +
    +
    + Response +
    + 200 - JSON Example:
    + + {
    + 'title' : 'Task1',
    + 'courseName' : 'advance Math',
    + 'description' : 'prepare by sunday',
    + 'dueDate' : { + 'year' : 2015, + 'month' : 12, + 'day' : 23 + }
    + 'isPersonal' : true,
    + 'task_id' : 589689456894
    + }
    +
    +
    + """ + + arr = [] + query = Task.all() + query.filter("courseName = ", courseName) + + for t in query.run(): + taskDic =dict(json.loads(t.to_JSON())) + #add a key 'forSortDate' for sorting dates + taskTime = datetime.datetime(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) + if taskTime >= datetime.date.today(): + taskDic['forSortDate'] = taskTime + arr.append(taskDic) + + #sort array by date, and remove added key + arr = sorted(arr, key=itemgetter('forSortDate'), reverse=False) + for i in arr: + del i['forSortDate'] + + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return no_content() + + + @task_routes.route('/api/tasks/getTaskComponents/', methods=["GET"]) @auto.doc() def getTaskComponents(taskId): From 6b8debec47a58281351c9d826d03563f6f346673 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Tue, 23 Jun 2015 00:13:03 +0300 Subject: [PATCH 3/4] MERGE WARNING! didnt touch it but it wants commit... --- Testing/CoursesAPI_test.py | 94 ++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/Testing/CoursesAPI_test.py b/Testing/CoursesAPI_test.py index dcc9a84..f4c37d5 100644 --- a/Testing/CoursesAPI_test.py +++ b/Testing/CoursesAPI_test.py @@ -3,8 +3,7 @@ import unittest import requests import json from Testing.config import __CONFIG__ - -class UserTestPlan(unittest.TestCase): +class CoursesTestPlan(unittest.TestCase): @classmethod def setUpClass(cls): debug = __CONFIG__['DEBUG'] @@ -17,80 +16,75 @@ class UserTestPlan(unittest.TestCase): if 200 <= request.status_code <= 299: print 'Initialized' - def test_courseCreate_lecturer(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER'] + def test_coursesCreate_Lecturer(self): + headers = {'content-type': 'application/json'} + url = 'http://se-hub.appspot.com/api/courses/create/_QA_TOKEN_TEST_LECTURER' + params = {'seToken': 'seToken' } data = { - 'courseName': 'matan', + 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', 'projects': '@gay.lord.ultima.multi.omega', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) - self.assertEquals(r.status_code, 201) - def test_courseCreate_lecturerExsistingCourse(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER'] - data = { - 'courseName': 'matan', + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.post(url, params=params, data=json.dumps(data), headers=headers) + ''' + payload = { + 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', 'projects': '@gay.lord.ultima.multi.omega', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) + ''' + # r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER'],data=payload) + #r = requests.post('http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER',data=payload) + #self.assertEquals(r.status_code, 201) + + def test_coursesCreate_InvalidToken(self): + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/create/invalidToken' + data = { + 'courseName': 'QA COURSE', + 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', + 'projects': '@gay.lord.ultima.multi.omega', + 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, + 'endDate': {'year': 2016,'month' : 6,'day' : 6} + } + params = {'seToken': 'seToken' } + r = requests.post(url, params=params, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 403) - - def test_courseCreate_student(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'] - data = { - 'courseName': 'matan', + ''' + payload = {'courseName': 'Advance Math', 'campusName': 'JCE', 'startDate':'2015-14-3','endDate': '2015-29-6','taskFlag': 'False'} + payload = { + 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', 'projects': '@gay.lord.ultima.multi.omega', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) - self.assertEquals(r.status_code, 403) - - def test_courseCreate_invalidToken(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/invalidToken' + r = requests.post(self.__class__.url_+'api/courses/create/invalidToken',data=payload) + ''' + def test_coursesCreate_Student(self): + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/create/_QA_TOKEN_TEST_STUDENT' + params = {'seToken': 'seToken' } data = { - 'courseName': 'matan', + 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', 'projects': '@gay.lord.ultima.multi.omega', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) - self.assertEquals(r.status_code, 403) - def test_courseCreate_hebrewToken(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/????' - data = { - 'courseName': 'matan', - 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', - 'projects': '@gay.lord.ultima.multi.omega', - 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, - 'endDate': {'year': 2016,'month' : 6,'day' : 6} - } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) - self.assertEquals(r.status_code, 404) + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.post(url, params=params, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 403, 'message: ' + r.json()['message']) - #/api/courses/getCourseByCampusName/ - def test_getCourseByCampusName_EXSISTING_CAMPUS(self): - url=self.__class__.url_+'api/courses/getCourseByCampusName/'+__CONFIG__['CAMPUS_NAME']['JCE'] - r = requests.get(url) + def test_getCourseByCampusName(self): + r = requests.get(self.__class__.url_+'api/courses/getCourseByCampusName/'+__CONFIG__['TOKENS']['CAMPUS_NAME']) self.assertEquals(r.status_code, 200) if __name__ == '__main__': From 41b62be4eccaa4cf5cb274620889746b9c52e4ec Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Tue, 23 Jun 2015 00:28:29 +0300 Subject: [PATCH 4/4] added deleteTask and deleteTaskComponents functions --- SE_API/TaskRoutes.py | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 5f163dd..ad3b990 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -321,6 +321,107 @@ def getTaskComponents(taskId): +@task_routes.route('/api/tasks/deleteTask//', methods=['DELETE']) +@auto.doc() +def deleteTask(token,taskid): + """ + This Call will delete a specific Task +
    + Route Parameters
    + - seToken: 'seToken' + - taskid: 'taskid' +
    +
    + Payload
    + - NONE
    +
    +
    + Response +
    + 202 - Deleted Course +
    + ....
    + {
    + ...
    + }req
    + + ]
    + 400 - no such Course +
    + 403 - Invalid token or not a lecturer or lecturer is not owner of Course!
    + """ + + if not is_lecturer(token): + return forbidden("Invalid token or not a lecturer!") + + #todo: check if lecturer is owner of course + #return forbidden("lecturer is not owner of course") + + user = get_user_by_token(token) + c = Task.get_by_id(int(taskid)) + + if c is None: + return bad_request("no such Task") + + + db.delete(c) + db.save + return accepted("Task deleted") + + +@task_routes.route('/api/tasks/deleteTaskComponents//', methods=['DELETE']) +@auto.doc() +def deleteTaskComponents(token,taskid): + """ + This Call will delete a specific Task's components +
    + Route Parameters
    + - seToken: 'seToken' + - taskid: 'taskid' +
    +
    + Payload
    + - NONE
    +
    +
    + Response +
    + 202 - Deleted Course +
    + ....
    + {
    + ...
    + }req
    + + ]
    + 400 - no such Task +
    + 403 - Invalid token or not a lecturer or lecturer is not owner of Task!
    + """ + + if not is_lecturer(token): + return forbidden("Invalid token or not a lecturer!") + + #todo: check if lecturer is owner of course + #return forbidden("lecturer is not owner of course") + + user = get_user_by_token(token) + t = Task.get_by_id(int(taskid)) + + if t is None: + return bad_request("no such Task") + + query = TaskComponent.all() + query.filter('taskId = ', t.key().id()) + + for tc in query.run(): + db.delete(tc) + + db.save + return accepted("Task deleted") + + + @task_routes.route('/api/tasks/help') def documentation(): return auto.html()