Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-06-03 12:16:04 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-06-03 12:16:04 (GMT)
commit1dd2e75de8606a73df87be40776b5ebd563d0ce1 (patch)
tree79867235394e20c372eba7ce9a0de50362bff4be
parente1bc94ec578504c3910d936bcad5816e90b0594a (diff)
Rename "author" property to "user"; add Context class for local contexts
-rw-r--r--local_document/activities.py18
-rw-r--r--local_document/context.py41
-rw-r--r--local_document/mounts.py34
-rwxr-xr-xsugar-network-service34
-rw-r--r--sugar_network/objects.py2
-rw-r--r--tests/__init__.py76
-rw-r--r--tests/units/__main__.py1
-rwxr-xr-xtests/units/activities.py17
-rwxr-xr-xtests/units/bus.py5
-rwxr-xr-xtests/units/client.py8
-rwxr-xr-xtests/units/glib_client.py5
-rwxr-xr-xtests/units/injector.py4
-rwxr-xr-xtests/units/mounts.py9
-rwxr-xr-xtests/units/server.py39
14 files changed, 170 insertions, 123 deletions
diff --git a/local_document/activities.py b/local_document/activities.py
index 31a8e37..a3cba86 100644
--- a/local_document/activities.py
+++ b/local_document/activities.py
@@ -48,18 +48,18 @@ def checkins(context):
yield os.readlink(path)
-def monitor(mounts, paths):
- _Monitor(mounts, paths).serve_forever()
+def monitor(volume, paths):
+ _Monitor(volume, paths).serve_forever()
-def populate(mounts, paths, prefix):
- _Monitor(mounts, paths, prefix).populate()
+def populate(volume, paths, prefix):
+ _Monitor(volume, paths, prefix).populate()
class _Monitor(object):
- def __init__(self, mounts, paths, prefix=''):
- self._mounts = mounts
+ def __init__(self, volume, paths, prefix=''):
+ self._volume = volume
self._paths = paths
self._prefix = prefix
@@ -83,7 +83,7 @@ class _Monitor(object):
return
context = spec['Activity', 'bundle_id']
- directory = self._mounts.home_volume['context']
+ directory = self._volume['context']
if directory.exists(context):
directory.update(context, {'keep_impl': 2})
else:
@@ -95,7 +95,7 @@ class _Monitor(object):
'summary': spec['summary'],
'description': spec['description'],
'keep_impl': 2,
- 'author': [sugar.uid()],
+ 'user': [sugar.uid()],
})
icon_path = join(spec.root, spec['icon'])
@@ -128,7 +128,7 @@ class _Monitor(object):
if not impls:
context = basename(context_dir)
- directory = self._mounts.home_volume['context']
+ directory = self._volume['context']
if directory.exists(context):
directory.update(context, {'keep_impl': 0})
diff --git a/local_document/context.py b/local_document/context.py
new file mode 100644
index 0000000..a1a456f
--- /dev/null
+++ b/local_document/context.py
@@ -0,0 +1,41 @@
+# Copyright (C) 2012 Aleksey Lim
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import active_document as ad
+from sugar_network_server.resources.context import Context as _Context
+
+
+class Context(_Context):
+
+ LOCAL_PROPS = {
+ 'keep': False,
+ 'keep_impl': 0,
+ 'position': (-1, -1),
+ }
+
+ @ad.active_property(prefix='LK', typecast=bool,
+ default=LOCAL_PROPS['keep'])
+ def keep(self, value):
+ return value
+
+ @ad.active_property(prefix='LI', typecast=[0, 1, 2],
+ default=LOCAL_PROPS['keep_impl'])
+ def keep_impl(self, value):
+ return value
+
+ @ad.active_property(ad.StoredProperty, typecast=[int],
+ default=LOCAL_PROPS['position'])
+ def position(self, value):
+ return value
diff --git a/local_document/mounts.py b/local_document/mounts.py
index 6dc6aff..27b95aa 100644
--- a/local_document/mounts.py
+++ b/local_document/mounts.py
@@ -25,26 +25,10 @@ import zerosugar
import sweets_recipe
import active_document as ad
from local_document import activities, sugar, http, env, zeroconf
+from local_document.context import Context
from active_toolkit import sockets, util, coroutine, enforce
-_HOME_PROPS = {
- 'context': [
- ad.ActiveProperty('keep',
- prefix='LK', typecast=bool, default=False),
- ad.ActiveProperty('keep_impl',
- prefix='LI', typecast=[0, 1, 2], default=0),
- ad.StoredProperty('position',
- typecast=[int], default=(-1, -1)),
- ],
- }
-
-_COMMON_PROPS = {
- # prop_name: default_value
- 'keep': False,
- 'keep_impl': 0,
- }
-
# TODO Incremental timeout
_RECONNECTION_TIMEOUT = 3
@@ -57,15 +41,15 @@ class Offline(Exception):
class Mounts(dict):
- def __init__(self, root, resources_path):
- self.home_volume = ad.SingleVolume(root, resources_path, _HOME_PROPS)
+ def __init__(self, home_volume):
+ self.home_volume = home_volume
self._subscriptions = {}
- self['~'] = _LocalMount('~', self.home_volume, self.publish)
+ self['~'] = _LocalMount('~', home_volume, self.publish)
if env.server_mode.value:
self['/'] = self['~']
else:
- self['/'] = _RemoteMount('/', self.home_volume, self.publish)
+ self['/'] = _RemoteMount('/', home_volume, self.publish)
def __getitem__(self, mountpoint):
enforce(mountpoint in self, _('Unknown mountpoint %r'), mountpoint)
@@ -218,7 +202,7 @@ class _LocalMount(ad.ProxyCommands, _Mount):
props = event.pop('props')
found_commons = False
- for prop in _COMMON_PROPS.keys():
+ for prop in Context.LOCAL_PROPS.keys():
if prop not in props:
continue
if prop == 'keep_impl':
@@ -305,13 +289,13 @@ class _RemoteMount(ad.CommandsProcessor, _Mount):
if command == ('GET', None):
if 'reply' in request:
reply = request.get('reply', [])[:]
- for prop, default in _COMMON_PROPS.items():
+ for prop, default in Context.LOCAL_PROPS.items():
if prop in reply:
patch[prop] = default
reply.remove(prop)
request['reply'] = reply
elif command in (('POST', None), ('PUT', None)):
- for prop in _COMMON_PROPS.keys():
+ for prop in Context.LOCAL_PROPS.keys():
if prop in request.content:
patch[prop] = request.content.pop(prop)
if not request.content:
@@ -347,7 +331,7 @@ class _RemoteMount(ad.CommandsProcessor, _Mount):
elif [True for prop, value in patch.items() if value]:
props = http.request('GET', ['context', guid])
props.update(patch)
- props['author'] = [sugar.uid()]
+ props['user'] = [sugar.uid()]
directory.create_with_guid(guid, props)
for prop in ('icon', 'artifact_icon', 'preview'):
blob = self.get_blob('context', guid, prop)
diff --git a/sugar-network-service b/sugar-network-service
index 25be150..50ecc2f 100755
--- a/sugar-network-service
+++ b/sugar-network-service
@@ -24,6 +24,7 @@ import restful_document as rd
import sugar_network_server as server
from local_document import application, sugar, env, bus, activities
from local_document.mounts import Mounts
+from local_document.context import Context
from sugar_network import bus as client
from active_toolkit import optparse, coroutine, enforce
@@ -42,6 +43,7 @@ class NullHandler(logging.Handler):
class Application(application.Daemon):
_prefix = ''
+ _home_volume = None
_mounts = None
_ipc_server = None
_api_server = None
@@ -79,8 +81,6 @@ class Application(application.Daemon):
_('[PREFIX-PATH SYSTEM-USER USER-GUID]\n'
'Index local Sugar Network database'))
def index(self):
- from sugar_network_server import resources
-
enforce(not self.args or len(self.args) == 3,
_('Not all command arguments where specified'))
@@ -97,7 +97,7 @@ class Application(application.Daemon):
ad.index_lazy_open.value = False
try:
- self._mounts = Mounts(self._db_path, resources.path)
+ self._mount(False)
self._populate_index()
activities.populate(self._mounts, self._activity_directories,
self._prefix)
@@ -110,15 +110,7 @@ class Application(application.Daemon):
SUGAR_REGISTRATION_TIMEOUT)
coroutine.sleep(SUGAR_REGISTRATION_TIMEOUT)
- if env.server_mode.value:
- from sugar_network_server import resources
- self._mounts = Mounts(self._db_path, resources.path)
- else:
- from sugar_network_server.resources.context import Context
- from sugar_network_server.resources.report import Report
- self._mounts = Mounts(self._db_path, [Context, Report])
- # Point client API to `self._mounts` directly passing over IPC
- client.Request.connection = self._mounts
+ self._mount(env.server_mode.value)
if env.delayed_start.value:
delayed_start = self._delayed_start
@@ -136,8 +128,7 @@ class Application(application.Daemon):
('0.0.0.0', server.port.value),
rd.Router(self._mounts['~']))
coroutine.spawn(self._api_server.serve_forever)
- self._api_subscriber = rd.SubscribeSocket(
- self._mounts.home_volume,
+ self._api_subscriber = rd.SubscribeSocket(self._home_volume,
'0.0.0.0', server.subscribe_port.value)
coroutine.spawn(self._api_subscriber.serve_forever)
@@ -175,7 +166,7 @@ class Application(application.Daemon):
self._reindexer = coroutine.spawn(self._populate_index)
- self._monitor = coroutine.spawn(activities.monitor, self._mounts,
+ self._monitor = coroutine.spawn(activities.monitor, self._home_volume,
self._activity_directories)
if env.webui.value:
@@ -188,8 +179,19 @@ class Application(application.Daemon):
('127.0.0.1', env.webui_port.value), app)
coroutine.spawn(self._web_server.serve_forever)
+ def _mount(self, server_mode):
+ if server_mode:
+ documents = [Context] + server.documents()
+ else:
+ documents = [Context] + server.documents(['report'])
+ self._home_volume = ad.SingleVolume(self._db_path, documents)
+ server.volume.update(self._home_volume)
+ self._mounts = Mounts(self._home_volume)
+ # Point client API to `self._mounts` directly passing over IPC
+ client.Request.connection = self._mounts
+
def _populate_index(self):
- for cls in self._mounts.home_volume.values():
+ for cls in self._home_volume.values():
for __ in cls.populate():
coroutine.dispatch()
diff --git a/sugar_network/objects.py b/sugar_network/objects.py
index fd92678..29a8c90 100644
--- a/sugar_network/objects.py
+++ b/sugar_network/objects.py
@@ -83,7 +83,7 @@ class Object(object):
self._request.call('PUT', guid=self._guid, content=props,
content_type='application/json')
else:
- props['author'] = [sugar.uid()]
+ props['user'] = [sugar.uid()]
self._guid = self._request.call('POST', content=props,
content_type='application/json')
diff --git a/tests/__init__.py b/tests/__init__.py
index fdb647f..d74610c 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -10,10 +10,9 @@ from os.path import dirname, join, exists, abspath
import active_document as ad
import restful_document as rd
-import sugar_network_server
from active_toolkit import coroutine
+from sugar_network_server import env as server_env
from sugar_network_server.resources.user import User
-from sugar_network_server.resources.context import Context
from restful_document.router import Router
from restful_document.subscribe_socket import SubscribeSocket
from local_document import env, sugar
@@ -21,6 +20,7 @@ from local_document.bus import Server
from sugar_network import client
from sugar_network.bus import Request
from local_document.mounts import Mounts
+from local_document.context import Context
root = abspath(dirname(__file__))
tmproot = join(root, '.tmp')
@@ -34,8 +34,6 @@ def main():
class Test(unittest.TestCase):
- httpd_pids = {}
-
def setUp(self):
self._overriden = []
@@ -88,8 +86,6 @@ class Test(unittest.TestCase):
Request.connection.close()
if self.server is not None:
self.server.stop()
- while Test.httpd_pids:
- self.httpdown(Test.httpd_pids.keys()[0])
while self.forks:
pid = self.forks.pop()
self.assertEqual(0, self.waitpid(pid))
@@ -158,42 +154,6 @@ class Test(unittest.TestCase):
self.forks.append(pid)
return pid
- def httpd(self, port, classes):
- if port in Test.httpd_pids:
- self.httpdown(port)
-
- self.httpd_seqno += 1
-
- child_pid = os.fork()
- if child_pid:
- coroutine.shutdown()
- time.sleep(1)
- Test.httpd_pids[port] = child_pid
- return
-
- for handler in logging.getLogger().handlers:
- logging.getLogger().removeHandler(handler)
- logging.basicConfig(level=logging.DEBUG, filename=tmpdir + '-%s.http.log' % self.httpd_seqno)
-
- volume = ad.SingleFolder(classes)
- httpd = coroutine.WSGIServer(('localhost', port), Router(volume))
-
- try:
- httpd.serve_forever()
- finally:
- httpd.stop()
- volume.close()
-
- def httpdown(self, port):
- pid = Test.httpd_pids[port]
- del Test.httpd_pids[port]
- os.kill(pid, signal.SIGINT)
- sys.stdout.flush()
- try:
- os.waitpid(pid, 0)
- except OSError:
- pass
-
def start_server(self, classes=None):
def server():
@@ -201,7 +161,9 @@ class Test(unittest.TestCase):
if classes is None:
classes = [User, Context]
- self.mounts = Mounts('local', classes)
+ volume = ad.SingleVolume('local', classes)
+ self.mounts = Mounts(volume)
+ server_env.volume = self.mounts.home_volume
self.server = Server(self.mounts)
self.mounts.connect(self.server.publish)
coroutine.spawn(server)
@@ -240,10 +202,10 @@ class Test(unittest.TestCase):
ad.find_limit.value = 1024
ad.index_write_queue.value = 10
- volume = ad.SingleVolume('remote', classes or [User, Context])
- cp = ad.VolumeCommands(volume)
+ server_env.volume = ad.SingleVolume('remote', classes or [User, Context])
+ cp = ad.VolumeCommands(server_env.volume)
httpd = coroutine.WSGIServer(('localhost', 8800), rd.Router(cp))
- subscriber = SubscribeSocket(volume, 'localhost', 8801)
+ subscriber = SubscribeSocket(server_env.volume, 'localhost', 8801)
try:
coroutine.joinall([
coroutine.spawn(httpd.serve_forever),
@@ -252,4 +214,24 @@ class Test(unittest.TestCase):
finally:
httpd.stop()
subscriber.stop()
- volume.close()
+ server_env.volume.close()
+
+
+PUBKEY = """\
+ssh-dss AAAAB3NzaC1kc3MAAACBANuYoFH3uvJGoQFMeW6M3CCJQlPrSv6sqd9dGQlwnnNxLBrq6KgY63e10ULtyYzq9UjiIUowqbtheGrtPCtL5w7qmFcCnq1cFzAk6Xxfe6ytJDx1fql5Y1wKqa+zxOKF6SGNnglyxvf78mZXt2G6wx22AjW+1fEhAOr+g8kRiUbBAAAAFQDA/W3LfD5NBB4vlZFcT10jU4B8QwAAAIBHh1U2B71memu/TsatwOo9+CyUyvF0FHHsXwQDkeRjqY3dcfeV38YoU/EbOZtHIQgdfGrzy7m5osnpBwUtHLunZJuwCt5tBNrpU8CAF7nEXOJ4n2FnoNiWO1IsbWdhkh9Hd7+TBM9hLGmOqlqTIx3TmUG0e4F2X33VVJ8UsrJ3mwAAAIEAm29WVw9zkRbv6CTFhPlLjJ71l/2GE9XFbdznJFRmPNBBWF2J452okRWywzeDMIIoi/z0wmNSr2B6P9wduxSxp8eIWQhKVQa4V4lJyqX/A2tE5SQtFULtw3yiYOUaCjvB2s46ZM6/9K3r8o7FSKHDpYlqAbBKURNCot5zDAu6RgE=
+"""
+PRIVKEY = """\
+-----BEGIN DSA PRIVATE KEY-----
+MIIBvAIBAAKBgQDbmKBR97ryRqEBTHlujNwgiUJT60r+rKnfXRkJcJ5zcSwa6uio
+GOt3tdFC7cmM6vVI4iFKMKm7YXhq7TwrS+cO6phXAp6tXBcwJOl8X3usrSQ8dX6p
+eWNcCqmvs8TihekhjZ4Jcsb3+/JmV7dhusMdtgI1vtXxIQDq/oPJEYlGwQIVAMD9
+bct8Pk0EHi+VkVxPXSNTgHxDAoGAR4dVNge9Znprv07GrcDqPfgslMrxdBRx7F8E
+A5HkY6mN3XH3ld/GKFPxGzmbRyEIHXxq88u5uaLJ6QcFLRy7p2SbsArebQTa6VPA
+gBe5xFzieJ9hZ6DYljtSLG1nYZIfR3e/kwTPYSxpjqpakyMd05lBtHuBdl991VSf
+FLKyd5sCgYEAm29WVw9zkRbv6CTFhPlLjJ71l/2GE9XFbdznJFRmPNBBWF2J452o
+kRWywzeDMIIoi/z0wmNSr2B6P9wduxSxp8eIWQhKVQa4V4lJyqX/A2tE5SQtFULt
+w3yiYOUaCjvB2s46ZM6/9K3r8o7FSKHDpYlqAbBKURNCot5zDAu6RgECFQC6wU/U
+6uUSSSw8Apr+eJQlSFhA+Q==
+-----END DSA PRIVATE KEY-----
+"""
+UID = '25c081e29242cf7a19ae893a420ab3de56e9e989'
diff --git a/tests/units/__main__.py b/tests/units/__main__.py
index 9a334ab..7c420ba 100644
--- a/tests/units/__main__.py
+++ b/tests/units/__main__.py
@@ -9,6 +9,7 @@ from activities import *
from client import *
from glib_client import *
from injector import *
+from server import *
tests.main()
diff --git a/tests/units/activities.py b/tests/units/activities.py
index ccb91db..ada2bcf 100755
--- a/tests/units/activities.py
+++ b/tests/units/activities.py
@@ -8,18 +8,21 @@ from os.path import abspath, lexists, exists
from __init__ import tests
+import active_document as ad
from sugar_network_server.resources.user import User
-from sugar_network_server.resources.context import Context
+from sugar_network_server import env as server_env
from active_toolkit import coroutine
from local_document.mounts import Mounts
from local_document import activities, sugar
+from local_document.context import Context
class ActivitiesTest(tests.Test):
def setUp(self):
tests.Test.setUp(self)
- self.mounts = Mounts('local', [User, Context])
+ volume = ad.SingleVolume('local', [User, Context])
+ self.mounts = Mounts(volume)
self.job = None
def tearDown(self):
@@ -29,7 +32,7 @@ class ActivitiesTest(tests.Test):
tests.Test.tearDown(self)
def test_Checkin(self):
- self.job = coroutine.spawn(activities.monitor, self.mounts, ['Activities'])
+ self.job = coroutine.spawn(activities.monitor, self.mounts.home_volume, ['Activities'])
coroutine.sleep()
self.mounts.home_volume['context'].create_with_guid(
@@ -38,7 +41,7 @@ class ActivitiesTest(tests.Test):
'title': 'title',
'summary': 'summary',
'description': 'description',
- 'author': [sugar.uid()],
+ 'user': [sugar.uid()],
})
self.touch(('Activities/activity/activity/activity.info', [
@@ -63,7 +66,7 @@ class ActivitiesTest(tests.Test):
self.mounts.home_volume['context'].get('org.sugarlabs.HelloWorld').properties(['guid', 'title', 'keep', 'keep_impl']))
def test_OfflineCheckin(self):
- self.job = coroutine.spawn(activities.monitor, self.mounts, ['Activities'])
+ self.job = coroutine.spawn(activities.monitor, self.mounts.home_volume, ['Activities'])
coroutine.sleep()
self.touch(('Activities/activity/activity/activity.info', [
@@ -88,7 +91,7 @@ class ActivitiesTest(tests.Test):
self.mounts.home_volume['context'].get('org.sugarlabs.HelloWorld').properties(['guid', 'title', 'keep', 'keep_impl']))
def test_Checkout(self):
- self.job = coroutine.spawn(activities.monitor, self.mounts, ['Activities'])
+ self.job = coroutine.spawn(activities.monitor, self.mounts.home_volume, ['Activities'])
self.mounts.home_volume['context'].create_with_guid(
'org.sugarlabs.HelloWorld', {
@@ -96,7 +99,7 @@ class ActivitiesTest(tests.Test):
'title': 'title',
'summary': 'summary',
'description': 'description',
- 'author': [sugar.uid()],
+ 'user': [sugar.uid()],
})
self.touch(('Activities/activity/activity/activity.info', [
diff --git a/tests/units/bus.py b/tests/units/bus.py
index b7df37b..161dd11 100755
--- a/tests/units/bus.py
+++ b/tests/units/bus.py
@@ -7,12 +7,12 @@ from os.path import join
from __init__ import tests
+import active_document as ad
from active_toolkit import coroutine
from sugar_network import client as client_
from sugar_network.client import Client
from sugar_network.bus import ServerError
from local_document.bus import Server
-from sugar_network_server.resources.context import Context
from local_document.mounts import Mounts
@@ -22,7 +22,8 @@ class IPCTest(tests.Test):
def server():
time.sleep(1)
- mounts = Mounts('local', [])
+ volume = ad.SingleVolume('local', [])
+ mounts = Mounts(volume)
server = Server(mounts)
mounts.call = lambda *args: None
server.serve_forever()
diff --git a/tests/units/client.py b/tests/units/client.py
index 45a0d5c..687be6b 100755
--- a/tests/units/client.py
+++ b/tests/units/client.py
@@ -6,18 +6,15 @@ from os.path import isdir
from __init__ import tests
-from sugar_network_server.resources.user import User
-from sugar_network_server.resources.context import Context
-
import active_document as ad
from active_toolkit import coroutine
from sugar_network_server.resources.user import User
-from sugar_network_server.resources.context import Context
from sugar_network.client import Client
from sugar_network.bus import Request
from local_document.bus import Server
from local_document import mounts
+from local_document.context import Context
class ClientTest(tests.Test):
@@ -308,7 +305,8 @@ class ClientTest(tests.Test):
self.assertEqual('value', blob.read())
def test_Direct(self):
- Request.connection = mounts.Mounts('local', [Context, User])
+ volume = ad.SingleVolume('local', [User, Context])
+ Request.connection = mounts.Mounts(volume)
client = Client('~')
guid_1 = client.Context(
diff --git a/tests/units/glib_client.py b/tests/units/glib_client.py
index 3bae5de..7dd5c3d 100755
--- a/tests/units/glib_client.py
+++ b/tests/units/glib_client.py
@@ -5,15 +5,10 @@ import gobject
from __init__ import tests
-from sugar_network_server.resources.user import User
-from sugar_network_server.resources.context import Context
-
import active_document as ad
from active_toolkit import coroutine
from sugar_network.client import Client
from sugar_network.glib_client import Client as GlibClient
-from local_document.bus import Server
-from local_document.mounts import Mounts
class GlibClientTest(tests.Test):
diff --git a/tests/units/injector.py b/tests/units/injector.py
index 23657e0..f36e3b2 100755
--- a/tests/units/injector.py
+++ b/tests/units/injector.py
@@ -14,9 +14,9 @@ import zerosugar
from active_toolkit import coroutine
from sugar_network.client import Client
from sugar_network_server.resources.user import User
-from sugar_network_server.resources.context import Context
from sugar_network_server.resources.implementation import Implementation
from local_document import activities
+from local_document.context import Context
class InjectorTest(tests.Test):
@@ -260,7 +260,7 @@ class InjectorTest(tests.Test):
self.start_server()
client = Client('~')
- monitor = coroutine.spawn(activities.monitor, self.mounts, ['Activities'])
+ monitor = coroutine.spawn(activities.monitor, self.mounts.home_volume, ['Activities'])
coroutine.sleep()
self.assertEqual(
diff --git a/tests/units/mounts.py b/tests/units/mounts.py
index f43aed0..19b40ba 100755
--- a/tests/units/mounts.py
+++ b/tests/units/mounts.py
@@ -22,7 +22,7 @@ from local_document.mounts import Mounts
from local_document.bus import Server
from local_document import env, mounts, sugar, http, activities
from sugar_network_server.resources.user import User
-from sugar_network_server.resources.context import Context
+from local_document.context import Context
class MountsTest(tests.Test):
@@ -175,7 +175,7 @@ class MountsTest(tests.Test):
'description': 'description',
'keep': True,
'keep_impl': 2,
- 'author': [sugar.uid()],
+ 'user': [sugar.uid()],
})
context = remote.Context(guid, ['keep', 'keep_impl'])
@@ -487,7 +487,8 @@ class MountsTest(tests.Test):
def test_ServerMode(self):
env.api_url.value = 'http://localhost:8881'
- self.mounts = Mounts('local', [User, Context])
+ volume = ad.SingleVolume('local', [Context, User])
+ self.mounts = Mounts(volume)
http_server = coroutine.WSGIServer(
('localhost', 8881), rd.Router(self.mounts['~']))
@@ -495,7 +496,7 @@ class MountsTest(tests.Test):
http_subscriber = rd.SubscribeSocket(self.mounts.home_volume, 'localhost', 8882)
coroutine.spawn(http_subscriber.serve_forever)
- monitor = coroutine.spawn(activities.monitor, self.mounts, ['Activities'])
+ monitor = coroutine.spawn(activities.monitor, self.mounts.home_volume, ['Activities'])
self.server = Server(self.mounts)
self.mounts.connect(self.server.publish)
diff --git a/tests/units/server.py b/tests/units/server.py
new file mode 100755
index 0000000..af568fb
--- /dev/null
+++ b/tests/units/server.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# sugar-lint: disable
+
+from __init__ import tests
+
+from sugar_network.client import Client
+from local_document import sugar
+
+
+class ServerTest(tests.Test):
+
+ def test_SetAuthor(self):
+ self.override(sugar, 'uid', lambda: tests.UID)
+
+ self.start_server()
+ client = Client('~')
+
+ user = client.User(
+ nickname='me',
+ fullname='M. E.',
+ color='',
+ machine_sn='',
+ machine_uuid='',
+ pubkey=tests.PUBKEY,
+ ).post()
+
+ guid = client.Context(
+ type='activity',
+ title='title',
+ summary='summary',
+ description='description').post()
+
+ context = client.Context(guid, reply=['user', 'author'])
+ self.assertEqual([user], context['user'])
+ self.assertEqual(['me', 'M. E.'], context['author'])
+
+
+if __name__ == '__main__':
+ tests.main()