From d0a9d0f51eba7dd08369edf0bffab0357b162b16 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Thu, 3 Sep 2015 20:35:12 -0700 Subject: [PATCH] add a test for parse_page --- tests/data/dan_bull_search.html | 461 ++++++++++++++++++++++++++++++++ tests/{ => data}/rich.xml | 0 tests/test_local.py | 5 +- tests/test_torrent.py | 18 ++ tests/util.py | 8 + 5 files changed, 491 insertions(+), 1 deletion(-) create mode 100644 tests/data/dan_bull_search.html rename tests/{ => data}/rich.xml (100%) create mode 100755 tests/test_torrent.py create mode 100644 tests/util.py diff --git a/tests/data/dan_bull_search.html b/tests/data/dan_bull_search.html new file mode 100644 index 0000000..b7799c8 --- /dev/null +++ b/tests/data/dan_bull_search.html @@ -0,0 +1,461 @@ + + + + The Pirate Bay - The galaxy's most resilient bittorrent site + + + + + + + + + + + + + + + + + + + + + + + + +

Search results: dan bull Displaying hits from 0 to 15 (approx 15 found)

+ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Type
Name (Order by: Uploaded, Size, ULed by, SE, LE)
View: Single / Double 
SELE
+
+ Audio
+ (Music) +
+
+ +Magnet linkTrusted + Uploaded 04-04 2014, Size 89.33 MiB, ULed by Capajebo + 161
+
+ Audio
+ (Other) +
+
+ +Magnet linkThis torrent has 1 comments. + Uploaded 03-02 2014, Size 294 MiB, ULed by Vakume + 40
+
+ Audio
+ (Music) +
+
+ +Magnet link + Uploaded 01-19 2013, Size 54.86 MiB, ULed by blowingfish + 20
+
+ Audio
+ (Other) +
+
+ +Magnet linkThis torrent has 11 comments. + Uploaded 01-21 2010, Size 236.78 MiB, ULed by SuperSaru + 10
+
+ Audio
+ (Music) +
+
+ +Magnet link + Uploaded 09-02 2014, Size 36.27 MiB, ULed by Bazookus + 10
+
+ Audio
+ (Music) +
+
+ +Magnet linkThis torrent has 1 comments.VIP + Uploaded 09-27 2009, Size 5.51 MiB, ULed by oneanight + 01
+
+ Audio
+ (Music) +
+
+ +Magnet linkThis torrent has 1 comments. + Uploaded 11-29 2009, Size 5.07 MiB, ULed by epiclawl + 00
+
+ Audio
+ (Music) +
+
+ +Magnet link + Uploaded 11-10 2011, Size 5.34 MiB, ULed by Imperator42 + 00
+
+ Audio
+ (Music) +
+
+ +Magnet link + Uploaded 12-20 2011, Size 4.8 MiB, ULed by lerdie + 00
+
+ Audio
+ (Music) +
+
+ +Magnet linkThis torrent has 1 comments. + Uploaded 12-21 2011, Size 3.4 MiB, ULed by mattdow + 01
+
+ Audio
+ (Music) +
+
+ +Magnet linkThis torrent has 3 comments. + Uploaded 12-21 2011, Size 4.8 MiB, ULed by lerdie + 01
+
+ Audio
+ (Other) +
+
+ +Magnet linkThis torrent has 1 comments.VIP + Uploaded 03-09 2012, Size 60.72 MiB, ULed by oneanight + 01
+
+ Audio
+ (Music) +
+
+ +Magnet linkThis torrent has 1 comments. + Uploaded 10-24 2012, Size 6.29 MiB, ULed by PIRATE300 + 00
+
+ Audio
+ (Music) +
+
+ +Magnet linkThis torrent has 1 comments. + Uploaded 11-10 2012, Size 6.41 MiB, ULed by AdpoX10 + 00
+
+ Audio
+ (Other) +
+
+ +Magnet linkThis torrent has 2 comments. + Uploaded 01-19 2013, Size 54.87 MiB, ULed by blowingfish + 01
+
+
+
+ + + + + + \ No newline at end of file diff --git a/tests/rich.xml b/tests/data/rich.xml similarity index 100% rename from tests/rich.xml rename to tests/data/rich.xml diff --git a/tests/test_local.py b/tests/test_local.py index 3d6b8d9..afda395 100755 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -3,10 +3,13 @@ import unittest import pirate.local import os +from tests import util + + class TestLocal(unittest.TestCase): def test_rich_xml(self): - path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'rich.xml') + path = util.data_path('rich.xml') expected = [['magnet:?xt=urn:btih:b03c8641415d3a0fc7077f5bf567634442989a74&dn=High.Chaparall.S02E02.PDTV.XViD.SWEDiSH-HuBBaTiX', '?', '?']] actual = pirate.local.search(path, ('High',)) self.assertEqual(actual, expected) diff --git a/tests/test_torrent.py b/tests/test_torrent.py new file mode 100755 index 0000000..b166359 --- /dev/null +++ b/tests/test_torrent.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import unittest +import pirate.torrent +import os + +from tests import util + + +class TestTorrent(unittest.TestCase): + + def test_rich_xml(self): + res = util.read_data('dan_bull_search.html') + actual = pirate.torrent.parse_page(res) + expected = ([['magnet:?xt=urn:btih:30df4f8b42b8fd77f5e5aa34abbffe97f5e81fbf&dn=Dan+Croll+%26bull%3B+Sweet+Disarray+%5B2014%5D+320&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '16', '1'], ['magnet:?xt=urn:btih:7abd3eda600996b8e6fc9a61b83288e0c6ac0d83&dn=Dan+Bull+-+Massive+Collection&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '4', '0'], ['magnet:?xt=urn:btih:8f8d68fd0a51237c89692c428ed8a8f64a969c70&dn=Dan+Bull+-+Generation+Gaming+-+2013&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '2', '0'], ['magnet:?xt=urn:btih:3da6a0fdc1d67a768cb32597e926abdf3e1a2fdd&dn=Dan+Bull+Collection&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '1', '0'], ['magnet:?xt=urn:btih:5cd371a235317319db7da52c64422f9c2ac75d77&dn=Dan+Bull+-+The+Garden+%7B2014-Album%7D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '1', '0'], ['magnet:?xt=urn:btih:4e14dbd077c920875be4c15971b23b609ad6716a&dn=Dan+Bull+-+Dear+Lily+%5Ban+open+letter+to+Lily+Allen%5D+-+2009%5BMP3+%40&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '1'], ['magnet:?xt=urn:btih:5d9319cf852f7462422cb1bffc37b65174645047&dn=Dan+Bull+-+Dear+Mandy+%5Ban+open+letter+to+Lord+Mandelson%5D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '0'], ['magnet:?xt=urn:btih:1c54af57426f53fdef4bbf1a9dbddf32f7b4988a&dn=Dan+Bull+-+Dear+Lily+%28Lily+Allen%29+%28Song+about+filesharing%29&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '0'], ['magnet:?xt=urn:btih:942c5bf3e1e9bc263939e13cea6ad7bd5f62aa36&dn=Dan+Bull+-+SOPA+Cabana.mp3&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '0'], ['magnet:?xt=urn:btih:d376f68a31b0db652234e790ed7256ac5e32db57&dn=Dan+Bull+-+SOPA+Cabana&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '1'], ['magnet:?xt=urn:btih:28163770a532eb24b9e0865878288a9bbdb7a5e6&dn=Dan+Bull+-+SOPA+Cabana+%5BWORKING%5D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '1'], ['magnet:?xt=urn:btih:779ab0f13a3fbb12ba68b27721491e4d143f26eb&dn=Dan+Bull+-+Bye+Bye+BPI+2012++%5BMP3%40192%5D%28oan%29&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '1'], ['magnet:?xt=urn:btih:2667e4795bd5c868dedcabcb52943f4bb7212bab&dn=Dan+Bull+-+Dishonored+%5BExplicit+ver.%5D+%28Single+2012%29&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '0'], ['magnet:?xt=urn:btih:16364f83c556ad0fd3bb57a4a7c890e7e8087414&dn=Halo+4+EPIC+Rap+By+Dan+Bull&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '0'], ['magnet:?xt=urn:btih:843b466d9fd1f0bee3a476573b272dc2d6d0ebae&dn=Dan+Bull+-+Generation+Gaming+-+2013&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', '0', '1']], [['89.33', 'MiB'], ['294', 'MiB'], ['54.86', 'MiB'], ['236.78', 'MiB'], ['36.27', 'MiB'], ['5.51', 'MiB'], ['5.07', 'MiB'], ['5.34', 'MiB'], ['4.8', 'MiB'], ['3.4', 'MiB'], ['4.8', 'MiB'], ['60.72', 'MiB'], ['6.29', 'MiB'], ['6.41', 'MiB'], ['54.87', 'MiB']], ['04-04 2014', '03-02 2014', '01-19 2013', '01-21 2010', '09-02 2014', '09-27 2009', '11-29 2009', '11-10 2011', '12-20 2011', '12-21 2011', '12-21 2011', '03-09 2012', '10-24 2012', '11-10 2012', '01-19 2013'], ['9890864', '9684858', '8037968', '5295449', '10954408', '5101630', '5185893', '6806996', '6901871', '6902247', '6903548', '7088979', '7756344', '7812951', '8037899']) + self.assertEqual(actual, expected) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/util.py b/tests/util.py new file mode 100644 index 0000000..26f0fbe --- /dev/null +++ b/tests/util.py @@ -0,0 +1,8 @@ +import os + +def data_path(name): + return os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', name) + +def read_data(name): + with open(data_path(name)) as f: + return f.read()