Example #1
0
    def handle(self, *args, **options):
        try:
            (driver, host, username, password) = args
        except:
            raise

        import curses
        type = CameraType(name=driver, driver='apps.cam.drivers.%s' % driver)
        camera = Camera(type=type,
                        host=host,
                        username=username,
                        password=password)
        control = camera.driver.control
        stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        stdscr.keypad(1)
        try:
            while 1:
                c = stdscr.getch()
                if c == curses.KEY_UP:
                    control.move_up()
                elif c == curses.KEY_DOWN:
                    control.move_down()
                elif c == curses.KEY_LEFT:
                    control.move_left()
                elif c == curses.KEY_RIGHT:
                    control.move_right()
                elif c == curses.KEY_NPAGE:
                    control.zoom_in()
                elif c == curses.KEY_PPAGE:
                    control.zoom_out()
                elif c == curses.KEY_HOME:
                    control.home()
                elif c == curses.KEY_END:
                    control.reset()

        except:
            pass

        curses.nocbreak()
        stdscr.keypad(0)
        curses.echo()
Example #2
0
class AcessCameraTest(unittest.TestCase):

    def setUp(self):
        self.tearDown()

        self.client = Client()

        self.camera_type_axis = CameraType(
            name='Axis',
            driver='axis.AxisDriver',
            is_controlled=False,
        )
        self.camera_type_axis.save()
        self.camera_type_axis_manage = CameraType(
            name='Axis Manage',
            driver='axis.AxisDriver',
            is_controlled=True,
        )
        self.camera_type_axis_manage.save()

        self.tariff_view_package = Tariff(
            name='View Package 1 min',
            description='View Package Description...',
            cost=1.0,
            duration=2,
            is_controlled=False,
        )
        self.tariff_view_package.save()

        self.tariff_view_time = Tariff(
            name='View Package Time',
            description='View Package Description...',
            cost=1.0,
            is_controlled=False,
        )
        self.tariff_view_time.save()

        self.tariff_manage_package = Tariff(
            name='Manage Package 1 min',
            description='Manage Package Description...',
            cost=2.0,
            duration=2,
            is_controlled=True,
        )
        self.tariff_manage_package.save()

        self.tariff_manage_time = Tariff(
            name='Manage Package Time',
            description='Manage Package Description...',
            cost=2.0,
            is_controlled=True,
        )
        self.tariff_manage_time.save()

        for i in xrange(1, 4):
            user = User.create_user(email='*****@*****.**' % i, password='******')
            user.cash = 1000000.0
            user.save()
            camera = Camera(
                name='Test Billing Camera %i' % i,
                owner=user,
                type=self.camera_type_axis_manage,
                stream_name='boston',
                camera_management_host='localhost.boston.com',
                camera_management_username='******',
                camera_management_password='******',
                is_view_enabled=True,
                is_view_public=True,
                is_view_paid=True,
                is_management_enabled=True,
                is_management_public=True,
                is_management_paid=True,
                is_managed=True,
                management_packet_tariff=self.tariff_manage_package,
                management_time_tariff=self.tariff_manage_time,
                view_packet_tariff=self.tariff_view_package,
                view_time_tariff=self.tariff_view_time,
            )
            camera.save()

    def tearDown(self):
        CameraType.objects.delete()
        Tariff.objects.delete()
        Camera.objects.delete()
        AccessCamOrder.objects.delete()
        User.objects.delete()

    def test_access_view_package(self):
        def get_access():
            user = User.objects.get(email='*****@*****.**')
            camera = Camera.objects.get(name='Test Billing Camera 2')
            return AccessCamOrder.create_packet_type(
                tariff=self.tariff_view_package,
                count_packets=1,
                user=user,
                camera=camera,
            )

        order = get_access()

        self.assertEqual(order.can_access(), True)
        time.sleep(1)
        self.assertEqual(order.can_access(), True)
        time.sleep(1)
        self.assertEqual(order.can_access(), False)

        get_access() # 2 sec
        get_access() # 4 sec
        get_access() # 6 sec

        camera = Camera.objects.get(name='Test Billing Camera 2')
        user_payed = User.objects.get(email='*****@*****.**')
        user_owner = User.objects.get(email='*****@*****.**')
        user_other = User.objects.get(email='*****@*****.**')

        self.assertEqual(camera.billing(user_payed)['can_show'], True)
        self.assertEqual(camera.billing(user_owner)['can_show'], True)
        self.assertEqual(camera.billing(user_other)['can_show'], False)
        time.sleep(4)
        self.assertEqual(camera.billing(user_payed)['can_show'], True)
        self.assertEqual(camera.billing(user_owner)['can_show'], True)
        self.assertEqual(camera.billing(user_other)['can_show'], False)
        time.sleep(4)
        self.assertEqual(camera.billing(user_payed)['can_show'], False)
        self.assertEqual(camera.billing(user_owner)['can_show'], True)
        self.assertEqual(camera.billing(user_other)['can_show'], False)

    def test_access_view_time(self):
        def get_access():
            user = User.objects.get(email='*****@*****.**')
            camera = Camera.objects.get(name='Test Billing Camera 2')
            return AccessCamOrder.create_time_type(
                tariff=self.tariff_view_time,
                user=user,
                camera=camera,
            )

        def view_notify(camera_id, status):
            params = dict(
                status=status,
                session_key=self.client.session.session_key,
                camera_id=camera_id,
                time=settings.TIME_INTERVAL_NOTIFY,
            )
            response = self.client.get('%s?%s' % (reverse('server_api:cam_view_notify', args=['txt']), urllib.urlencode(params)))
            status, time, stream = response.content.split('|')
            self.assertEqual(status, '0')


        self.client.login(email='*****@*****.**', password='******')

        order = get_access()

        self.failUnlessRaises(AccessCamOrder.CanNotAddOrder, get_access)
        
        view_notify(order.camera.id, 'connect')
        order.reload()
        self.assertEqual(order.can_access(), True)
        time.sleep(settings.TIME_INTERVAL_NOTIFY)
        view_notify(order.camera.id, 'next')
        order.reload()
        self.assertEqual(order.can_access(), True)
        time.sleep(settings.TIME_INTERVAL_NOTIFY)
        view_notify(order.camera.id, 'disconnect')
        order.reload()
        self.assertEqual(order.can_access(), False)
