示例#1
0
    def test_status(self, capsys):
        args = 'status'
        main(sys_args=args.split())
        out, _ = capsys.readouterr()

        expected_msg = 'active hooks to send'

        assert expected_msg in out
示例#2
0
    def test_status(self, capsys):
        args = 'status'
        main(sys_args=args.split())
        out, _ = capsys.readouterr()

        expected_msg = 'active hooks to send'

        assert expected_msg in out
示例#3
0
    def test_status_list(self, capsys):
        args = 'status --list'
        main(sys_args=args.split())
        out, _ = capsys.readouterr()

        expected_msg = 'active hooks to send'
        expected_msg2 = 'Detailed list:'

        assert expected_msg in out
        assert expected_msg2 in out
示例#4
0
    def test_add_nooptions(self, capsys):
        args = 'add'

        with pytest.raises(SystemExit):
            main(sys_args=args.split())
        _, err = capsys.readouterr()

        expected_msg = 'error: add command needs --url and --message.'

        assert expected_msg in err.encode('utf-8')
示例#5
0
    def test_status_list(self, capsys):
        args = 'status --list'
        main(sys_args=args.split())
        out, _ = capsys.readouterr()

        expected_msg = 'active hooks to send'
        expected_msg2 = 'Detailed list:'

        assert expected_msg in out
        assert expected_msg2 in out
示例#6
0
    def test_add_nooptions(self, capsys):
        args = 'add'

        with pytest.raises(SystemExit):
            main(sys_args=args.split())
        _, err = capsys.readouterr()

        expected_msg = 'error: add command needs --url and --message.'

        assert expected_msg in err.encode('utf-8')
示例#7
0
    def test_cancel_nonexistent_id(self, capsys):
        n_hooks = len(ses.query(models.Webhook).all())

        args = 'cancel --id 99999999999999'
        main(sys_args=args.split())
        out, _ = capsys.readouterr()

        n_hooks2 = len(ses.query(models.Webhook).all())
        expected_msg = 'Webhook with ID 99999999999999 does not exist\n'

        assert n_hooks == n_hooks2
        assert expected_msg in out.encode('utf-8')
示例#8
0
    def test_cancel_nonexistent_id(self, capsys):
        n_hooks = len(ses.query(models.Webhook).all())

        args = 'cancel --id 99999999999999'
        main(sys_args=args.split())
        out, _ = capsys.readouterr()

        n_hooks2 = len(ses.query(models.Webhook).all())
        expected_msg = 'Webhook with ID 99999999999999 does not exist\n'

        assert n_hooks == n_hooks2
        assert expected_msg in out.encode('utf-8')
示例#9
0
    def test_cancel_without_id(self, capsys):
        n_hooks = len(ses.query(models.Webhook).all())

        args = 'cancel'
        with pytest.raises(SystemExit):
            main(sys_args=args.split())
        _, err = capsys.readouterr()

        n_hooks2 = len(ses.query(models.Webhook).all())
        expected_msg = 'error: cancel command needs --id\n'\
                       'example: ./sender.py cancel --id {id}'

        assert n_hooks == n_hooks2
        assert expected_msg in err.encode('utf-8')
示例#10
0
    def test_cancel_without_id(self, capsys):
        n_hooks = len(ses.query(models.Webhook).all())

        args = 'cancel'
        with pytest.raises(SystemExit):
            main(sys_args=args.split())
        _, err = capsys.readouterr()

        n_hooks2 = len(ses.query(models.Webhook).all())
        expected_msg = 'error: cancel command needs --id\n'\
                       'example: ./sender.py cancel --id {id}'

        assert n_hooks == n_hooks2
        assert expected_msg in err.encode('utf-8')
示例#11
0
    def test_add_without_message(self, capsys):
        test_pin_nomessage = test_pin + 'nomessage'
        args = 'add --url http://' + test_pin_nomessage + '.com'

        with pytest.raises(SystemExit):
            main(sys_args=args.split())
        _, err = capsys.readouterr()

        fhooks = ses.query(models.Webhook)\
            .filter(models.Webhook.message == test_pin_nomessage)

        expected_msg = 'error: add command needs --url and --message.'

        assert fhooks.count() == 0
        assert expected_msg in err.encode('utf-8')
示例#12
0
    def test_add_without_message(self, capsys):
        test_pin_nomessage = test_pin + 'nomessage'
        args = 'add --url http://' + test_pin_nomessage + '.com'

        with pytest.raises(SystemExit):
            main(sys_args=args.split())
        _, err = capsys.readouterr()

        fhooks = ses.query(models.Webhook)\
            .filter(models.Webhook.message == test_pin_nomessage)

        expected_msg = 'error: add command needs --url and --message.'

        assert fhooks.count() == 0
        assert expected_msg in err.encode('utf-8')
示例#13
0
    def test_add(self):
        args = 'add --url http://test.com --message ' + test_pin
        main(sys_args=args.split())
        fhooks = ses.query(models.Webhook)\
            .filter(models.Webhook.message == test_pin)

        assert fhooks.count() == 1

        hook = fhooks.first()

        assert type(hook.id) == int
        assert hook.url.encode('utf-8') == 'http://test.com'
        assert hook.message.encode('utf-8') == test_pin
        assert type(hook.retryat) == datetime.datetime
        assert type(hook.received) == bool
        assert type(hook.attempts) == int
示例#14
0
    def test_add(self):
        args = 'add --url http://test.com --message ' + test_pin
        main(sys_args=args.split())
        fhooks = ses.query(models.Webhook)\
            .filter(models.Webhook.message == test_pin)

        assert fhooks.count() == 1

        hook = fhooks.first()

        assert type(hook.id) == int
        assert hook.url.encode('utf-8') == 'http://test.com'
        assert hook.message.encode('utf-8') == test_pin
        assert type(hook.retryat) == datetime.datetime
        assert type(hook.received) == bool
        assert type(hook.attempts) == int
示例#15
0
    def test_cancel(self):
        test_pin_cancel = test_pin + 'cancel'
        hook = models.Webhook(url='http://test.com', message=test_pin_cancel)
        ses.add(hook)
        ses.commit()

        fhooks = ses.query(models.Webhook)\
            .filter(models.Webhook.message == test_pin_cancel)

        assert fhooks.count() == 1

        hook = fhooks.first()
        hid = hook.id
        args = 'cancel --id ' + str(hid)
        main(sys_args=args.split())

        fhooks = ses.query(models.Webhook).filter(models.Webhook.id == hid)

        assert fhooks.count() == 0
示例#16
0
    def test_cancel(self):
        test_pin_cancel = test_pin + 'cancel'
        hook = models.Webhook(url='http://test.com', message=test_pin_cancel)
        ses.add(hook)
        ses.commit()

        fhooks = ses.query(models.Webhook)\
            .filter(models.Webhook.message == test_pin_cancel)

        assert fhooks.count() == 1

        hook = fhooks.first()
        hid = hook.id
        args = 'cancel --id ' + str(hid)
        main(sys_args=args.split())

        fhooks = ses.query(models.Webhook).filter(models.Webhook.id == hid)

        assert fhooks.count() == 0