コード例 #1
0
    def test_trying_all_providers_before_giving_up_with_retries(self):
        config = {
            "providers": [
                { 
                    "name": "should_fail_0",
                    "type": "dummy_provider",
                    "priority": 5,
                    "countries": ["a", "b", "c"]
                },
                {
                    "name": "should_fail_1",
                    "type": "dummy_provider",
                    "priority": 1,
                    "countries": ["a", "b", "e"]
                },
                {
                    "name": "should_fail_2",
                    "type": "dummy_provider",
                    "priority": 1,
                    "countries": ["a", "d"]
                },
            ]
        }

        teleport = Teleport(config)

        with self.assertRaisesRegexp(RuntimeError, "failed to teleport to 'a'"):
            teleport.goto("a")

        self.assertEqual(len(teleport.who_can_teleport_to("a")), 3)

        for provider in teleport.who_can_teleport_to("a"):
            self.assertEqual(provider.callCount, 1)
コード例 #2
0
ファイル: teleporter.py プロジェクト: EverythingMe/teleport
def Teleporter(config, place, with_firewall=True, dns_servers=None):
    t = Teleport(config).goto(place)
    
    try:
        if with_firewall:
            with FirewallContext(t.get_peer_address(), dns_servers=dns_servers):
                yield t
        else:
            yield t
    finally:
        t.go_home()
コード例 #3
0
ファイル: teleporter.py プロジェクト: ironSource/teleport
def Teleporter(config, place, with_firewall=True, dns_servers=None):
    t = Teleport(config).goto(place)

    try:
        if with_firewall:
            with FirewallContext(t.get_peer_address(),
                                 dns_servers=dns_servers):
                yield t
        else:
            yield t
    finally:
        t.go_home()
コード例 #4
0
    def test_initialization_correct_order(self):
        config = {
            "providers": [
                { 
                    "name": "vova",
                    "type": "vpn",
                    "priority": 5,
                    "countries": [],
                    "params": {},
                },
                {
                    "name": "pita",
                    "type": "vpn",
                    "priority": 1,
                    "countries": [],
                    "params": {},
                },
                {
                    "name": "misha",
                    "type": "vpn",
                    "priority": 1,
                    "countries": [],
                    "params": {},
                },
                {
                    "name": "baba",
                    "type": "luminati",
                    "priority": 10,
                    "countries": [],
                    "username": "******",
                    "password": "******",
                }
            ]
        }

        teleport = Teleport(config)
        providers = teleport.get_sorted_providers()

        # pita and misha are highest priority so they
        # go first, the order between them is random
        # then vova, and finally baba

        names = [p.name for p in providers]
        expected_order_a = ["pita", "misha", "vova", "baba"] 
        expected_order_b = ["misha", "pita", "vova", "baba"]

        if names != expected_order_a and names != expected_order_b:
            self.fail("providers in incorrect order")
コード例 #5
0
ファイル: test_teleport.py プロジェクト: ironSource/teleport
    def test_filtering_providers_that_cant_provide(self):
        config = {
            "providers": [
                {
                    "name": "vova",
                    "type": "dummy_provider",
                    "priority": 5,
                    "countries": ["a", "b", "c"]
                },
                {
                    "name": "pita",
                    "type": "dummy_provider",
                    "priority": 1,
                    "countries": ["a", "b", "e"]
                },
                {
                    "name": "misha",
                    "type": "dummy_provider",
                    "priority": 1,
                    "countries": ["d"]
                },
            ]
        }

        teleport = Teleport(config)
        self.assertProviders(teleport, "a", ["pita", "vova"])
        self.assertProviders(teleport, "b", ["pita", "vova"])
        self.assertProviders(teleport, "c", ["vova"])
        self.assertProviders(teleport, "d", ["misha"])
        self.assertProviders(teleport, "e", ["pita"])
        self.assertProviders(teleport, "f", [])
コード例 #6
0
ファイル: third.py プロジェクト: DRAGON1662/The-Lviv
def init_game():
    pygame.init()
    clock = pygame.time.Clock()
    game_set = Settings()

    animation = Animation()
    bullets = Group()

    screen = pygame.display.set_mode(
        (game_set.screen_width, game_set.screen_height))
    main_ch = Main_character(game_set, screen, animation)
    teleport = Teleport(screen, main_ch, game_set)
    loot = Loot(screen, game_set)
    while True:
        pygame.display.set_caption(game_set.title + " FPS: " +
                                   str(round(clock.get_fps(), 1)))

        clock.tick(game_set.fps)
        g_f.update_bullets(bullets)
        g_f.check_events(main_ch, game_set, screen, bullets, teleport)
        g_f.update_screen(game_set, screen, main_ch, bullets, teleport, loot)
        mousex, mousey = pygame.mouse.get_pos()
        print(mousex, mousey)
        #print(game_set.cam_x,game_set.cam_y)
        obstacle = pygame.draw.rect(game_set.bg_image_third, (255, 0, 0),
                                    (0, 2160, 3450, 2))
        print(main_ch.main_ch_rect.y, main_ch.main_ch_rect.x)
