Exemple #1
0
 def test_1(self):
     class request():
         user=User.objects.get(username="******")
         #body="""{"x":1,"y":1}"""
     r=request()
     j=json.loads(send_units_list(r).content)
     self.assertEqual(j["max"],1)
     self.assertEqual(j["own_units_pos"][1],[2,3,4])
     #print j
     r.body="""{"x":5,"y":6,"id":2}"""
     move_unit(r)
     finalize_move()
     j=json.loads(send_units_list(r).content)
     print j
     self.assertEqual(j["own_units_pos"][1],[2,5,6])
     #print j
     #print "1"
     t=unit.objects.filter(in_combat__isnull=False)
     self.assertEqual(t.count(),0)
     found_combat(unit.objects.get(pk=1))
     t=unit.objects.filter(in_combat__isnull=False)
     self.assertEqual(t.count(),2)
     #print "second test ",t.count()
 #def test_fount_combat(self):
     #t=unit.objects.filter(in_combat__isnull=False)
     #print "second test ",t.count()
     #pass
Exemple #2
0
 def handle(self, *args, **options):
     welcome = RedisMessage('Hello everybody')
     print "begin update unit pos"
     redis_publisher=RedisPublisher(facility='units_updated', users=[x for x in User.objects.all()])
     
     while True:
         sleep(1)
         start=clock()
         #self.stdout.write( "ruslix " )
         try:
             cursor = connection.cursor()
             cursor.execute('begin')
             cursor.execute('LOCK TABLE game_unit')
             #cursor.fetchone()
             d=datetime.now()
             t=unit.objects.filter(in_move__lte=d)
             for i in t:
                 i.in_move=None
                 i.save()
                 found_combat(i)
                 """for ii in neighbor:
                     print ii.user.user," lalala3  ",i.user.user
                 """
                 redis_publisher=RedisPublisher(facility='units_updated', users=[i.user.user,])
                 welcome = RedisMessage("unit moved "+str(i.pk))
                 redis_publisher.publish_message(welcome)
                 print i.pk,i.in_move,i.user
         finally:
             cursor.execute('commit')