From d50c3cd98d6e99c7311286559136dc1a775a326d Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 02 Nov 2009 19:23:15 +0000 Subject: final version of the StoreProxy and its tests --- diff --git a/tests/storetests.py b/tests/storetests.py index 36c623c..1752fe6 100644 --- a/tests/storetests.py +++ b/tests/storetests.py @@ -17,14 +17,15 @@ import unittest from tests.utils import skip, catch_unimplemented +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 @@ -46,7 +47,7 @@ class StoreProxyTest(unittest.TestCase): @catch_unimplemented 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 @@ -56,10 +57,11 @@ class StoreProxyTest(unittest.TestCase): @catch_unimplemented 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) @@ -68,8 +70,8 @@ class StoreProxyTest(unittest.TestCase): class StoreProxyLoginTest(unittest.TestCase): @catch_unimplemented 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") @catch_unimplemented def tearDown(self): @@ -78,9 +80,6 @@ class StoreProxyLoginTest(unittest.TestCase): if session_id is not None: self.store.close_session() - @catch_unimplemented - def test_close_session(self): - assert self.store.close_session() @catch_unimplemented def test_get_session_id(self): @@ -110,11 +109,13 @@ class StoreProxyLoginTest(unittest.TestCase): @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']) - 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) @catch_unimplemented def test_update_published_tutorial(self): @@ -123,10 +124,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': '' @@ -134,3 +135,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 c197c9e..81925ed 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 -- cgit v0.9.1