Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben <ben@tutorius-dev.(none)>2009-10-30 15:06:59 (GMT)
committer Ben Tremblay <benoit.tremblay1@gmail.com>2009-11-02 20:01:31 (GMT)
commitcea72a7d9ae41e53e00126a0528056e077eb4240 (patch)
tree1128e494dd3f2f4bebc0f405a52383c7c35a0855
parent897113f89fc2fef9cf3ca1da834f104c861382c6 (diff)
StoreProxy ready for review
-rwxr-xr-xsetup.py2
-rw-r--r--tests/storetests.py49
-rw-r--r--tutorius/apilib/__init__.pycbin105 -> 105 bytes
-rw-r--r--tutorius/apilib/httplib2/__init__.pycbin43223 -> 39750 bytes
-rw-r--r--tutorius/apilib/httplib2/iri2uri.pycbin3920 -> 3674 bytes
-rw-r--r--tutorius/apilib/mimeTypes.pycbin2249 -> 2249 bytes
-rw-r--r--tutorius/apilib/restful_lib.pycbin4972 -> 4972 bytes
-rw-r--r--tutorius/store.py78
8 files changed, 85 insertions, 44 deletions
diff --git a/setup.py b/setup.py
index a994937..e33873c 100755
--- a/setup.py
+++ b/setup.py
@@ -93,6 +93,8 @@ setup(name='Tutorius',
'sugar.tutorius',
'sugar.tutorius.uam',
'sugar.tutorius.addons',
+ 'sugar.tutorius.apilib',
+ 'sugar.tutorius.apilib.httplib2',
],
package_dir={
'sugar.tutorius': 'tutorius',
diff --git a/tests/storetests.py b/tests/storetests.py
index 0d1d9af..36c623c 100644
--- a/tests/storetests.py
+++ b/tests/storetests.py
@@ -19,7 +19,7 @@ from tests.utils import skip, catch_unimplemented
from sugar.tutorius.store import *
-g_tutorial_id = '114db454-b2a1-11de-8cfc-001f5bf747dc'
+g_tutorial_id = '4075'
g_other_id = '47efc6ee-b2a3-11de-8cfc-001f5bf747dc'
class StoreProxyTest(unittest.TestCase):
@@ -39,13 +39,6 @@ class StoreProxyTest(unittest.TestCase):
def test_get_tutorials(self):
self.store.get_tutorials()
- @catch_unimplemented
- def test_get_tutorial_collection(self):
- collection_list = self.store.get_tutorial_collection('top5_rating')
-
- assert isinstance(collection_list, list), "get_tutorial_collection should return a list"
-
- @catch_unimplemented
def test_get_latest_version(self):
version_dict = self.store.get_latest_version([])
@@ -59,15 +52,14 @@ class StoreProxyTest(unittest.TestCase):
@catch_unimplemented
def test_login(self):
- assert self.store.login("unknown_user", "random_password")
+ assert self.store.login("benoit.tremblay1@gmail.com", "tutorius12")
@catch_unimplemented
def test_register_new_user(self):
user_info = {
- 'name' : "Albert",
- 'last_name' : "The Tester",
- 'location' : 'Mozambique',
- 'email' : 'albertthetester@mozambique.org'
+ 'nickname' : "Albert2",
+ 'password' : "tutorius12",
+ 'email' : 'albertthetester2@mozambique.org'
}
assert self.store.register_new_user(user_info)
@@ -77,7 +69,7 @@ class StoreProxyLoginTest(unittest.TestCase):
@catch_unimplemented
def setUp(self):
self.store = StoreProxy()
- self.store.login("unknown_user", "random_password")
+ self.store.login("benoit.tremblay1@gmail.com", "tutorius12")
@catch_unimplemented
def tearDown(self):
@@ -104,20 +96,41 @@ class StoreProxyLoginTest(unittest.TestCase):
def test_publish(self):
# TODO : We need to send in a real tutorial loaded from
# the Vault
- assert self.store.publish(['This should be a real tutorial...'])
+ tutorial_info = {
+ 'name': 'newtut',
+ 'summary': 'This is a tutorial',
+ 'filename': 'test.xml',
+ 'homepage': 'http://google.com',
+ 'version': '1',
+ 'cat1': '17',
+ 'cat2': '18',
+ 'cat3': ''
+ }
+ assert self.store.publish('This should be a real tutorial...', tutorial_info)
@catch_unimplemented
def test_unpublish(self):
# TODO : We need to send in a real tutorial loaded from
# the Vault
- self.store.publish([g_tutorial_id, 'Fake tutorial'])
+ #self.store.publish([g_tutorial_id, 'Fake tutorial'])
assert self.store.unpublish(g_tutorial_id)
@catch_unimplemented
def test_update_published_tutorial(self):
# TODO : Run these tests with files from the Vault
- self.store.publish([g_tutorial_id, 'Fake tutorial'])
+ #self.store.publish([g_tutorial_id, 'Fake tutorial'])
+
+ tutorial_info = {
+ 'name': 'newtut',
+ 'summary': 'This is a tutorial',
+ 'filename': 'test.xml',
+ 'homepage': 'http://google.com',
+ 'version': '1',
+ 'cat1': '17',
+ 'cat2': '18',
+ 'cat3': ''
+ }
- assert self.store.update_published_tutorial(g_tutorial_id, [g_tutorial_id, 'This is an updated tutorial'])
+ assert self.store.update_published_tutorial(g_tutorial_id, 'This is an updated tutorial', tutorial_info)
diff --git a/tutorius/apilib/__init__.pyc b/tutorius/apilib/__init__.pyc
index 5ccf259..bd4346b 100644
--- a/tutorius/apilib/__init__.pyc
+++ b/tutorius/apilib/__init__.pyc
Binary files differ
diff --git a/tutorius/apilib/httplib2/__init__.pyc b/tutorius/apilib/httplib2/__init__.pyc
index f4d8036..e5f8ebe 100644
--- a/tutorius/apilib/httplib2/__init__.pyc
+++ b/tutorius/apilib/httplib2/__init__.pyc
Binary files differ
diff --git a/tutorius/apilib/httplib2/iri2uri.pyc b/tutorius/apilib/httplib2/iri2uri.pyc
index 670ac45..879e719 100644
--- a/tutorius/apilib/httplib2/iri2uri.pyc
+++ b/tutorius/apilib/httplib2/iri2uri.pyc
Binary files differ
diff --git a/tutorius/apilib/mimeTypes.pyc b/tutorius/apilib/mimeTypes.pyc
index e9bd261..35ef2b2 100644
--- a/tutorius/apilib/mimeTypes.pyc
+++ b/tutorius/apilib/mimeTypes.pyc
Binary files differ
diff --git a/tutorius/apilib/restful_lib.pyc b/tutorius/apilib/restful_lib.pyc
index 9cf5277..5b06765 100644
--- a/tutorius/apilib/restful_lib.pyc
+++ b/tutorius/apilib/restful_lib.pyc
Binary files differ
diff --git a/tutorius/store.py b/tutorius/store.py
index 225cdd4..c197c9e 100644
--- a/tutorius/store.py
+++ b/tutorius/store.py
@@ -18,6 +18,7 @@ import urllib
import urllib2
from xml.dom import minidom
from apilib.restful_lib import Connection
+from array import array
class StoreProxy(object):
"""
@@ -27,14 +28,14 @@ class StoreProxy(object):
"""
def __init__(self):
-
+
# Base Urls for the api
- self.base_url = "http://tutorius.dev/en-US/tutorius"
+ self.base_url = "http://bobthebuilder.mine.nu/tutorius/en-US/tutorius"
self.remora_api = "api/1.4"
self.tutorius_api = "TutoriusApi"
self.bandwagon_api = "api/1.4/sharing"
- self.api_auth_key = ""
+ self.api_auth_key = None
# Prepares the connection with the api
self.conn = Connection(self.base_url)
@@ -67,22 +68,48 @@ class StoreProxy(object):
# Loop through the categories and create the list to be returned
for xml_category in xml_categories:
category = {}
-
+
category['id'] = xml_category.getElementsByTagName('id')[0].firstChild.nodeValue
category['name'] = xml_category.getElementsByTagName('name')[0].firstChild.nodeValue
categories.append(category)
return categories
+
+ def search(self, keywords, category='all', page=1, numResults=10, sortBy='name'):
+ """
+ Returns a list of tutorials that correspond to the given search criteria.
+
+ @param keywords The keywords to search for
+ @param page The page in the result set from which to return results. This is
+ used to allow applications to fetch results one set at a time.
+ @param numResults The max number of results that can be returned in a page
+ @param sortBy The field on which to sort the results
+ @return A list of tutorial meta-data that corresponds to the query
+ """
+ request_url = "/%s/search/%s/%s/%d/%d/%s" % (self.tutorius_api, keywords, category, page, numResults, sortBy)
+
+ response = self.conn.request_get(request_url)
+
+ if (self.helper.iserror(response)):
+ return False
+
+ xml_response = minidom.parseString(response['body'])
+
+ xml_tutorials = xml_response.getElementsByTagName('tutorial')
+
+ tutorials = list()
+
+ for xml_tutorial in xml_tutorials:
+ tutorial = self.helper.parse_tutorial(xml_tutorial)
+ tutorials.append(tutorial)
+ return tutorials
def get_tutorials(self, category='all', page=1, numResults=10, sortBy='name'):
"""
Returns the list of tutorials that correspond to the given search criteria.
- @param keywords The list of keywords that should be matched inside the tutorial title
- or description. If None, the search will not filter the results
- according to the keywords.
@param category The category in which to restrict the search.
@param page The page in the result set from which to return results. This is
used to allow applications to fetch results one set at a time.
@@ -138,17 +165,6 @@ class StoreProxy(object):
return tutorials
- def get_tutorial_collection(self, collection_name):
- """
- Returns a list of tutorials corresponding to the given collection name.
- Collections can be groups like '5 most downloaded' or 'Top 10 ratings'.
-
- @param collection_name The name of the collection from which we want the
- meta-data
- @return A list of tutorial meta-data corresponding to the given group
- """
- raise NotImplementedError("get_tutorial_collection() not implemented... yet!")
-
def get_latest_version(self, tutorial_id_list):
"""
Returns the latest version number on the server, for each tutorial ID
@@ -325,7 +341,7 @@ class StoreProxy(object):
return True
-
+
def unpublish(self, tutorial_store_id):
"""
Removes a tutorial from the server. The user in the current session
@@ -433,12 +449,22 @@ class StoreProxyHelper(object):
@return A dictionnary containing the metadata
"""
tutorial = {}
-
- tutorial['name'] = xml_tutorial.getElementsByTagName('name')[0].firstChild.nodeValue
- tutorial['summary'] = xml_tutorial.getElementsByTagName('summary')[0].firstChild.nodeValue
- tutorial['version'] = xml_tutorial.getElementsByTagName('version')[0].firstChild.nodeValue
- tutorial['description'] =""
- tutorial['author'] = ""
- tutorial['rating'] = ""
+
+ params = [
+ 'name',
+ 'summary',
+ 'version',
+ 'description',
+ 'author',
+ 'rating'
+ ]
+
+ for param in params:
+ xml_node = xml_tutorial.getElementsByTagName(param)[0].firstChild
+
+ if xml_node != None:
+ tutorial[param] = xml_node.nodeValue
+ else:
+ tutorial[param] = ''
return tutorial