~awuerl/blitzortung-python/master

« back to all changes in this revision

Viewing changes to tests/db/test_db_mapper.py

  • Committer: Andreas Wuerl
  • Date: 2019-06-24 19:32:25 UTC
  • mto: This revision was merged to the branch mainline in revision 394.
  • Revision ID: git-v1:29d4be282c05035bdff8d4828573537ed6d8ceea
update tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
"""
20
20
 
 
21
import datetime
21
22
from unittest import TestCase
22
 
import datetime
23
23
 
24
24
import pytz
 
25
import shapely.geometry
 
26
import shapely.wkb
 
27
from assertpy import assert_that
25
28
from mock import Mock, call
26
 
from hamcrest import assert_that, is_, equal_to, none
27
 
import shapely.wkb
28
 
import shapely.geometry
29
29
 
30
30
import blitzortung.builder
31
31
import blitzortung.db.mapper
52
52
        self.strike_builder.build.return_value = self.strike
53
53
 
54
54
    def test_strike_mapper(self):
55
 
        assert_that(self.strike_mapper.create_object(self.result), is_(self.strike))
 
55
        assert_that(self.strike_mapper.create_object(self.result)).is_equal_to(self.strike)
56
56
 
57
 
        assert_that(self.strike_builder.method_calls, is_([
 
57
        assert_that(self.strike_builder.method_calls).is_equal_to([
58
58
            call.set_id(12),
59
59
            call.set_timestamp(self.timestamp, 789),
60
60
            call.set_x(11.0),
64
64
            call.set_station_count(12),
65
65
            call.set_lateral_error(5000),
66
66
            call.build()
67
 
        ]))
 
67
        ])
68
68
 
69
69
    def test_strike_mapper_with_timezone(self):
70
70
        zone = pytz.timezone('CET')
73
73
 
74
74
        timestamp = self.strike_builder.set_timestamp.call_args[0][0]
75
75
 
76
 
        assert_that(timestamp, is_(self.timestamp))
77
 
        assert_that(timestamp.tzinfo.zone, is_(zone.zone))
 
76
        assert_that(timestamp).is_equal_to(self.timestamp)
 
77
        assert_that(timestamp.tzinfo.zone).is_equal_to(zone.zone)
78
78
 
79
79
    def test_strike_mapper_without_timestamp(self):
80
80
        self.result['timestamp'] = None
81
81
 
82
82
        self.strike_mapper.create_object(self.result)
83
83
 
84
 
        assert_that(self.strike_builder.set_timestamp.call_args[0][0], is_(none()))
 
84
        assert_that(self.strike_builder.set_timestamp.call_args[0][0]).is_none()
85
85
 
86
86
 
87
87
class TestStationMapper(TestCase):
103
103
        self.station_builder.build.return_value = self.station
104
104
 
105
105
    def test_station_mapper(self):
106
 
        assert_that(self.strike_mapper.create_object(self.result), is_(self.station))
 
106
        assert_that(self.strike_mapper.create_object(self.result)).is_equal_to(self.station)
107
107
 
108
 
        assert_that(self.station_builder.method_calls, is_([
 
108
        assert_that(self.station_builder.method_calls).is_equal_to([
109
109
            call.set_number(31),
110
110
            call.set_user('<user>'),
111
111
            call.set_name('<name>'),
114
114
            call.set_y(49.0),
115
115
            call.set_timestamp(self.timestamp),
116
116
            call.build()
117
 
        ]))
 
117
        ])
118
118
 
119
119
    def test_strike_mapper_with_timezone(self):
120
120
        zone = pytz.timezone('CET')
123
123
 
124
124
        timestamp = self.station_builder.set_timestamp.call_args[0][0]
125
125
 
126
 
        assert_that(timestamp, is_(self.timestamp))
127
 
        assert_that(timestamp.tzinfo.zone, is_(zone.zone))
 
126
        assert_that(timestamp).is_equal_to(self.timestamp)
 
127
        assert_that(timestamp.tzinfo.zone).is_equal_to(zone.zone)
128
128
 
129
129
    def test_strike_mapper_without_timestamp(self):
130
130
        self.result['begin'] = None
131
131
 
132
132
        self.strike_mapper.create_object(self.result)
133
133
 
134
 
        assert_that(self.station_builder.set_timestamp.call_args[0][0], is_(none()))
 
134
        assert_that(self.station_builder.set_timestamp.call_args[0][0]).is_none()