def test_withdraw(self): nick = 'Testie' phenny = DummyPhenny(self.start, self.end) inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append('%s %s' % (self.start.strftime('%H:%M'), self.end.strftime('%H:%M'))) nanowars.war(phenny, inputobj) inputobj = DummyInput(nick) inputobj.properties.append('participate') inputobj.properties.append('war 1') nanowars.participate(phenny, inputobj) assert 'OK, ik verwittig je persoonlijk 10 seconden voordat war 1 begint, en nog eens wanneer de war eindigt, %s' % nick in phenny.said, 'Phenny should confirm participation.' inputobj = DummyInput(nick) inputobj.properties.append('withdraw') inputobj.properties.append('1') nanowars.withdraw(phenny, inputobj) assert 'OK, ik schrap je uit de deelnemerslijst, %s.' % nick, 'Phenny should confirm that %s doesn\'t participate' % nick time_to_wait = int(self.end.strftime('%s')) - time.time() time.sleep(time_to_wait + 5) expected_said = '%s, war 1 begint over 10 seconden.' % nick assert expected_said not in phenny.said, 'Expected phenny not to say %s, instead she said %s' % (expected_said, '\n'.join(phenny.said)) phenny_said = filter(lambda said: 'STOP' in said, phenny.said) assert len(phenny_said) == 1, 'Phenny should stopped the war, instead she said: %s' % '\n'.join(phenny.said) assert nick not in phenny_said[0], 'Phenny should not have notified %s when stopping the war, instead she said: %s' % '\n'.join(phenny.said)
def test_participate_again(self): nick = 'Testie' phenny = DummyPhenny(self.start, self.end) inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append('%s %s' % (self.start.strftime('%H:%M'), self.end.strftime('%H:%M'))) nanowars.war(phenny, inputobj) inputobj = DummyInput(nick) inputobj.properties.append('participate') inputobj.properties.append('1') nanowars.participate(phenny, inputobj) nanowars.participate(phenny, inputobj) assert 'Geen zorgen %s, ik was nog niet vergeten dat je meedoet :-)' % nick in phenny.said, 'Phenny should say that %s already participates' % nick time_to_wait = int(self.end.strftime('%s')) - time.time() time.sleep(time_to_wait + 5) expected_said = '%s, war 1 begint over 10 seconden.' % nick assert expected_said in phenny.said, 'Expected phenny to say %s, instead she said %s' % (expected_said, '\n'.join(phenny.said)) phenny_said = filter(lambda said: 'STOP' in said, phenny.said) assert len(phenny_said) == 1, 'Phenny should have notified people when stopping the war, instead she said: %s' % '\n'.join(phenny.said) assert nick in phenny_said[0], 'Phenny should have notified %s when stopping the war, instead she said: %s' % (nick, '\n'.join(phenny.said))
def test_war_too_long(self): end = self.now + datetime.timedelta(hours=6) - datetime.timedelta(microseconds=self.now.microsecond) - datetime.timedelta(seconds=self.now.second) phenny = DummyPhenny(self.start, end) inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append('%s %s' % (self.start.strftime('%H:%M'), end.strftime('%H:%M'))) nanowars.war(phenny, inputobj) expected_said = 'Een war van meer dan 5 uur? Ik dacht het niet.' assert expected_said in phenny.said, 'Expected phenny to say %s, instead she said %s' % (expected_said, '\n'.join(phenny.said))
def test_not_enough_arguments(self): nick = 'Testie' phenny = DummyPhenny() inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append(self.start.strftime('%H:%M')) nanowars.war(phenny, inputobj) expected_said = 'Ik moet wel weten wanneer de war start EN eindigt, %s. Als ik hem alleen moet stoppen moet je busy zeggen als startuur.' % nick assert expected_said in phenny.said, 'Expected phenny to say %s, instead she said %s' % (expected_said, '\n'.join(phenny.said))
def test_withdraw_not_participating(self): nick = 'Testie' phenny = DummyPhenny(self.start, self.end) inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append('%s %s' % (self.start.strftime('%H:%M'), self.end.strftime('%H:%M'))) nanowars.war(phenny, inputobj) inputobj = DummyInput(nick) inputobj.properties.append('withdraw') inputobj.properties.append('1') nanowars.withdraw(phenny, inputobj) assert 'Je deed niet mee, %s :-)' % nick in phenny.said, 'Phenny should tell %s that he wasn\'t participating.'
def test_one_of_two_withdraws(self): nick = 'Testie' nick2 = 'AnotherTester' start = self.start + datetime.timedelta(minutes=1) end = self.end + datetime.timedelta(minutes=1) phenny = DummyPhenny(start, end) inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append('%s %s' % (start.strftime('%H:%M'), end.strftime('%H:%M'))) nanowars.war(phenny, inputobj) inputobj = DummyInput(nick) inputobj.properties.append('participate') inputobj.properties.append('1') nanowars.participate(phenny, inputobj) assert 'OK, ik verwittig je persoonlijk 10 seconden voordat war 1 begint, en nog eens wanneer de war eindigt, %s' % nick in phenny.said, 'Phenny should confirm participation.' inputobj = DummyInput(nick2) inputobj.properties.append('participate') inputobj.properties.append('1') nanowars.participate(phenny, inputobj) assert 'OK, ik verwittig je persoonlijk 10 seconden voordat war 1 begint, en nog eens wanneer de war eindigt, %s' % nick2 in phenny.said, 'Phenny should confirm participation.' inputobj = DummyInput(nick) inputobj.properties.append('withdraw') inputobj.properties.append('1') nanowars.withdraw(phenny, inputobj) assert 'OK, ik schrap je uit de deelnemerslijst, %s.' % nick, 'Phenny should confirm that %s doesn\'t participate' % nick time_to_wait = int(end.strftime('%s')) - time.time() time.sleep(time_to_wait + 5) phenny_said = filter(lambda said: 'war 1 begint over 10 seconden' in said, phenny.said) assert len(phenny_said) == 1, 'Phenny should have notified people, instead she said: %s' % '\n'.join(phenny.said) assert nick not in phenny_said[0], 'Phenny should not have notified %s when stopping the war, instead she said: %s' % (nick, '\n'.join(phenny.said)) assert nick2 in phenny_said[0], 'Phenny should have notified %s when stopping the war, instead she said: %s' % (nick2, '\n'.join(phenny.said)) phenny_said = filter(lambda said: 'STOP' in said, phenny.said) assert len(phenny_said) == 1, 'Phenny should have notified people when stopping the war, instead she said: %s' % '\n'.join(phenny.said) assert nick not in phenny_said[0], 'Phenny should not have notified %s when stopping the war, instead she said: %s' % (nick, '\n'.join(phenny.said)) assert nick2 in phenny_said[0], 'Phenny should have notified %s when stopping the war, instead she said: %s' % (nick2, '\n'.join(phenny.said))
def test_two_wars_last_planned_first(self): phenny = DummyPhenny(self.start, self.end) phenny2 = DummyPhenny(self.start + datetime.timedelta(minutes=2), self.end + datetime.timedelta(minutes=2)) inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append('%s %s' % (self.start.strftime('%H:%M'), self.end.strftime('%H:%M'))) inputobj2 = DummyInput() inputobj2.properties.append('war') inputobj2.properties.append('%s %s' % (phenny2.expected_start.strftime('%H:%M'), phenny2.expected_end.strftime('%H:%M'))) nanowars.war(phenny2, inputobj2) nanowars.war(phenny, inputobj) time_to_wait = int(phenny2.expected_end.strftime('%s')) - time.time() time.sleep(time_to_wait + 5) duration = (self.end - self.start).seconds / 60 assert 'START war 2 (van %s tot %s, %s %s dus)' % (self.start.strftime('%H:%M'), self.end.strftime('%H:%M'), duration, 'minuut' if duration == 1 else 'minuten') in phenny.said, 'phenny.say was not called with START' assert len(filter(lambda x: 'War 2: STOP' in x, phenny.said)) > 0, 'phenny.say was not called with STOP' assert '3' in phenny.said, 'phenny.say was not called with 3' assert '2' in phenny.said, 'phenny.say was not called with 2' assert '1' in phenny.said, 'phenny.say was not called with 1' assert 'War 2 is voorbij. Je kan je score registreren met .score 2 <score>' in phenny.said, 'phenny did not say how to register score' assert 'Een overzichtje kan je vinden op http://phenny.venefyxatu.be/wars/2/overview/' in phenny.said, 'phenny did not say where to find the score list' duration = (phenny2.expected_end - phenny2.expected_start).seconds / 60 assert 'START war 1 (van %s tot %s, %s %s dus)' % (phenny2.expected_start.strftime('%H:%M'), phenny2.expected_end.strftime('%H:%M'), duration, 'minuut' if duration == 1 else 'minuten') in phenny2.said, 'phenny2.say was not called with START' assert len(filter(lambda x: 'War 1: STOP' in x, phenny2.said)) > 0, 'phenny2.say was not called with STOP' assert '3' in phenny2.said, 'phenny2.say was not called with 3' assert '2' in phenny2.said, 'phenny2.say was not called with 2' assert '1' in phenny2.said, 'phenny2.say was not called with 1' assert 'War 1 is voorbij. Je kan je score registreren met .score 1 <score>' in phenny2.said, 'phenny2 did not say how to register score' assert 'Een overzichtje kan je vinden op http://phenny.venefyxatu.be/wars/1/overview/' in phenny2.said, 'phenny2 did not say where to find the score list'
def test_busy_war(self): end = self.now + datetime.timedelta(minutes=1) end -= datetime.timedelta(seconds=end.second, microseconds=end.microsecond) phenny = DummyPhenny() phenny.expected_end = end inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append('busy %s' % end.strftime('%H:%M')) inputobj.properties.append(end) nanowars.war(phenny, inputobj) time.sleep(2) expected_said = 'Ik zal het stopsein geven om %s.' % end.strftime('%H:%M') assert expected_said in phenny.said, 'Expected phenny to say %s, instead she said %s' % (expected_said, '\n'.join(phenny.said)) expected_unsaid = 'Ik zal het startsein geven voor war 1 om %s.' % self.now.strftime('%H:%M') assert expected_unsaid not in phenny.said, 'Expected phenny not to say %s, instead she said %s' % (expected_unsaid, '\n'.join(phenny.said)) time_to_wait = int(end.strftime('%s')) - time.time() time.sleep(time_to_wait + 5) assert len(filter(lambda x: 'War 1: STOP' in x, phenny.said)) > 0, 'phenny.say was not called with STOP'
def test_two_participants(self): nick = 'Testie' nick2 = 'AnotherTester' phenny = DummyPhenny(self.start, self.end) inputobj = DummyInput() inputobj.properties.append('war') inputobj.properties.append('%s %s' % (self.start.strftime('%H:%M'), self.end.strftime('%H:%M'))) nanowars.war(phenny, inputobj) inputobj = DummyInput(nick) inputobj.properties.append('participate') inputobj.properties.append('1') nanowars.participate(phenny, inputobj) assert 'OK, ik verwittig je persoonlijk 10 seconden voordat war 1 begint, en nog eens wanneer de war eindigt, %s' % nick in phenny.said, 'Phenny should confirm participation.' inputobj = DummyInput(nick2) inputobj.properties.append('participate') inputobj.properties.append('1') nanowars.participate(phenny, inputobj) assert 'OK, ik verwittig je persoonlijk 10 seconden voordat war 1 begint, en nog eens wanneer de war eindigt, %s' % nick2 in phenny.said, 'Phenny should confirm participation.' time_to_wait = int(self.end.strftime('%s')) - time.time() time.sleep(time_to_wait + 5) phenny_said = filter(lambda said: 'war 1 begint over 10 seconden' in said, phenny.said) assert len(phenny_said) == 1, 'Phenny should have notified people, instead she said: %s' % '\n'.join(phenny.said) assert nick in phenny_said[0], 'Phenny should have notified %s when stopping the war, instead she said: %s' % (nick, '\n'.join(phenny.said)) assert nick2 in phenny_said[0], 'Phenny should have notified %s when stopping the war, instead she said: %s' % (nick2, '\n'.join(phenny.said)) phenny_said = filter(lambda said: 'STOP' in said, phenny.said) assert len(phenny_said) == 1, 'Phenny should have notified people when stopping the war, instead she said: %s' % '\n'.join(phenny.said) assert nick in phenny_said[0], 'Phenny should have notified %s when stopping the war, instead she said: %s' % (nick, '\n'.join(phenny.said)) assert nick2 in phenny_said[0], 'Phenny should have notified %s when stopping the war, instead she said: %s' % (nick2, '\n'.join(phenny.said))