Пример #1
0
def test_platform_option_tuple():
    for _ in range(50):
        generate_user_agent(os=('win', 'linux'))
        generate_user_agent(os=('win', 'linux', 'mac'))
        generate_user_agent(os=('win',))
        generate_user_agent(os=('linux',))
        generate_user_agent(os=('mac',))
Пример #2
0
def test_platform_option():
    for _ in range(50):
        agent = generate_user_agent(os='linux')
        assert 'linux' in agent.lower()

        agent = generate_user_agent(os='win')
        assert 'windows' in agent.lower()

        agent = generate_user_agent(os='mac')
        assert 'mac' in agent.lower()
Пример #3
0
def test_impossible_combination():
    for _ in range(50):
        with pytest.raises(InvalidOption):
            generate_user_agent(os='linux', navigator='ie')
            generate_user_agent(os='linux', navigator='edge')
        with pytest.raises(InvalidOption):
            generate_user_agent(os='mac', navigator='ie')
            generate_user_agent(os='mac', navigator='edge')
Пример #4
0
def test_navigator_option():
    for _ in range(50):
        agent = generate_user_agent(navigator='firefox')
        assert 'firefox' in agent.lower()

        agent = generate_user_agent(navigator='chrome')
        assert 'chrome' in agent.lower()

        agent = generate_user_agent(navigator='ie')
        assert 'msie' in agent.lower() or 'rv:11' in agent.lower()

        agent = generate_user_agent(navigator='edge')
        assert 'edge' in agent.lower()

        agent = generate_user_agent(navigator='opera')
        assert 'opr' in agent.lower() or 'opios' in agent.lower()
Пример #5
0
def test_platform_navigator_option():
    for _ in range(50):
        agent = generate_user_agent(os='win', navigator='firefox')
        assert 'firefox' in agent.lower()
        assert 'windows' in agent.lower()

        agent = generate_user_agent(os='win', navigator='chrome')
        assert 'chrome' in agent.lower()
        assert 'windows' in agent.lower()

        agent = generate_user_agent(os='win', navigator='ie')
        assert 'msie' in agent.lower() or 'rv:11' in agent.lower()
        assert 'windows' in agent.lower()

        agent = generate_user_agent(os='win', navigator='edge')
        assert 'edge' in agent.lower()
        assert 'windows' in agent.lower()
Пример #6
0
def test_invalid_platform_option():
    with pytest.raises(InvalidOption):
        generate_user_agent(os=11)

    with pytest.raises(InvalidOption):
        generate_user_agent(os='dos')

    with pytest.raises(InvalidOption):
        generate_user_agent(os='win,dos')
Пример #7
0
def test_navigator_option_tuple():
    for _ in range(50):
        generate_user_agent(navigator=('chrome',))
        generate_user_agent(navigator=('chrome', 'firefox'))
        generate_user_agent(navigator=('chrome', 'firefox', 'ie'))
        generate_user_agent(navigator=('chrome', 'firefox', 'ie', 'edge'))
Пример #8
0
def test_invalid_navigator_option():
    with pytest.raises(InvalidOption):
        generate_user_agent(navigator='vim')

    with pytest.raises(InvalidOption):
        generate_user_agent(navigator='chrome,vim')
Пример #9
0
def test_device_type_smartphone_chrome():
    for _ in range(50):
        agent = generate_user_agent(device_type='smartphone',
                                    navigator='chrome')
        assert 'Mobile' in agent
Пример #10
0
def test_mac_chrome():
    for _ in range(50):
        agent = generate_user_agent(os='mac', navigator='chrome')
        assert re.search(r'OS X \d+_\d+(_\d+\b|\b)', agent)
Пример #11
0
def test_no_os_options_default_device_type():
    for _ in range(50):
        agent = generate_user_agent()
        # by default if no os option has given
        # then device_type is "desktop"
        assert 'Android' not in agent
Пример #12
0
def test_invalid_combination_device_type_navigator():
    for _ in range(50):
        with pytest.raises(InvalidOption):
            generate_user_agent(device_type='smartphone', navigator='ie')
Пример #13
0
def test_invalid_combination_device_type_os():
    for _ in range(50):
        with pytest.raises(InvalidOption):
            generate_user_agent(device_type='smartphone', os='win')
Пример #14
0
def test_it():
    agent = generate_user_agent()
    assert len(agent) > 0
Пример #15
0
def test_device_type_option_invalid():
    for _ in range(50):
        with pytest.raises(InvalidOption):
            generate_user_agent(device_type='fridge')
Пример #16
0
def test_device_type_option():
    for _ in range(50):
        agent = generate_user_agent(device_type='smartphone')
        assert 'Android' in agent or 'iPhone' in agent
Пример #17
0
def test_device_type_all():
    for _ in range(50):
        generate_user_agent(device_type='all')
        generate_user_agent(device_type='all', navigator='ie')
Пример #18
0
def test_platform_linux():
    for _ in range(50):
        agent = generate_user_agent(os='linux')
        assert agent.startswith('Mozilla/5.0 (X11;')