Skip to content

Commit

Permalink
Start #46
Browse files Browse the repository at this point in the history
  • Loading branch information
d_dd committed May 2, 2015
1 parent ded12a3 commit d60441e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
6 changes: 6 additions & 0 deletions connections/cytube/plugins/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def _com_points(self, cy, username, args, source):
dl = defer.DeferredList([d1, d2])
dl.addCallback(self.returnPoints, cy, querier, username, source)

def get_part_of_day(self, user_tz_offset, test_time):
pass

def choose_greeting(self, username, points, part_of_day):
pass

def greet(self, res, cy, username, isReg, source):
flag = res[0][0]
if flag & 1: # user has greeted us before
Expand Down
90 changes: 90 additions & 0 deletions connections/cytube/plugins/testpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import unittest
#from points import get_part_of_day, choose_greeting
from points import Points

class TestGreeting(unittest.TestCase):

def setUp(self):
self.g = Points()

def test_part_of_day_0offset_local_time0(self):
# 2015-04-01 0:00:00 midnight
test_time = 1427846400
user_tz_offset = 0
part_of_day = self.g.get_part_of_day(user_tz_offset, test_time)
self.assertEqual('midnight', part_of_day)

def test_part_of_day_0offset_local_time13(self):
# 2015-04-01 13:05:20
test_time= 1429967120
user_tz_offset = 0
part_of_day = self.g.get_part_of_day(user_tz_offset, test_time)
self.assertEqual('afternoon', part_of_day)

def test_part_of_day_minus9offset_local_time5(self):
# 2012-02-29 05:20:59 (-9)
# 2012-02-29 14:20:59 UTC
test_time = 1330525259
user_tz_offset = -9
part_of_day = self.g.get_part_of_day(user_tz_offset, test_time)
self.assertEqual('dawn', part_of_day)

def test_part_of_day_minus4offset_local_time22(self):
# 2030-03-09 22:00:59 (-4)
# 2030-03-10 02:00:59 UTC
test_time = 1899338459
user_tz_offset = -4
part_of_day = self.g.get_part_of_day(user_tz_offset, test_time)
self.assertEqual('night', part_of_day)

def test_part_of_day_11offset_local_time5(self):
# 2015-04-25 05:00:00 (+11)
# 2015-04-24 18:00:00 UTC
test_time = 1429898400
user_tz_offset = 11
part_of_day = self.g.get_part_of_day(user_tz_offset, test_time)
self.assertEqual('dawn', part_of_day)

def test_choose_greeting_testuser_0_dawn(self):
reply = 'Good early morning, TestUser.'
self.assertEqual(reply, self.g.choose_greeting('TestUser', 0, 'dawn'))

def test_choose_greeting_testuser_0_midnight(self):
reply = 'Hi, TestUser.'
self.assertEqual(reply, self.g.choose_greeting('TestUser', 0, 'midnight'))

def test_choose_greeting_testuser_0_evening(self):
reply = 'Good evening, TestUser123.'
self.assertEqual(reply,
self.g.choose_greeting('TestUser123', 0, 'evening'))

def test_choose_greeting_testuser_1_afternoon(self):
reply = 'Good afternoon, Level1User!'
self.assertEqual(reply,
self.g.choose_greeting('Level1User', 1, 'afternoon'))

def test_choose_greeting_testuser_2_dusk(self):
reply = 'Good afternoon Level2User!!'
self.assertEqual(reply,
self.g.choose_greeting('Level2User', 2, 'dusk'))

def test_choose_greeting_testuser_2_morning(self):
reply = 'Good morning Level2User!!'
self.assertEqual(reply,
self.g.choose_greeting('Level2User', 2, 'morning'))

def test_choose_greeting_testuser_0_noon(self):
reply = 'Hi, TestUser.'
self.assertEqual(reply, self.g.choose_greeting('TestUser', 0, 'noon'))

def test_choose_greeting_testuser_1_noon(self):
reply = 'Hi, TestUser!'
self.assertEqual(reply, self.g.choose_greeting('TestUser', 1, 'noon'))

def test_choose_greeting_testuser_2_noon(self):
reply = 'Hi Level2User!!' # no comma
self.assertEqual(reply,
self.g.choose_greeting('Level2User', 2, 'noon'))

if __name__ == '__main__':
unittest.main()

0 comments on commit d60441e

Please sign in to comment.