Exemplo n.º 1
0
 def test_launches_executable_with_random_local_id(self):
     self.create_fake_archive()
     BrowserStackTunnel()
     first = self.extract_local_id()
     BrowserStackTunnel()
     second = self.extract_local_id()
     expect(second).not_to(equal(first))
 def setUp(self):
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.context.set_env(BROWSERSTACK_ACCESS_KEY="fake")
     # Prevent real network activity
     self.context.inject_as_class(HttpClient, HttpStub())
     self.context.set_env(BROWSER_ACCESS_KEY="spam")
     self.popen_spy = MasterSpy(PopenStub())
     self.context.inject_as_class(Popen, self.popen_spy)
     # Thwart actual sleeping
     self.context.inject(time.sleep, lambda n: None)
     self.tunnel = BrowserStackTunnel()
Exemplo n.º 3
0
 def test_launches_executable_with_access_key_as_first_arg(self):
     access_key = "LOVELY-SPAM"
     self.context.set_env(BROWSERSTACK_ACCESS_KEY=access_key)
     self.create_fake_archive()
     BrowserStackTunnel()
     args = self.extract_popen_arguments()
     assert len(args) > 2, "Expected at least 2 arguments in %s" % (args)
     expect(args[1]).to(equal(access_key))
Exemplo n.º 4
0
 def test_creates_local_binary_path(self):
     self.create_fake_archive()
     spy = MasterSpy(self.context.os.makedirs)
     self.context.os.makedirs = spy
     BrowserStackTunnel()
     assert spy.call_history, "makedirs was not called"
     args, kwargs = spy.call_history[-1]
     expect(args[0]).to(equal(self.local_binary_path))
Exemplo n.º 5
0
 def test_stores_unzipped_binary_from_nexus(self):
     expected = b"spamspamspam243rwedf24r\x42spamandspam"
     self.create_fake_archive(content=expected)
     BrowserStackTunnel()
     full_path = self.join_path(self.local_binary_path,
                                self.local_binary_filename)
     fopen = dependency(open)
     with fopen(full_path, "rb") as f:
         expect(f.read()).to(equal(expected))
Exemplo n.º 6
0
 def test_sets_executable_bits(self):
     self.create_fake_archive()
     spy = MasterSpy(self.context.os.chmod)
     self.context.os.chmod = spy
     BrowserStackTunnel()
     assert spy.call_history, "chmod was not called"
     args, kwargs = spy.call_history[-1]
     expect(args).to(
         equal((self.join_path(self.local_binary_path,
                               self.local_binary_filename), 0o775)))
Exemplo n.º 7
0
 def test_launches_correct_executable(self):
     self.create_fake_archive()
     BrowserStackTunnel()
     assert self.popen_spy.call_history, "popen was not called."
     args, kwargs = self.popen_spy.call_history[-1]
     assert args, "popen was called without arguments"
     command_parts = args[0]
     expect(command_parts[0]).to(
         equal(
             self.join_path(self.local_binary_path,
                            self.local_binary_filename)))
Exemplo n.º 8
0
 def test_writes_binary_in_binary_mode(self):
     full_path = self.join_path(self.local_binary_path,
                                self.local_binary_filename)
     self.create_fake_archive()
     spy = self.attach_spy(open)
     BrowserStackTunnel()
     for args, kwargs in spy.call_history:
         if args[0] == full_path:
             expect(args[1]).to(equal("wb"))
             return
     raise RuntimeError("Failed to locate the open command")
class TestClose(TestCase):
    def setUp(self):
        self.context = open_dependency_context(supply_env=True, supply_fs=True)
        self.context.set_env(BROWSERSTACK_ACCESS_KEY="fake")
        # Prevent real network activity
        self.context.inject_as_class(HttpClient, HttpStub())
        self.context.set_env(BROWSER_ACCESS_KEY="spam")
        self.popen_spy = MasterSpy(PopenStub())
        self.context.inject_as_class(Popen, self.popen_spy)
        # Thwart actual sleeping
        self.context.inject(time.sleep, lambda n: None)
        self.tunnel = BrowserStackTunnel()

    def tearDown(self):
        self.context.close()

    def test_kills_with_sigterm(self):
        self.tunnel.close()
        expect(self.popen_spy.attribute_spies.keys()).to(contain("terminate"))
        spy = self.popen_spy.attribute_spies["terminate"]
        expect(spy.call_history).to(have_length(1))
Exemplo n.º 10
0
 def test_launches_executable_with_stderr_to_stdout(self):
     self.create_fake_archive()
     BrowserStackTunnel()
     assert self.popen_spy.call_history, "popen was not called."
     args, kwargs = self.popen_spy.call_history[-1]
     expect(kwargs).to(contain_key_with_value("stderr", subprocess.STDOUT))
Exemplo n.º 11
0
 def test_exposes_local_id(self):
     self.create_fake_archive()
     sut = BrowserStackTunnel()
     expect(sut.local_identifier).to(equal(self.extract_local_id()))