Use six.text_type instead of unicode().
[mediagoblin.git] / mediagoblin / tests / test_timesince.py
CommitLineData
79e2d4ee
J
1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from datetime import datetime, timedelta
18
19from mediagoblin.tools.timesince import is_aware, timesince
20
21
d38e9779 22def test_timesince():
79e2d4ee
J
23 test_time = datetime.now()
24
25 # it should ignore second and microseconds
26 assert timesince(test_time, test_time + timedelta(microseconds=1)) == "0 minutes"
27 assert timesince(test_time, test_time + timedelta(seconds=1)) == "0 minutes"
28
29 # test minutes, hours, days, weeks, months and years (singular and plural)
30 assert timesince(test_time, test_time + timedelta(minutes=1)) == "1 minute"
31 assert timesince(test_time, test_time + timedelta(minutes=2)) == "2 minutes"
32
33 assert timesince(test_time, test_time + timedelta(hours=1)) == "1 hour"
34 assert timesince(test_time, test_time + timedelta(hours=2)) == "2 hours"
35
36 assert timesince(test_time, test_time + timedelta(days=1)) == "1 day"
37 assert timesince(test_time, test_time + timedelta(days=2)) == "2 days"
38
39 assert timesince(test_time, test_time + timedelta(days=7)) == "1 week"
40 assert timesince(test_time, test_time + timedelta(days=14)) == "2 weeks"
41
42 assert timesince(test_time, test_time + timedelta(days=30)) == "1 month"
43 assert timesince(test_time, test_time + timedelta(days=60)) == "2 months"
44
45 assert timesince(test_time, test_time + timedelta(days=365)) == "1 year"
46 assert timesince(test_time, test_time + timedelta(days=730)) == "2 years"
47
48 # okay now we want to test combinations
49 # e.g. 1 hour, 5 days
50 assert timesince(test_time, test_time + timedelta(days=5, hours=1)) == "5 days, 1 hour"
51
52 assert timesince(test_time, test_time + timedelta(days=15)) == "2 weeks, 1 day"
53
54 assert timesince(test_time, test_time + timedelta(days=97)) == "3 months, 1 week"
55
56 assert timesince(test_time, test_time + timedelta(days=2250)) == "6 years, 2 months"
57