Example #3
0
    def setUp(self):
        self.tearDown()

        self.client = Client()

        self.camera_type_axis = CameraType(
            name='Axis',
            driver='axis.AxisDriver',
            is_controlled=False,
        )
        self.camera_type_axis.save()
        self.camera_type_axis_manage = CameraType(
            name='Axis Manage',
            driver='axis.AxisDriver',
            is_controlled=True,
        )
        self.camera_type_axis_manage.save()

        self.tariff_view_package = Tariff(
            name='View Package 1 min',
            description='View Package Description...',
            cost=1.0,
            duration=2,
            is_controlled=False,
        )
        self.tariff_view_package.save()

        self.tariff_view_time = Tariff(
            name='View Package Time',
            description='View Package Description...',
            cost=1.0,
            is_controlled=False,
        )
        self.tariff_view_time.save()

        self.tariff_manage_package = Tariff(
            name='Manage Package 1 min',
            description='Manage Package Description...',
            cost=2.0,
            duration=2,
            is_controlled=True,
        )
        self.tariff_manage_package.save()

        self.tariff_manage_time = Tariff(
            name='Manage Package Time',
            description='Manage Package Description...',
            cost=2.0,
            is_controlled=True,
        )
        self.tariff_manage_time.save()

        for i in xrange(1, 4):
            user = User.create_user(email='*****@*****.**' % i, password='******')
            user.cash = 1000000.0
            user.save()
            camera = Camera(
                name='Test Billing Camera %i' % i,
                owner=user,
                type=self.camera_type_axis_manage,
                stream_name='boston',
                camera_management_host='localhost.boston.com',
                camera_management_username='******',
                camera_management_password='******',
                is_view_enabled=True,
                is_view_public=True,
                is_view_paid=True,
                is_management_enabled=True,
                is_management_public=True,
                is_management_paid=True,
                is_managed=True,
                management_packet_tariff=self.tariff_manage_package,
                management_time_tariff=self.tariff_manage_time,
                view_packet_tariff=self.tariff_view_package,
                view_time_tariff=self.tariff_view_time,
            )
            camera.save()
