Ejemplo n.º 1
0
Archivo: tests.py Proyecto: sz-2013/sz
 def test_update_gamemap(self):
     for p in models.Place.objects.all():
         self.assertIsNone(p.get_gamemap_position())
     gamemap_service.update_gamemap(self.params)
     for p in models.Place.objects.all():
         self.check_val_type(
             p.get_gamemap_position(), 'gamemap_position', list, 2)
Ejemplo n.º 2
0
Archivo: places.py Proyecto: sz-2013/sz
 def get(self, request, format=None):
     params = self.validate_req_params(request.QUERY_PARAMS)
     creator = request.user
     params['user'] = creator
     places_list = place_service.explore_in_venues(**params)
     user_data = serializers.UserStandartDataShortSerializer(
         instance=creator).data
     places_len = len(places_list)
     code = status.HTTP_200_OK
     if places_len:
         places_len = 0
         bl_data = user_data
         bl_data['user_longitude'] = params.get('latitude')
         bl_data['user_latitude'] = params.get('longitude')
         places_list = map(
             lambda p: serializers.PlaceStandartDataSerializer(
                 instance=p).data,
             places_list)
         places_tuples = map(
             lambda data: (str(data.get('place_id')), data), places_list)
         bl_data['places'] = dict(places_tuples)
         engine_answer = posts.Place.create(bl_data)
         code = engine_answer.get("status")
         engine_data = engine_answer.get("data", {})
         if code != status.HTTP_201_CREATED:
             return sz_api_response(status=code, data=engine_data)
         user_data = engine_data.get("user")
         for p_id, p_data in engine_data.get('places', {}).iteritems():
             s = serializers.PlaceStandartDataSerializer(data=p_data)
             if s.is_valid():
                 s.object.create_in_engine(p_data)
                 places_len += 1
         gamemap_service.update_gamemap(params)
         # code = status.HTTP_201_CREATED
         # gamemap_service.update_gamemap(params)
     return sz_api_response(
         data=dict(user=user_data, places_explored=places_len), status=code)
Ejemplo n.º 3
0
Archivo: tests.py Proyecto: sz-2013/sz
 def test_get_gamemap(self):
     def _get_data(current_box):
         params = dict(latitude=current_box.latitude(),
                       longitude=current_box.longitude(), radius=RADIUS)
         response = get_response(
             API['gamemap']['get_gamemap'], 'GET', views_places.GameMapRoot,
             query=params, user=self.user)
         self.assertEqual(
             response.status_code, 200, msg=response.render())
         return get_data(response)
     gamemap_service.update_gamemap(self.params)
     current_box = models.Place.objects.all()[0]
     data = _get_data(current_box)
     self.assertIsNone(data.get('last_box'))
     self.check_val_type(data, 'current_box', dict)
     self.check_place_data(data=data['current_box'], place=current_box,
                           bl_test=False, is_owner=0, distance=True)
     self.check_val_type(data['map_width'], 'map_width', int)
     self.check_val_type(data['map_height'], 'map_height', int)
     self.check_val_type(data, 'gamemap', list)
     for box in data['gamemap']:
         place = models.Place.objects.get(pk=box['place_id'])
         self.check_place_data(data=box, place=place,
                               bl_test=False, is_owner=0, distance=True)