コード例 #7
0
ファイル: test_teleport.py プロジェクト: ironSource/teleport
    def test_initialization_correct_order(self):
        config = {
            "providers": [{
                "name": "vova",
                "type": "vpn",
                "priority": 5,
                "countries": [],
                "params": {},
            }, {
                "name": "pita",
                "type": "vpn",
                "priority": 1,
                "countries": [],
                "params": {},
            }, {
                "name": "misha",
                "type": "vpn",
                "priority": 1,
                "countries": [],
                "params": {},
            }, {
                "name": "baba",
                "type": "luminati",
                "priority": 10,
                "countries": [],
                "username": "******",
                "password": "******",
            }]
        }

        teleport = Teleport(config)
        providers = teleport.get_sorted_providers()

        # pita and misha are highest priority so they
        # go first, the order between them is random
        # then vova, and finally baba

        names = [p.name for p in providers]
        expected_order_a = ["pita", "misha", "vova", "baba"]
        expected_order_b = ["misha", "pita", "vova", "baba"]

        if names != expected_order_a and names != expected_order_b:
            self.fail("providers in incorrect order")
コード例 #8
0
ファイル: test_teleport.py プロジェクト: ironSource/teleport
    def test_trying_all_providers_before_giving_up_with_retries(self):
        config = {
            "providers": [
                {
                    "name": "should_fail_0",
                    "type": "dummy_provider",
                    "priority": 5,
                    "countries": ["a", "b", "c"]
                },
                {
                    "name": "should_fail_1",
                    "type": "dummy_provider",
                    "priority": 1,
                    "countries": ["a", "b", "e"]
                },
                {
                    "name": "should_fail_2",
                    "type": "dummy_provider",
                    "priority": 1,
                    "countries": ["a", "d"]
                },
            ]
        }

        teleport = Teleport(config)

        with self.assertRaisesRegexp(RuntimeError,
                                     "failed to teleport to 'a'"):
            teleport.goto("a")

        self.assertEqual(len(teleport.who_can_teleport_to("a")), 3)

        for provider in teleport.who_can_teleport_to("a"):
            self.assertEqual(provider.callCount, 1)
コード例 #9
0
ファイル: test_teleport.py プロジェクト: ironSource/teleport
    def test_try_teleporting_to_unteleportable_location(self):
        config = {
            "providers": [
                {
                    "name": "vova",
                    "type": "dummy_provider",
                    "priority": 5,
                    "countries": ["a", "b", "c"]
                },
            ]
        }

        with self.assertRaisesRegexp(RuntimeError, "no providers for 'd'"):
            Teleport(config).goto("d")
コード例 #10
0
ファイル: test_teleport.py プロジェクト: ironSource/teleport
    def test_once_provider_connects_stop_trying_to_connect(self):
        config = {
            "providers": [
                {
                    "name": "pita",
                    "type": "dummy_provider",
                    "priority": 5,
                    "countries": ["a"]
                },
                {
                    "name": "vova",
                    "type": "dummy_provider",
                    "priority": 2,
                    "countries": ["a"]
                },
                {
                    "name": "should_fail",
                    "type": "dummy_provider",
                    "priority": 1,
                    "countries": ["a"]
                },
            ]
        }

        teleport = Teleport(config)

        # shouldn't raise an exception
        provider = teleport.goto("a")

        providers = teleport.who_can_teleport_to("a")
        self.assertEqual(len(providers), 3)

        self.assertEqual(providers[0].callCount, 1)
        self.assertEqual(providers[1].callCount, 1)
        self.assertEqual(providers[2].callCount, 0)

        self.assertEqual(provider.name, "vova")
コード例 #11
0
    def test_once_provider_connects_stop_trying_to_connect(self):
        config = {
            "providers": [
                { 
                    "name": "pita",
                    "type": "dummy_provider",
                    "priority": 5,
                    "countries": ["a"]
                },
                {
                    "name": "vova",
                    "type": "dummy_provider",
                    "priority": 2,
                    "countries": ["a"]
                },
                {
                    "name": "should_fail",
                    "type": "dummy_provider",
                    "priority": 1,
                    "countries": ["a"]
                },
            ]
        }

        teleport = Teleport(config)

        # shouldn't raise an exception
        provider = teleport.goto("a")

        providers = teleport.who_can_teleport_to("a")
        self.assertEqual(len(providers), 3)

        self.assertEqual(providers[0].callCount, 1)
        self.assertEqual(providers[1].callCount, 1)
        self.assertEqual(providers[2].callCount, 0)

        self.assertEqual(provider.name, "vova")
コード例 #12
0
ファイル: test_teleport.py プロジェクト: ironSource/teleport
    def test_initializing_with_unsupported_provider(self):
        config = {
            "providers": [
                {
                    "name": "vova",
                    "type": "la la la",
                    "priority": 10,
                },
            ]
        }

        exceptionMessage = "unsupported teleporation provider 'la la la'"

        with self.assertRaisesRegexp(RuntimeError, exceptionMessage):
            Teleport(config).goto("hell")