Example #4
0
    def handle(self, *args, **options):
        num = int(args and args[0] or 10)
        with_ava = len(args) > 1

        for type in (
                documents.User,
                Message,
                FriendshipOffer,
                UserFriends,
                GroupUser,
        ):
            type.objects.delete()

        if with_ava:
            if not os.path.exists('faces94'):
                raise CommandError(
                    'faces database not exists, do\n'
                    'wget http://cswww.essex.ac.uk/mv/allfaces/faces94.zip && unzip faces94.zip'
                )

            faces = []

            def visit(arg, dirname, names):
                if len(re.split('/', dirname)) != 3:
                    return
                faces.append(os.path.join(dirname, random.choice(names)))

            os.path.walk('faces94', visit, None)
            random.shuffle(faces)

        # creating accounts
        male_first_names = u'''
        Сергей
        Александр
        Дмитрий
        Андрей
        Артур
        Игорь
        Армен
        Алексей
        Григорий
        '''.split()

        female_first_names = u'''
        Анна
        Анастасия
        Риана
        Елена
        Мария
        Дарина
        Кристина
        Марина
        Ангелина
        Полина
        '''.split()

        male_last_names = u'''
        Смирнов
        Иванов
        Кузнецов
        Соколов
        Попов
        Лебедев
        Козлов
        Новиков
        Морозов
        Петров
        Волков
        Соловьёв
        Васильев
        Зайцев
        Павлов
        Семёнов
        Голубев
        Виноградов
        Богданов
        Воробьёв
        Фёдоров
        Михайлов
        Беляев
        Тарасов
        '''.split()

        female_last_names = [u'%sа' % x for x in male_last_names]

        male_names = (male_first_names, male_last_names)
        female_names = (female_first_names, female_last_names)

        print
        for i in xrange(num):
            if not i % (num / 10 or 10):
                print '\rusers creation %002d%%' % (i * 100 / num)
                sys.stdout.flush()
            if with_ava:
                if faces[i].find('/female/') != -1:
                    names = female_names
                else:
                    names = male_names
            else:
                names = random.choice((male_names, female_names))

            first_name = random.choice(names[0])
            last_name = random.choice(names[1])

            email = '*****@*****.**' % i

            acc = documents.User.create_user(first_name=first_name,
                                             last_name=last_name,
                                             email=email,
                                             password='******',
                                             is_superuser=bool(not i))
            acc.save()
            if with_ava:
                client = Client()
                client.login(email=email, password='******')
                file = open(faces[i])
                with patch_settings(TASKS_ENABLED={}):
                    client.post(reverse('social:avatar_edit'), {'file': file})

        print '\rusers creation 100%'
        # friending & messaging
        print
        for i in xrange(num):
            max_friends_count = random.randint(0, num % 25 + 25)
            friends_numbers = set([
                random.randint(0, num - 1) for _ in xrange(max_friends_count)
            ]).difference(set([i]))
            this_user = documents.User.objects().order_by('username')[i]

            for fn in friends_numbers:
                friend = documents.User.objects().order_by('username')[fn]
                #this_user.reload()
                this_user.friends.offers.send(friend)
                random.randint(0, 3) and friend.friends.offers.send(
                    this_user)  # ~66%

            max_msg_sndrs_count = random.randint(0, num)
            msg_sndrs_numbers = set([
                random.randint(0, num - 1) for _ in xrange(max_msg_sndrs_count)
            ]).difference(set([i]))

            for sndr_num in msg_sndrs_numbers:
                messages_count = random.randint(0, 3)

                sndr = documents.User.objects().order_by('username')[sndr_num]
                for _ in xrange(messages_count):
                    Message.send(sndr, this_user, lorem_ipsum.paragraph())

            if not i % (num / 10 or 10):
                print '\rfriending and messaging %002d%%' % (i * 100 / num),
                sys.stdout.flush()
        print '\rfriending and messaging 100%'
        print

        CameraType(
            name='Axis only view',
            driver='apps.cam.drivers.axis.AxisDriver',
        ).save()
        CameraType(
            name='Axis manage',
            driver='apps.cam.drivers.axis.AxisDriver',
            is_controlled=True,
        ).save()
        print '\rCemeras 100%'
        print

        Tariff(
            name='View Package 1 min',
            description='View Package Description...',
            cost=1.0,
            duration=60.0,
            is_controlled=False,
        ).save()
        Tariff(
            name='View Package Time',
            description='View Package Description...',
            cost=1.0,
            is_controlled=False,
        ).save()
        Tariff(
            name='Manage Package 1 min',
            description='Manage Package Description...',
            cost=2.0,
            duration=60.0,
            is_controlled=True,
        ).save()
        Tariff(
            name='Manage Package Time',
            description='Manage Package Description...',
            cost=2.0,
            is_controlled=True,
        ).save()
        print '\rTariffs 100%'