forked from rrenaud/dominionstats
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_isotropic.py
79 lines (53 loc) · 2.83 KB
/
test_isotropic.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python
# -*- coding: utf-8 -*-
# TODO: Add copyright notice here
from urllib2 import HTTPError
import datetime
import logging
import unittest
import isotropic
import utils
# Module-level logging instance
log = logging.getLogger(__name__)
class IsotropicScraper(unittest.TestCase):
def test_rawgames_functions(self):
"""Validate IsotropicScraper for raw games"""
# Careful, as right now this touches bits of production, such
# as the S3 buckets.
# TODO: Figure out how to get this pointed at a database for
# use in integration tests.
iso = isotropic.IsotropicScraper(None)
self.assertEquals(iso.our_gamelog_filename(datetime.date(2010, 10, 15)),
"20101015.all.tar.bz2")
self.assertEquals(iso.our_gamelog_filename(datetime.date(2010, 3, 7)),
"20100307.all.tar.bz2")
self.assertEquals(iso.isotropic_rawgame_url(datetime.date(2010, 10, 15)),
"http://dominion.isotropic.org/gamelog/201010/15/all.tar.bz2")
self.assertEquals(iso.isotropic_rawgame_url(datetime.date(2010, 3, 7)),
"http://dominion.isotropic.org/gamelog/201003/07/all.tar.bz2")
self.assertEquals(iso.s3_rawgame_url(datetime.date(2010, 10, 15)),
"http://static.councilroom.mccllstr.com/scrape_data/20101015.all.tar.bz2")
self.assertEquals(iso.s3_rawgame_url(datetime.date(2010, 3, 7)),
"http://static.councilroom.mccllstr.com/scrape_data/20100307.all.tar.bz2")
def test_rawgames_integration(self):
"""Validate IsotropicScraper for raw games"""
# Careful, as right now this touches bits of production, such
# as the S3 buckets.
# TODO: Figure out how to get this pointed at a database for
# use in integration tests.
iso = isotropic.IsotropicScraper(utils.get_mongo_database(), 'unittest_raw_games')
self.assertTrue(iso.is_rawgames_in_s3(datetime.date(2010, 10, 15)))
self.assertRaisesRegexp(HTTPError, 'HTTP Error 404: Not Found',
iso.copy_rawgames_to_s3, datetime.date(2009, 10, 15))
content = iso.get_rawgames_from_s3(datetime.date(2010, 10, 15))
self.assertEquals(content[0:7], 'BZh91AY', "Tar file signature")
# TODO: Figure out how to run the lengthy tests that hit
# actual files on Isotropic only in certain limited modes
if None:
iso.copy_rawgames_to_s3(datetime.date(2012, 10, 3))
# Scrape and insert a whole gameday
count = iso.scrape_and_store_rawgames(datetime.date(2012, 9, 15))
self.assertEquals(count, 9999, "Inserted expected number of rawgames")
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
unittest.main()