コード例 #1
0
ファイル: tests.py プロジェクト: benthomasson/tree
 def test_save_load_sim(self):
     self.test_create_sim()
     self.sim.a = 1
     self.sim.b = 2
     self.sim.c = None
     Thing.save_sim(self.sim)
     new_sim = Thing.load_sim(self.sim.uuid)
     self.assertEquals(new_sim.uuid, self.sim.uuid)
     self.assertEquals(new_sim.a, 1)
     self.assertEquals(new_sim.b, 2)
     self.assertEquals(new_sim.c, None)
コード例 #2
0
ファイル: tests.py プロジェクト: benthomasson/tree
 def test_save_load(self):
     t = Thing()
     t.save()
     sim = TestSim(t.uuid)
     sim.x = 10
     sim.z = 'hello'
     sim.ts = [1, 2, 3, 4]
     Data.save_state(t, sim)
     new_sim = TestSim(t.uuid)
     Data.load_state(t, new_sim)
     self.assertEquals(new_sim.x, 10)
     self.assertEquals(new_sim.z, 'hello')
     self.assertEquals(new_sim.ts, [1, 2, 3, 4])
コード例 #3
0
ファイル: tests.py プロジェクト: benthomasson/tree
    def setUp(self):
        super(TestTaskResource, self).setUp()

        # Create a user.
        self.username = '******'
        self.password = '******'
        self.user = User.objects.create_user(self.username, '*****@*****.**', self.password)

        self.robot = Thing.create_thing(sim_class=TestSim2)
        self.robot.save()
        self.task = Task(thing=self.robot, name='foo')
        self.task.save()

        # We also build a detail URI, since we will be using it all over.
        # DRY, baby. DRY.
        self.detail_url = '/leaf_api/v1/task/{0}/'.format(self.task.pk)

        # The data we'll send on POST requests. Again, because we'll use it
        # frequently (enough).
        self.post_data = {
            'robot': self.robot.uuid,
            'name': 'foo',
        }

        self.task_args = dict(format='json', authentication=self.get_credentials(), HTTP_AUTHORIZATION_KEY=self.task.authorization)
        self.robot_args = dict(format='json', authentication=self.get_credentials(), HTTP_AUTHORIZATION_KEY=self.robot.authorization)
コード例 #4
0
ファイル: tests.py プロジェクト: benthomasson/tree
    def setUp(self):
        super(TestRobotResource, self).setUp()

        # Create a user.
        self.username = '******'
        self.password = '******'
        self.user = User.objects.create_user(self.username, '*****@*****.**', self.password)

        self.thing = Thing.create_thing(sim_class=TestSim2)
        self.thing.save()

        # We also build a detail URI, since we will be using it all over.
        # DRY, baby. DRY.
        self.detail_url = '/leaf_api/v1/robot2/{0}/'.format(self.thing.pk)

        # The data we'll send on POST requests. Again, because we'll use it
        # frequently (enough).
        self.post_data = {
            'user': '******'.format(self.user.pk),
            'title': 'Second Post!',
            'slug': 'second-post',
            'created': '2012-05-01T22:05:12'
        }

        self.args = dict(format='json', authentication=self.get_credentials(), HTTP_AUTHORIZATION_KEY=self.thing.authorization)
コード例 #5
0
ファイル: tests.py プロジェクト: benthomasson/tree
 def test_sim_task_call(self):
     sim = Thing.create_sim(HelloRobot)
     task = Task(thing=Thing.objects.get(uuid=sim.uuid), name='hello')
     task.save()
     task2 = Task.objects.get(id=task.id)
     self.assertEquals(task2.status, 'REQUESTED')
     self.assertEquals(call_sim_task_method(sim.uuid, task.id, 'sim_task_hello'), 'Hello')
     task2 = Task.objects.get(id=task.id)
     self.assertEquals(task2.status, 'COMPLETED')
