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_no_args_withdraw(self): phenny = DummyPhenny() nick = 'Testie' inputobj = DummyInput(nick) inputobj.properties.append('withdraw') nanowars.withdraw(phenny, inputobj) phenny_said = filter(lambda said: 'Ja, maar waaraan wil je niet meer deelnemen, %s?' % nick in said, phenny.said) assert len(phenny_said) == 1, 'Phenny should ask what to withdraw from, instead she said %s' % '\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))