Project

General

Profile

Download (1.79 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / test / test_unit.py @ 463e6830

1
# SPDX-License-Identifier: CC0-1.0
2

    
3
"""
4
Haketilo unit tests
5
"""
6

    
7
# This file is part of Haketilo
8
#
9
# Copyright (C) 2021, jahoti
10
# Copyright (C) 2021, Wojtek Kosior
11
#
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the CC0 1.0 Universal License as published by
14
# the Creative Commons Corporation.
15
#
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
# CC0 1.0 Universal License for more details.
20

    
21
import pytest
22
from .profiles      import firefox_safe_mode
23
from .server        import do_an_internet
24
from .script_loader import load_script
25

    
26
@pytest.fixture(scope="module")
27
def proxy():
28
    httpd = do_an_internet()
29
    yield httpd
30
    httpd.shutdown()
31

    
32
@pytest.fixture(scope="module")
33
def driver(proxy):
34
    with firefox_safe_mode() as driver:
35
        yield driver
36
        driver.quit()
37

    
38
def test_proxy(driver):
39
    """
40
    A trivial test case that verifies mocked web pages served by proxy can be
41
    accessed by the browser driven.
42
    """
43
    for proto in ['http://', 'https://']:
44
        driver.get(proto + 'gotmyowndoma.in')
45
        element = driver.find_element_by_tag_name('title')
46
        title = driver.execute_script('return arguments[0].innerText;', element)
47
        assert "Schrodinger's Document" in title
48

    
49
def test_script_loader(driver):
50
    """
51
    A trivial test case that verifies Haketilo's .js files can be properly
52
    loaded into a test page together with their dependencies.
53
    """
54
    driver.get('http://gotmyowndoma.in')
55
    driver.execute_script(load_script('common/stored_types.js', ['common']))
56
    get_var_prefix = 'return window.haketilo_exports.TYPE_PREFIX.VAR;'
57
    assert driver.execute_script(get_var_prefix) == '_'
(8-8/9)