diff options
-rw-r--r-- | tests/storetests.py | 38 | ||||
-rw-r--r-- | tutorius/store.py | 25 |
2 files changed, 35 insertions, 28 deletions
diff --git a/tests/storetests.py b/tests/storetests.py index 73ac2f7..97aa5e3 100644 --- a/tests/storetests.py +++ b/tests/storetests.py @@ -16,14 +16,15 @@ import unittest +import random from sugar.tutorius.store import * -g_tutorial_id = '4075' -g_other_id = '47efc6ee-b2a3-11de-8cfc-001f5bf747dc' +g_tutorial_id = '4079' +g_other_id = '4080' class StoreProxyTest(unittest.TestCase): def setUp(self): - self.store = StoreProxy() + self.store = StoreProxy("http://bobthebuilder.mine.nu/tutorius/en-US/tutorius") def tearDown(self): pass @@ -42,7 +43,7 @@ class StoreProxyTest(unittest.TestCase): assert isinstance(version_dict, dict) def test_download_tutorial(self): - tutorial = self.store.download_tutorial(g_tutorial_id) + tutorial = self.store.download_tutorial(g_other_id) assert tutorial is not None @@ -50,10 +51,11 @@ class StoreProxyTest(unittest.TestCase): assert self.store.login("benoit.tremblay1@gmail.com", "tutorius12") def test_register_new_user(self): + random_num = str(random.randint(0, 999999999)) user_info = { - 'nickname' : "Albert2", + 'nickname' : "Albert%s" % (random_num), 'password' : "tutorius12", - 'email' : 'albertthetester2@mozambique.org' + 'email' : 'albertthetester%s@mozambique.org' % (random_num) } assert self.store.register_new_user(user_info) @@ -61,17 +63,14 @@ class StoreProxyTest(unittest.TestCase): class StoreProxyLoginTest(unittest.TestCase): def setUp(self): - self.store = StoreProxy() - self.store.login("benoit.tremblay1@gmail.com", "tutorius12") + self.store = StoreProxy("http://bobthebuilder.mine.nu/tutorius/en-US/tutorius") + self.store.login("nobody@mozilla.org", "tutorius12") def tearDown(self): session_id = self.store.get_session_id() if session_id is not None: self.store.close_session() - - def test_close_session(self): - assert self.store.close_session() def test_get_session_id(self): session_id = self.store.get_session_id() @@ -97,11 +96,13 @@ class StoreProxyLoginTest(unittest.TestCase): assert self.store.publish('This should be a real tutorial...', tutorial_info) 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']) - assert self.store.unpublish(g_tutorial_id) + + # Republish the tutorial + self.store.publish(None, None, g_tutorial_id) + + def test_republish(self): + assert self.store.publish(None, None, g_tutorial_id) def test_update_published_tutorial(self): # TODO : Run these tests with files from the Vault @@ -109,10 +110,10 @@ class StoreProxyLoginTest(unittest.TestCase): tutorial_info = { 'name': 'newtut', - 'summary': 'This is a tutorial', + 'summary': 'This is an updated tutorial', 'filename': 'test.xml', 'homepage': 'http://google.com', - 'version': '1', + 'version': '2', 'cat1': '17', 'cat2': '18', 'cat3': '' @@ -120,3 +121,6 @@ class StoreProxyLoginTest(unittest.TestCase): assert self.store.update_published_tutorial(g_tutorial_id, 'This is an updated tutorial', tutorial_info) + def test_close_session(self): + assert self.store.close_session() + diff --git a/tutorius/store.py b/tutorius/store.py index d678729..760daec 100644 --- a/tutorius/store.py +++ b/tutorius/store.py @@ -27,10 +27,10 @@ class StoreProxy(object): shop to implement all the requests that could be made to the Store. """ - def __init__(self): + def __init__(self, base_url): # Base Urls for the api - self.base_url = "http://bobthebuilder.mine.nu/tutorius/en-US/tutorius" + self.base_url = base_url self.remora_api = "api/1.4" self.tutorius_api = "TutoriusApi" self.bandwagon_api = "api/1.4/sharing" @@ -50,14 +50,13 @@ class StoreProxy(object): @return The list of category names stored on the server. """ - categories = {} request_url = "/%s/categories" % (self.tutorius_api) response = self.conn.request_get(request_url) if self.helper.iserror(response): - return categories + return None xml_response = minidom.parseString(response['body']) @@ -92,7 +91,7 @@ class StoreProxy(object): response = self.conn.request_get(request_url) if (self.helper.iserror(response)): - return False + return None xml_response = minidom.parseString(response['body']) @@ -123,7 +122,7 @@ class StoreProxy(object): response = self.conn.request_get(request_url) if (self.helper.iserror(response)): - return False + return None xml_response = minidom.parseString(response['body']) @@ -150,7 +149,7 @@ class StoreProxy(object): response = self.conn.request_get(request_url) if (self.helper.iserror(response)): - return False + return None xml_response = minidom.parseString(response['body']) @@ -184,6 +183,9 @@ class StoreProxy(object): response = self.conn.request_get(request_url) + if (self.helper.iserror(response)): + return None + xml = minidom.parseString(response['body']) versionnode = xml.getElementsByTagName("version")[0] @@ -211,7 +213,7 @@ class StoreProxy(object): response = self.conn.request_get(request_url) if (self.helper.iserror(response)): - return False + return None xml = minidom.parseString(response['body']) @@ -267,7 +269,7 @@ class StoreProxy(object): if (self.helper.iserror(response)): return False - self.api_auth_key = "" + self.api_auth_key = None return True @@ -316,10 +318,11 @@ class StoreProxy(object): """ # This is in the case we have to re-publish a tutorial - if tutorial_store_id != None: + if tutorial_store_id is not None: request_url = "/%s/publish/%s" % (self.tutorius_api, tutorial_store_id) + headers = { 'X-API-Auth' : self.api_auth_key } - response = self.conn.request_post(request_url) + response = self.conn.request_post(request_url, None, None, None, headers) if self.helper.iserror(response): return False |