|
| 1 | +import sys, os |
| 2 | +import copy |
| 3 | +import unittest |
| 4 | +import pytest |
| 5 | +from bs4 import BeautifulSoup |
| 6 | + |
| 7 | +sys.path.insert(1, os.path.join(sys.path[0], '..')) |
| 8 | +from csskrt.bootstrapCsskrt import BootstrapCsskrt |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture() |
| 12 | +def bootstrap_csskrt(): |
| 13 | + bs_csskrt = BootstrapCsskrt(os.path.join(os.path.dirname(__file__), 'input/test1.html')) |
| 14 | + before = copy.copy(bs_csskrt.soup) |
| 15 | + bs_csskrt.freshify() |
| 16 | + after = bs_csskrt.soup |
| 17 | + return before, after |
| 18 | + |
| 19 | + |
| 20 | +class TestBootstrapButtons(): |
| 21 | + def test_compare_num_button_tags(self, bootstrap_csskrt): |
| 22 | + before: BeautifulSoup = bootstrap_csskrt[0] |
| 23 | + after: BeautifulSoup = bootstrap_csskrt[1] |
| 24 | + tag = 'button' |
| 25 | + |
| 26 | + old_tags = before.find_all(tag) |
| 27 | + new_tags = after.find_all(tag) |
| 28 | + assert (len(old_tags) == len(new_tags)) |
| 29 | + |
| 30 | + def test_buttons_styles(self, bootstrap_csskrt): |
| 31 | + before: BeautifulSoup = bootstrap_csskrt[0] |
| 32 | + after: BeautifulSoup = bootstrap_csskrt[1] |
| 33 | + tag = 'button' |
| 34 | + style = ['btn', 'btn-primary'] |
| 35 | + |
| 36 | + old_tags = before.find_all(tag) |
| 37 | + new_tags = after.find_all(tag) |
| 38 | + for old_t, new_t in zip(old_tags, new_tags): |
| 39 | + old_class = old_t.get('class', []) |
| 40 | + new_class = new_t.get('class', []) |
| 41 | + |
| 42 | + if type(new_class) == str: # sometimes get returns str instead of list |
| 43 | + new_class = new_class.strip().split(' ') |
| 44 | + |
| 45 | + assert(set(old_class).issubset(new_class)) |
| 46 | + |
| 47 | + def test_buttons_content(self, bootstrap_csskrt): |
| 48 | + before: BeautifulSoup = bootstrap_csskrt[0] |
| 49 | + after: BeautifulSoup = bootstrap_csskrt[1] |
| 50 | + tag = 'button' |
| 51 | + |
| 52 | + old_tags = before.find_all(tag) |
| 53 | + new_tags = after.find_all(tag) |
| 54 | + for old_t, new_t in zip(old_tags, new_tags): |
| 55 | + assert old_t.get_text() == new_t.get_text() |
| 56 | + |
| 57 | + |
| 58 | +class TestBootstrapForm(): |
| 59 | + def test_number_form_tags(self, bootstrap_csskrt): |
| 60 | + before: BeautifulSoup = bootstrap_csskrt[0] |
| 61 | + after: BeautifulSoup = bootstrap_csskrt[1] |
| 62 | + tag = 'form' |
| 63 | + |
| 64 | + old_tags = before.find_all(tag) |
| 65 | + new_tags = after.find_all(tag) |
| 66 | + assert (len(old_tags) == len(new_tags)) |
| 67 | + |
| 68 | + |
| 69 | + def test_form_wrapper(self, bootstrap_csskrt): |
| 70 | + before: BeautifulSoup = bootstrap_csskrt[0] |
| 71 | + after: BeautifulSoup = bootstrap_csskrt[1] |
| 72 | + tag = 'form' |
| 73 | + wrapper_class = 'form-group' |
| 74 | + |
| 75 | + old_tags = before.find_all(tag) |
| 76 | + new_tags = after.find_all(tag) |
| 77 | + for form in new_tags: |
| 78 | + wrappers = form.find_all('div', recursive=False, attrs={'class': wrapper_class}) |
| 79 | + inputs = form.find_all('input') |
| 80 | + assert len(wrappers) == len(inputs) # 1 input per wrapper ? |
| 81 | + |
| 82 | + for wrapper in wrappers: |
| 83 | + inputs = wrapper.find_all('input') |
| 84 | + assert len(inputs) == 1 |
| 85 | + |
| 86 | + |
| 87 | + |
0 commit comments