forked from lepture/og.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_og.py
58 lines (42 loc) · 1.53 KB
/
test_og.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
# coding: utf-8
import og
def test_parse_no_data():
assert not og.parse(u'')
def test_parse_only_title():
html = u'<head><title>Pure Title</title></head>'
assert str(og.parse(html)) == str({u'title': u'Pure Title'})
def test_parse_uppercase():
html = u'<head><TITLE>Pure Title</title></head>'
assert str(og.parse(html)) == str({u'title': u'Pure Title'})
def test_parse_og_info():
html = u'''
<head>
<meta property="og:title" content="Python on A Hard Wheel">
<meta property="og:image" content="image_src">
<meta property="og:url"
content="http://lepture.com/en/2014/python-on-a-hard-wheel">
<meta property="og:description" content="How to build and distribute
binary wheels on your Mac for every Mac.">
<meta name="twitter:creator" content="@lepture">
</head>
'''
rv = og.parse(html)
assert rv[u'title'] == u'Python on A Hard Wheel'
assert rv[u'image'] == u'image_src'
assert rv[u'url'] == u'http://lepture.com/en/2014/python-on-a-hard-wheel'
assert rv[u'twitter'] == u'@lepture'
assert u'description' in rv
def test_parse_twitter_card():
html = u'''
<head>
<meta name="twitter:title" content="Python on A Hard Wheel">
</head>
'''
rv = og.parse(html)
assert rv[u'title'] == u'Python on A Hard Wheel'
def test_empty_name():
html = u'<head><meta name="" content="empty name"></head>'
assert not og.parse(html)
def test_empty_content():
html = u'<head><meta name="title" content=""></head>'
assert not og.parse(html)