tests.py 949 Bytes
Newer Older
frekk's avatar
frekk committed
1
from django.test import TestCase
frekk's avatar
frekk committed
2
3
from django.conf import settings
from datetime import datetime
frekk's avatar
frekk committed
4

frekk's avatar
frekk committed
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
from .cokelog import CokeLog

class ParseCokeLog(TestCase):
    def test_parse_cokelog(self):
        fn = getattr(settings, 'COKELOG_PATH', None)
        if fn is None:
            return

        cokelog = CokeLog()
        self.assertFalse(cokelog.is_loaded())
        cokelog.open()
        self.assertTrue(cokelog.is_loaded())

        self.assertIsInstance(cokelog.dispenses, dict)
        for key, val in cokelog.dispenses.items():
            self.assertIsInstance(val, (list, tuple))
            for record in val:
                self.assertIsInstance(record, dict)
                self.assertTrue('by' in record)
                self.assertTrue('item' in record)
                self.assertIsInstance(record['date'], datetime)

        n = len(cokelog.dispenses)
        cokelog.reload()
        self.assertTrue(n == len(cokelog.dispenses))