# Path: jasmine/url_builder.py
# class JasmineUrlBuilder(object):
# 
#     def __init__(self, jasmine_config):
#         self.jasmine_config = jasmine_config
# 
#     def build_url(self, port, seed=None):
#         netloc = "localhost:{0}".format(port)
#         query_string = self._build_query_params(seed=seed)
#         jasmine_url = urllib.parse.urlunparse(('http', netloc, "", "", query_string, ""))
#         return jasmine_url
# 
#     def _build_query_params(self, seed):
#         query_params = {
#             "throwFailures": self.jasmine_config.stop_spec_on_expectation_failure(),
#             "failFast": self.jasmine_config.stop_on_spec_failure(),
#             "random": self.jasmine_config.random(),
#             "seed": seed
#         }
#         query_params = self._remove_empty_params(query_params)
#         return urllib.parse.urlencode(query_params)
# 
#     def _remove_empty_params(self, query_params):
#         return dict(((k, str(v).lower()) for k, v in query_params.items() if k == "random" or v))
# 
# Path: test/helpers/fake_config.py
# class FakeConfig(object):
#     def __init__(
#             self,
#             src_dir=None,
#             spec_dir=None,
#             stylesheet_urls=None,
#             script_urls=None,
#             stop_spec_on_expectation_failure=False,
#             stop_on_spec_failure=False,
#             random=True
#     ):
#         self._src_dir = src_dir
#         self._spec_dir = spec_dir
#         self._stylesheet_urls = stylesheet_urls
#         self._script_urls = script_urls
#         self._stop_spec_on_expectation_failure = stop_spec_on_expectation_failure
#         self._stop_on_spec_failure = stop_on_spec_failure
#         self._random = random
# 
#         self.reload_call_count = 0
# 
#     def src_dir(self):
#         return self._src_dir
# 
#     def spec_dir(self):
#         return self._spec_dir
# 
#     def stylesheet_urls(self):
#         return self._stylesheet_urls
# 
#     def script_urls(self):
#         return self._script_urls
# 
#     def stop_spec_on_expectation_failure(self):
#         return self._stop_spec_on_expectation_failure
# 
#     def stop_on_spec_failure(self):
#         return self._stop_on_spec_failure
# 
#     def random(self):
#         return self._random
# 
#     def reload(self):
#         self.reload_call_count += 1


import pytest
import urllib
from jasmine.url_builder import JasmineUrlBuilder
from test.helpers.fake_config import FakeConfig
        spec_dir='spec',
    )


def test_defaults(jasmine_config):
    url = JasmineUrlBuilder(jasmine_config=jasmine_config).build_url(port=80)

    assert url == 'http://localhost:80?random=true'


def test_stop_spec_on_expectation_failure(jasmine_config):
    jasmine_config._stop_spec_on_expectation_failure = True
    url = JasmineUrlBuilder(jasmine_config=jasmine_config).build_url(port=80)
    uri_tuple = urllib.parse.urlparse(url)
    assert uri_tuple[0] == 'http'
    assert uri_tuple[1] == 'localhost:80'
    assert urllib.parse.parse_qs(uri_tuple[4]) == {"random": ['true'], "throwFailures": ['true']}


def test_stop_on_spec_failure(jasmine_config):
    jasmine_config._stop_on_spec_failure = True
    url = JasmineUrlBuilder(jasmine_config=jasmine_config).build_url(port=80)
    uri_tuple = urllib.parse.urlparse(url)
    assert uri_tuple[0] == 'http'
    assert uri_tuple[1] == 'localhost:80'
    assert urllib.parse.parse_qs(uri_tuple[4]) == {"random": ['true'], "failFast": ['true']}


def test_random(jasmine_config):
    jasmine_config._random = False

# Path: jasmine/url_builder.py
# class JasmineUrlBuilder(object):
# 
#     def __init__(self, jasmine_config):
#         self.jasmine_config = jasmine_config
# 
#     def build_url(self, port, seed=None):
#         netloc = "localhost:{0}".format(port)
#         query_string = self._build_query_params(seed=seed)
#         jasmine_url = urllib.parse.urlunparse(('http', netloc, "", "", query_string, ""))
#         return jasmine_url
# 
#     def _build_query_params(self, seed):
#         query_params = {
#             "throwFailures": self.jasmine_config.stop_spec_on_expectation_failure(),
#             "failFast": self.jasmine_config.stop_on_spec_failure(),
#             "random": self.jasmine_config.random(),
#             "seed": seed
#         }
#         query_params = self._remove_empty_params(query_params)
#         return urllib.parse.urlencode(query_params)
# 
#     def _remove_empty_params(self, query_params):
#         return dict(((k, str(v).lower()) for k, v in query_params.items() if k == "random" or v))
# 
# Path: test/helpers/fake_config.py
# class FakeConfig(object):
#     def __init__(
#             self,
#             src_dir=None,
#             spec_dir=None,
#             stylesheet_urls=None,
#             script_urls=None,
#             stop_spec_on_expectation_failure=False,
#             stop_on_spec_failure=False,
#             random=True
#     ):
#         self._src_dir = src_dir
#         self._spec_dir = spec_dir
#         self._stylesheet_urls = stylesheet_urls
#         self._script_urls = script_urls
#         self._stop_spec_on_expectation_failure = stop_spec_on_expectation_failure
#         self._stop_on_spec_failure = stop_on_spec_failure
#         self._random = random
# 
#         self.reload_call_count = 0
# 
#     def src_dir(self):
#         return self._src_dir
# 
#     def spec_dir(self):
#         return self._spec_dir
# 
#     def stylesheet_urls(self):
#         return self._stylesheet_urls
# 
#     def script_urls(self):
#         return self._script_urls
# 
#     def stop_spec_on_expectation_failure(self):
#         return self._stop_spec_on_expectation_failure
# 
#     def stop_on_spec_failure(self):
#         return self._stop_on_spec_failure
# 
#     def random(self):
#         return self._random
# 
#     def reload(self):
#         self.reload_call_count += 1


# Path: test/url_builder_test.py
import pytest
import urllib
from jasmine.url_builder import JasmineUrlBuilder
from test.helpers.fake_config import FakeConfig

        spec_dir='spec',
    )


def test_defaults(jasmine_config):
    url = JasmineUrlBuilder(jasmine_config=jasmine_config).build_url(port=80)

    assert url == 'http://localhost:80?random=true'


def test_stop_spec_on_expectation_failure(jasmine_config):
    jasmine_config._stop_spec_on_expectation_failure = True
    url = JasmineUrlBuilder(jasmine_config=jasmine_config).build_url(port=80)
    uri_tuple = urllib.parse.urlparse(url)
    assert uri_tuple[0] == 'http'
    assert uri_tuple[1] == 'localhost:80'
    assert urllib.parse.parse_qs(uri_tuple[4]) == {"random": ['true'], "throwFailures": ['true']}


def test_stop_on_spec_failure(jasmine_config):
    jasmine_config._stop_on_spec_failure = True
    url = JasmineUrlBuilder(jasmine_config=jasmine_config).build_url(port=80)
    uri_tuple = urllib.parse.urlparse(url)
    assert uri_tuple[0] == 'http'
    assert uri_tuple[1] == 'localhost:80'
    assert urllib.parse.parse_qs(uri_tuple[4]) == {"random": ['true'], "failFast": ['true']}


def test_random(jasmine_config):
    jasmine_config._random = False

    false_url = JasmineUrlBuilder(jasmine_config=jasmine_config).build_url(port=80)