This repository was archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 447
/
Copy pathtest_text.py
64 lines (52 loc) · 2.15 KB
/
test_text.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pytest
from flask import request
from urllib.parse import urljoin
from slugify.main import Slugify
from quokka.utils.text import (
abbreviate, normalize_var,
make_social_link, make_social_link,
make_social_name, cdata,
make_external_url, split_all_category_roots,
remove_tags_from_string
)
################################
#pytest - fixtures - setUp(); #
################################
slugify = Slugify()
slugify.to_lower = True
slugify_category = Slugify()
slugify_category.to_lower = True
slugify_category.safe_chars = '/'
abbrev = abbreviate("pytest-mock")
norma = normalize_var("http://yahoo.com")
make_link = make_social_link(network="twitter", txt="http://twitter.com/python")
make_name = make_social_name('http://twitter.com/python')
data = cdata("py-cdata")
split = split_all_category_roots(cat="categoria1/categoria2/categoria3")
##################################
#pytest - Quokka - test_text.py #
##################################
def test_abbreviate():
debugger = abbreviate("pytest-mock")
assert abbrev == 'pytest-mock'
def test_normalize_var():
assert norma == "http:__yahoo.com"
def test_make_social_link():
assert make_link == 'http://twitter.com/python'
def test_make_social_name():
assert make_name == 'python'
def test_cdata():
assert data == '<![CDATA[\npy-cdata\n]]>'
def test_make_external_url():
with pytest.raises(RuntimeError) as err:
make_external_url("http://it.yahoo.com")
assert "Working outside of application context." in str(err.value)
def test_split_all_category_roots():
assert split[0] == 'categoria1/categoria2/categoria3'
assert split[1] == 'categoria1/categoria2'
assert split[2] == 'categoria1'
def test_remove_tags_from_string():
assert remove_tags_from_string('<script>alert("python-quokka");</script>') == 'alertpython-quokka'
assert remove_tags_from_string('<script>console.log("python-quokka");</script>') == 'console.logpython-quokka'
assert remove_tags_from_string('<b>python-quokka</b>') == 'python-quokka'
assert remove_tags_from_string('<style>position:relative;top:10px;float:left;</style>') == 'position:relativetop:10pxfloat:left'