Example #1
0
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     self.http_proxy = "http://munchausen-gateway:4427"
     self.https_proxy = "http://special-something:7727"
     self.context.os.environ = {"HTTP_PROXY": self.http_proxy, "HTTPS_PROXY": self.https_proxy}
     self.session_spy = MasterSpy(FakeRequests())
     self.requests_spy = MasterSpy(FakeRequests(self.session_spy))
     self.context.inject(requests, self.requests_spy)
Example #2
0
 def test_disabled_when_configured(self):
     spy = MasterSpy(EndlessFake())
     self.context.inject(requests, spy)
     self.context.set_env(HTTPS_VERIFY_CERTS="FAlSe")
     HttpClient().get("http://spam")
     args, kwargs = spy.last_call_to("get")
     expect(kwargs).to(have_keys(verify=False))
Example #3
0
 def test_attribute_requested_returns_true_if_tracking_and_requested(self):
     stub = EmptyFake()
     stub.thing = None
     spy = MasterSpy(stub, affect_only_functions=False)
     spy.thing
     assert spy.attribute_was_requested(
         "thing"), "Spy did not report that attribute was requested"
Example #4
0
 def setUp(self):
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.context.inject(webdriver, EndlessFake())
     self.fake_tunnel_class = MasterSpy(EndlessFake())
     self.context.inject(BrowserStackTunnel, self.fake_tunnel_class)
     self.context.set_env(browserstack_access_key="whatever",
                          browserstack_url="gopher:hahah",
                          browserstack_username="******")
Example #5
0
 def test_sets_full_screen(self):
     remote_spy = MasterSpy(EndlessFake())
     self.webdriver_spy.Remote = lambda *a, **k: remote_spy
     Browser()
     expect(remote_spy.attribute_spies.keys()).to(
         contain("fullscreen_window"))
     calls = remote_spy.attribute_spies["fullscreen_window"].call_history
     assert calls, "fullscreen_window was not called"
 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))
Example #7
0
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.fake_file = FakeFile()
     self.context.inject(open, self.fake_file.open)
     self.makedirs_spy = MasterSpy(self.context.os.makedirs)
     self.context.os.makedirs = self.makedirs_spy
     self.sut = ArtifactSaver()
     self.sut.activate()
Example #8
0
 def test_closes_tunnel_on_suite_end(self):
     self.context.set_env(browser_locaton="BrowserStack",
                          BROWSERSTACK_SET_LOCAL="true")
     spy = MasterSpy(TunnelToNowhere())
     self.context.inject_as_class(BrowserStackTunnel, spy)
     sut = Browser()  # noqa: F841
     assert not spy.was_closed, "close was called prematurely."
     EventBroker.publish(event=TestEvent.suite_ended)
     assert spy.was_closed, "close was not called."
Example #9
0
 def test_last_call_to_returns_last_call_to_given_func(self):
     stub = EmptyFake()
     stub.func = lambda *a, **k: None
     spy = MasterSpy(stub)
     planted_args = (4, 5)
     planted_kwargs = {"foo": 77, "bar": "soap"}
     spy.func(spam=1, eggs=2)
     spy.func(*planted_args, **planted_kwargs)
     expect(spy.last_call_to("func")).to(
         equal((planted_args, planted_kwargs)))
Example #10
0
 def test_enabled_in_session_by_default(self):
     requests_stub = EndlessFake()
     self.context.inject(requests, requests_stub)
     spy = MasterSpy(EndlessFake())
     requests_stub.Session = lambda *a, **k: spy
     client = HttpClient()
     client.enable_cookies()
     client.get("http://spam")
     args, kwargs = spy.last_call_to("send")
     expect(kwargs).to(have_keys(verify=True))
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context(supply_env=True)
     defanged = copy(junit_xml.TestSuite)
     defanged.to_xml_string = lambda *args, **kwargs: ""
     self.spy = MasterSpy(defanged, affect_only_functions=False)
     self.context.inject(junit_xml.TestSuite, self.spy)
     self.results = SuiteResults()
     self.sut = JunitReporter()
     self.sut.activate()
 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)))
 def test_last_call_to_returns_last_call_to_given_func(self):
     stub = EmptyFake()
     stub.func = lambda *a, **k: None
     spy = MasterSpy(stub)
     planted_args = (4, 5)
     planted_kwargs = {'foo': 77, 'bar': 'soap'}
     spy.func(spam=1, eggs=2)
     spy.func(*planted_args, **planted_kwargs)
     expect(spy.last_call_to('func')).to(
         equal((planted_args, planted_kwargs)))
Example #14
0
 def test_saves_first_function_call(self):
     planted_args = (1, 4, 5)
     planted_kwargs = {"spam": 32, "eggs": object()}
     stub = EmptyFake()
     stub.func = lambda *a, **k: None
     spy = MasterSpy(stub)
     spy.func(*planted_args, **planted_kwargs)
     spy.func(5, 7, 2, bruces=4, michaels=1)
     expect(spy.attribute_spies["func"].call_history[0]).to(
         equal((planted_args, planted_kwargs)))
Example #15
0
 def test_disabled_in_session_when_configured(self):
     self.context.set_env(HTTPS_VERIFY_CERTS="FAlSe")
     requests_stub = EndlessFake()
     self.context.inject(requests, requests_stub)
     spy = MasterSpy(EndlessFake())
     requests_stub.Session = lambda *a, **k: spy
     client = HttpClient()
     client.enable_cookies()
     client.get("http://spam")
     args, kwargs = spy.last_call_to("send")
     expect(kwargs).to(have_keys(verify=False))
 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()
