commit
cace7be507
3 changed files with 207 additions and 52 deletions
|
@ -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/<string:courseName>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getAllFutureTasks(courseName):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all Future Tasks in a course, ordered by date</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- name: 'course name'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
'title' : 'Task1',<br>
|
||||
'courseName' : 'advance Math',<br>
|
||||
'description' : 'prepare by sunday',<br>
|
||||
'dueDate' : {
|
||||
'year' : 2015,
|
||||
'month' : 12,
|
||||
'day' : 23
|
||||
}<br>
|
||||
'isPersonal' : true,<br>
|
||||
'task_id' : 589689456894<br>
|
||||
}<br>
|
||||
</code>
|
||||
<br>
|
||||
"""
|
||||
|
||||
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/<string:taskId>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getTaskComponents(taskId):
|
||||
|
@ -263,6 +321,107 @@ def getTaskComponents(taskId):
|
|||
|
||||
|
||||
|
||||
@task_routes.route('/api/tasks/deleteTask/<string:token>/<string:taskid>', methods=['DELETE'])
|
||||
@auto.doc()
|
||||
def deleteTask(token,taskid):
|
||||
"""
|
||||
<span class="card-title">This Call will delete a specific Task</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- taskid: 'taskid'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
202 - Deleted Course
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - no such Course
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer or lecturer is not owner of Course!<br>
|
||||
"""
|
||||
|
||||
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/<string:token>/<string:taskid>', methods=['DELETE'])
|
||||
@auto.doc()
|
||||
def deleteTaskComponents(token,taskid):
|
||||
"""
|
||||
<span class="card-title">This Call will delete a specific Task's components</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- taskid: 'taskid'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
202 - Deleted Course
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - no such Task
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer or lecturer is not owner of Task!<br>
|
||||
"""
|
||||
|
||||
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()
|
||||
|
|
|
@ -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/<string:name>
|
||||
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__':
|
||||
|
|
|
@ -60,6 +60,8 @@
|
|||
<li class="collection-item dismissable"><div>Users Related API<a href="/api/users/help" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
<li class="collection-item dismissable"><div>Campuses Related API<a href="/api/campuses/help" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
<li class="collection-item dismissable"><div>Courses Related API<a href="/api/courses/help" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
<li class="collection-item dismissable"><div>Projects Related API<a href="/api/projects/help" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
<li class="collection-item dismissable"><div>Tasks Related API<a href="/api/tasks/help" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
<li class="collection-item dismissable"><div>Validation Related API<a href="#!" class="secondary-content"><i class="mdi-content-send"></i></a></div></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue