summaryrefslogtreecommitdiff
path: root/tests/test_api.py
blob: dafe598bf8bfa4a8e16c4d7a176b282f165aa66b (plain)
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
# -*- coding: utf-8 -*-

import time
import unittest

from datetime import datetime

from bvggrabber.api import QueryApi, Departure


class TestQueryApi(unittest.TestCase):

    def test_call(self):
        q = QueryApi()
        self.assertRaises(NotImplementedError, q.call)


class TestDeparture(unittest.TestCase):

    def test_timestamp_futur(self):
        when = time.time() + 10 * 60
        dep = Departure("from", "to", when, "line")
        self.assertLessEqual(dep.remaining().total_seconds(), 600)
        self.assertGreaterEqual(dep.remaining().total_seconds(), 590)

    def test_string_futur(self):
        when = datetime.now()
        when = when.replace(minute=when.minute + 10)
        when = when.strftime('%Y-%m-%d %H:%M:%S')
        dep = Departure("from", "to", when, "line")
        self.assertLessEqual(dep.remaining().total_seconds(), 600)
        self.assertGreaterEqual(dep.remaining().total_seconds(), 590)

    def test_datetime_futur(self):
        when = datetime.now()
        when = when.replace(minute=when.minute + 10)
        dep = Departure("from", "to", when, "line")
        self.assertLessEqual(dep.remaining().total_seconds(), 600)
        self.assertGreaterEqual(dep.remaining().total_seconds(), 590)

    def test_error(self):
        self.assertRaises(ValueError, Departure, "from", "to", "foo", "line")