Example #17
0
 def test_applies_affect_only_functions_flag_recursively(self):
     child = EmptyFake()
     child.value = 7
     parent = EmptyFake()
     parent.get_child = lambda: child
     parent_spy = MasterSpy(parent, affect_only_functions=False)
     parent_spy.get_child()
     func_spy = parent_spy.attribute_spies["get_child"]
     ret_spy = func_spy.return_value_spies[0]
     ret_spy.value
     expect(ret_spy.attribute_spies.keys()).to(contain("value"))
 def test_saves_last_function_call(self):
     planted_args = (1, 4, 5)
     planted_kwargs = {'spam': 32, 'eggs': object()}
     stub = EmptyFake()
     stub.func = lambda *a, **k: None
     spy = MasterSpy(stub)
     spy.func(5, 7, 2, bruces=4, michaels=1)
     spy.func()
     spy.func(*planted_args, **planted_kwargs)
     expect(spy.attribute_spies['func'].call_history[-1]).to(
         equal((planted_args, planted_kwargs)))
Example #19
0
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.fake_file = FakeFile()
     self.context.inject(open, self.fake_file.open)
     self.makedirs_spy = MasterSpy(self.context.os.makedirs)
     self.context.os.makedirs = self.makedirs_spy
     reports_path = "/where/oh/where"
     self.artifacts_path = os.path.join(reports_path, "artifacts")
     self.context.os.environ["reports_path"] = reports_path
     self.sut = ArtifactSaver()
     self.sut.activate()
Example #20
0
    def test_saves_last_return_value(self):
        values = range(3)
        it = iter(range(3))

        def func():
            return next(it)

        spy = MasterSpy(func, affect_only_functions=False)
        for i in values:
            spy()
        expect(spy.return_value_spies[-1].unwrap_spy_target()).to(
            equal(values[-1]))
Example #21
0
 def setUp(self):
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.context.set_env(
         BROWSERSTACK_ACCESS_KEY="lomein",
         BROWSERSTACK_URL="spam",
         BROWSERSTACK_USERNAME="******",
         BROWSER_LOCATION="BrowserStack",
         BROWSERSTACK_SET_LOCAL="True",
     )
     self.fake_tunnel = EndlessFake()
     self.context.inject_as_class(BrowserStackTunnel, self.fake_tunnel)
     self.webdriver_spy = MasterSpy(EndlessFake())
     self.context.inject(webdriver, self.webdriver_spy)
 def setUp(self):
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.fake_http = FakeHttpClient()
     self.context.inject_as_class(HttpClient, self.fake_http)
     self.fake_popen = FakePopen()
     self.popen_spy = MasterSpy(self.fake_popen)
     self.context.inject(Popen, self.popen_spy)
     self.context.inject(logging, EndlessFake())
     # Thwart actual sleeping
     self.context.inject(time.sleep, lambda n: None)
     self.binary_zip_url = "https://where-we-expect.the/binary.zip"
     local_binary = "/where/we/put/the/binary"
     self.local_binary_path, self.local_binary_filename = os.path.split(
         local_binary)
     self.context.set_env(
         BROWSERSTACK_ACCESS_KEY="whatever",
         BROWSERSTACK_LOCAL_BINARY_ZIP_URL=self.binary_zip_url,
         BROWSERSTACK_LOCAL_BINARY=local_binary,
     )
Example #23
0
 def setUp(self):
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.context.set_env(
         BROWSER_AVAILABILITY_TIMEOUT=0,
         BROWSER_AVAILABILITY_THROTTLE=0,
         BROWSERSTACK_URL="https://browserstack.not:43/really",
         BROWSERSTACK_OS="CP/M",
         BROWSERSTACK_OS_VERSION="1.7",
         USE_BROWSER="NCSA-Mosaic",
         USE_BROWSER_VERSION="1.3",
         BROWSERSTACK_SCREEN_RESOLUTION="kumquat",
         BROWSER_AVALABILITY_TIMEOUT="0",
         BROWSERSTACK_SET_LOCAL="fAlSe",
         BROWSERSTACK_SET_DEBUG="TrUe",
         BROWSER_LOCATION="BrowserStack",
         BROWSERSTACK_USERNAME="******",
         BROWSERSTACK_ACCESS_KEY="gdf0i9/38md-p00",
     )
     self.webdriver_spy = MasterSpy(EndlessFake())
     self.context.inject(webdriver, self.webdriver_spy)
Example #24
0
 def test_does_not_wrap_non_functions_by_default(self):
     target = EmptyFake()
     target.non_func = 42
     spy = MasterSpy(target)
     expect(spy.non_func).to(be(target.non_func))
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     self.requests_spy = MasterSpy(FakeResponse())
     self.context.inject(requests, self.requests_spy)
 def __init__(self):
     self.call_history = []
     self.session_spy = MasterSpy(FakeResponse())
Example #27
0
 def test_wraps_target_if_one_supplied(self):
     thing = object()
     expect(MasterSpy(thing).unwrap_spy_target()).to(be(thing))
Example #28
0
 def test_call_returns_return_value(self):
     value = 27
     spy = MasterSpy(lambda: value)
     expect(spy()).to(equal(value))
Example #29
0
 def test_can_wrap_non_functions(self):
     target = EmptyFake()
     target.non_func = 42
     spy = MasterSpy(target, affect_only_functions=False)
     expect(spy.non_func).to(be_a(MasterSpy))
Example #30
0
 def test_unwrapp_spy_target_returns_unwrapped_target(self):
     target = 7
     expect(MasterSpy(target).unwrap_spy_target()).to(be(target))