Example #1
0
    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)
Example #2
0
    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))
Example #3
0
    def test_invalid_data(self):
        phenny = DummyPhenny()

        nick = 'Testie'

        inputobj = DummyInput(nick)
        inputobj.properties.append('participate')
        inputobj.properties.append('999')

        nanowars.participate(phenny, inputobj)

        assert 'Die war ken ik niet, %s' % nick in phenny.said, 'Phenny should warn that she doesn\'t know an unplanned war.'
Example #4
0
    def test_no_args(self):
        phenny = DummyPhenny()

        nick = 'Testie'

        inputobj = DummyInput(nick)
        inputobj.properties.append('participate')

        nanowars.participate(phenny, inputobj)

        phenny_said = filter(lambda said: 'Ja, maar waaraan wil je deelnemen, %s?' % nick in said, phenny.said)
        assert len(phenny_said) == 1, 'Phenny should ask what to participate in, instead she said: %s' % '\n'.join(phenny.said)
Example #5
0
    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))
Example #6
0
    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))