-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_daily_parser.py
47 lines (35 loc) · 1.28 KB
/
test_daily_parser.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
#!/usr/bin/env python
# -*- coding: latin-1 -*-
"""Unit tests."""
import unittest
from daily_parser import url_from_args, DonationsParser
class TestDailyParser(unittest.TestCase):
"""Testing methods from daily_parser."""
def test_url_from_args(self):
output = url_from_args(2014, 1)
expected = 'https://dons.wikimedia.fr/journal/2014-01'
self.assertEqual(output, expected)
class TestDonationsParser(unittest.TestCase):
"""Testing DonationsParser class."""
def setUp(self):
self.donations_parser = DonationsParser(2014, 01)
donations_data = {
'01': {'sum': 370, 'avg': 46.25, 'quantity': 8},
'02': {'sum': 5682, 'avg': 132.14, 'quantity': 43}
}
self.donations_parser.donations = donations_data
def test_get_csv(self):
expected = """'day', 'sum', 'quantity', 'avg'
'2014-01-01', 370, 8, 46.25
'2014-01-02', 5682, 43, 132.14
"""
output = self.donations_parser.get_csv()
self.assertEqual(output, expected)
def test_get_js(self):
expected = """var my_var = [
['day', 'sum', 'quantity', 'avg'],
['2014-01-01', 370, 8, 46.25],
['2014-01-02', 5682, 43, 132.14]
];"""
output = self.donations_parser.get_js('my_var')
self.assertEqual(output, expected)