コード例 #6
0
ファイル: tests.py プロジェクト: benthomasson/tree
    def test_defaults(self):
        t = Thing.create_thing(sim_class=TestSim2)
        t.save()
        self.task = Task(thing=t, name='foo')
        self.task.save()
        id = self.task.id

        task2 = Task.objects.get(id=id)
        self.assertEquals(task2.thing, t)
        self.assertEquals(task2.kwargs, {})
        self.assertEquals(task2.result, None)
        self.assertEquals(task2.name, 'foo')
        self.assert_(task2.authorization)
        self.assertEquals(len(task2.authorization), 64)
        self.assertEquals(task2.result, None)
        self.assertEquals(task2.status, 'REQUESTED')
コード例 #7
0
ファイル: tests.py プロジェクト: benthomasson/tree
 def test_get_set(self):
     t = Thing()
     t.save()
     Data.set_attribute(t, 'a', 5)
     self.assertEquals(Data.get_attribute(t, 'a'), 5)
コード例 #8
0
ファイル: tests.py プロジェクト: benthomasson/tree
 def test_sim_call(self):
     sim = Thing.create_sim(HelloRobot)
     self.assertEquals(call_sim_method(sim.uuid, 'sim_hello'), 'Hello')
コード例 #9
0
ファイル: simulations.py プロジェクト: benthomasson/tree
 def all(cls):
     return map(lambda x: Thing.load_sim(uuid=x.uuid), Thing.objects.filter(sim_class=class_name(cls)))
コード例 #10
0
ファイル: tasks.py プロジェクト: benthomasson/tree
def call_sim_method(thing_id, method_name, *args, **kwargs):
    sim = Thing.load_sim(thing_id)
    assert hasattr(sim, method_name)
    fn = getattr(sim, method_name)
    return fn(*args, **kwargs)
コード例 #11
0
ファイル: resources.py プロジェクト: benthomasson/tree
 def obj_create(self, bundle, request=None, **kwargs):
     bundle.obj = Thing.create_sim(self._meta.object_class)
     self.full_hydrate(bundle)
     bundle.obj.save()
     return bundle
コード例 #12
0
ファイル: simulations.py プロジェクト: benthomasson/tree
def load_sim(uuid):
    return Thing.load_sim(uuid)
コード例 #13
0
ファイル: simulations.py プロジェクト: benthomasson/tree
 def save(self):
     return Thing.save_sim(self)
コード例 #14
0
ファイル: simulations.py プロジェクト: benthomasson/tree
 def get(cls, uuid):
     return Thing.load_sim(uuid=uuid)
コード例 #15
0
ファイル: simulations.py プロジェクト: benthomasson/tree
 def filter(cls,**kwargs):
     return map(lambda x: Thing.load_sim(uuid=x.uuid), Thing.objects.filter(**kwargs))
コード例 #16
0
ファイル: tests.py プロジェクト: benthomasson/tree
 def test(self):
     t = Thing()
     t.save()
     self.assertTrue(t.uuid)
コード例 #17
0
ファイル: tests.py プロジェクト: benthomasson/tree
 def test_create_sim(self):
     self.sim = Thing.create_sim(BaseSim)
     self.assertTrue(self.sim.uuid)
     t = Thing.objects.get(uuid=self.sim.uuid)
     self.assertEquals(t.uuid, self.sim.uuid)
コード例 #18
0
ファイル: resources.py プロジェクト: benthomasson/tree
 def obj_update(self, bundle, request=None, **kwargs):
     bundle.obj = Thing.load_sim(bundle.data['uuid'])
     self.full_hydrate(bundle)
     bundle.obj.save()
     return bundle
コード例 #19
0
ファイル: tests.py プロジェクト: benthomasson/tree
 def test_call(self):
     sim = Thing.create_sim(HelloRobot)
     self.assertEquals(sim.sim_hello(), 'Hello')
コード例 #20
0
ファイル: tasks.py プロジェクト: benthomasson/tree
def call_sim_task_method(thing_id, task_id, method_name, *args, **kwargs):
    sim = Thing.load_sim(thing_id)
    task = Task.objects.get(id=task_id)
    assert hasattr(sim, method_name)
    fn = getattr(sim, method_name)
    return fn(task=task, *args, **kwargs)
コード例 #21
0
ファイル: simulations.py プロジェクト: benthomasson/tree
 def create_sim(cls):
     return Thing.create_sim(cls)