Ejemplo n.º 1
0
	def setUp(self):
		self.command = Command()
		self.command.handle_noargs()
		self.client = Client()
		self.client2 = Client()
		self.sim_server = SimulationServer()
		self.sim_server.start()
Ejemplo n.º 2
0
class APITest(TestCase):
    """A test suite for the web API"""

    fixtures = ["auth.json", "sites.json"]
    root_url = "/api/sim/"

    def setUp(self):
        self.client = Client()
        self.command = Command()
        self.command.handle_noargs()

    def tearDown(self):
        pass

    def test_web_api(self):
        spaces = Space.objects.all()
        self.assertTrue(len(spaces) > 0)
        response = self.client.get(reverse("sim.api_views.scene_document", kwargs={"id": spaces[0].id}))
        self.assertEqual(response.status_code, 200)
        parsed_scene = json.loads(response.content)
        templates = Template.objects.all()
        self.assertTrue(len(templates) > 0)
        self.assertTrue(len(templates[0].assets.all()) > 0)
        asset = templates[0].assets.all()[0]
        response = self.client.get(
            reverse(
                "sim.api_views.template_asset",
                kwargs={"template_id": templates[0].id, "asset_key": templates[0].get_key(asset)},
            )
        )
        self.assertEqual(response.status_code, 302)  # the template asset view redirects to the static file url
        response = self.client.get(
            reverse(
                "sim.api_views.template_asset",
                kwargs={"template_id": templates[0].id, "asset_key": templates[0].get_key(asset)},
            ),
            follow=True,
        )
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/api/sim/space/%s" % spaces[0].id, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(self.client.login(username="******", password="******"))
Ejemplo n.º 3
0
 def setUp(self):
     self.client = Client()
     self.command = Command()
     self.command.handle_noargs()
Ejemplo n.º 4
0
class SimTest(TransactionTestCase): 
	"""A test suite for the sim server and client.
	It must be a TransactionalTestCase because we're accessing the db in multiple threads."""
	
	fixtures = ['auth.json', 'sites.json']
	
	def setUp(self):
		self.command = Command()
		self.command.handle_noargs()
		self.client = Client()
		self.client2 = Client()
		self.sim_server = SimulationServer()
		self.sim_server.start()

	def tearDown(self):
		self.sim_server.stop()

	def test_sim_setup(self):
		self.client.login(username='******', password='******')
		self.client2.login(username='******', password='******')

		self.failUnlessEqual(SimulatorPoolRegistration.objects.all().count(), 1)
		self.failUnlessEqual(SimulatorPoolRegistration.objects.all()[0], self.sim_server.registration)

		event_handler = EventHandler()

		sim_client = SimClient(self.client.session.session_key, '127.0.0.1', self.sim_server.ws_server.port, '127.0.0.1:8000', event_handler=event_handler.handle_event)

		sim_client.authenticate()
		event = event_handler.events.get(True, 10)
		self.failUnless(event.authenticated)
		self.failUnlessEqual('trevor', event.username)
		self.failUnlessEqual('trevor', sim_client.username)

		sim_client.request_pool_info()
		event = event_handler.events.get(True, 10)
		self.failUnless(event.infos)
		self.failUnless(event.infos['space_infos'])
		self.failUnless(event.infos['space_infos'][0].has_key('name'))
		self.failUnless(event.infos['space_infos'][0].has_key('url'))

		space = Space.objects.all()[0]
		sim_client.join_space(space.id)
		event = event_handler.events.get(True, 10)
		self.failUnlessEqual(space.id, event.space_id)
		self.failUnless(event.joined)
		self.failUnless(sim_client.scene)
		self.failUnless(len(sim_client.scene.children) > 0)
		
		event_handler2 = EventHandler()
		sim_client2 = SimClient(self.client2.session.session_key, '127.0.0.1', self.sim_server.ws_server.port, '127.0.0.1:8000', event_handler=event_handler2.handle_event)
		sim_client2.authenticate()
		event = event_handler2.events.get(True, 10)
		self.failUnless(event.authenticated)
		
		sim_client2.join_space(space.id)
		event = event_handler2.events.get(True, 10)
		self.failUnless(event.joined == False) # client 2 is not a member yet
		user2 = User.objects.get(username='******')
		space_member = SpaceMember.objects.create(space=space, member=user2)
		sim_client2.join_space(space.id)
		event = event_handler2.events.get(True, 10)
		self.failUnless(event.joined == False)
		space_member.is_admin = True
		space_member.save()
		sim_client2.join_space(space.id)
		event = event_handler2.events.get(True, 10)
		self.failUnless(event.joined)
		
		sim_client.add_user()
		event = event_handler.events.get(True, 10)
		self.failUnless(event.json_data)
		event = event_handler2.events.get(True, 10)
		self.failUnless(event.json_data)
		
		sim_client.notify_template_updated(3, '/url')
		event = event_handler.events.get(True, 10)
		self.failUnlessEqual(event.template_id, 3)
		event = event_handler2.events.get(True, 10)
		self.failUnlessEqual(event.template_id, 3)

		sim_client.notify_template_updated(2, '/some/thing/2', 'moon')
		event = event_handler.events.get(True, 10)
		self.failUnlessEqual(event.template_id, 2)
		self.failUnlessEqual(event.key, 'moon')
		self.failUnlessEqual(event.url, '/some/thing/2')
		event = event_handler2.events.get(True, 10)
		self.failUnlessEqual(event.template_id, 2)
		self.failUnlessEqual(event.key, 'moon')

		SimulatorPoolRegistration.objects.broadcast_event(self.client.session.session_key, TemplateUpdated(space.id, 23, '/some/url/23', 'dink'))
		event = event_handler.events.get(True, 10)
		self.failUnlessEqual(event.template_id, 23)
		self.failUnlessEqual(event.key, 'dink')
		event = event_handler2.events.get(True, 10)
		self.failUnlessEqual(event.template_id, 23)
		self.failUnlessEqual(event.key, 'dink')

		sim_client.close()
		sim_client2.close()