コード例 #1
0
def test_actie(monkeypatch, capsys):
    def mock_nieuw(*args):
        print('called Actie.nieuw()')

    def mock_read(*args):
        print('called Actie.read()')

    monkeypatch.setattr(dmlm, 'Settings', MockSettings)
    monkeypatch.setattr(dmlm.Actie, 'read', mock_read)
    monkeypatch.setattr(dmlm.Actie, 'nieuw', mock_nieuw)
    testobj = dmlm.Actie('', '0')
    assert testobj.imagecount == 1
    assert testobj.id == '0'
    assert (testobj.imagelist, testobj.events) == ([], [])
    assert (testobj.datum, testobj.updated, testobj.soort,
            testobj.titel) == ('', '', '', '')
    assert (testobj.status, testobj.arch) == ('0', False)
    assert testobj.melding == ''
    assert capsys.readouterr().out == 'called Actie.nieuw()\n'
    testobj = dmlm.Actie('', 'x')
    assert testobj.imagecount == 1
    assert testobj.id == 'x'
    assert (testobj.imagelist, testobj.events) == ([], [])
    assert (testobj.datum, testobj.updated, testobj.soort,
            testobj.titel) == ('', '', '', '')
    assert (testobj.status, testobj.arch) == ('0', False)
    assert testobj.melding == ''
    assert capsys.readouterr().out == 'called Actie.read()\n'
コード例 #2
0
def test_actie_nieuw(monkeypatch, capsys):
    monkeypatch.setattr(dmlm.dt, 'datetime', MockDatetime)
    monkeypatch.setattr(dmlm, 'Settings', MockSettings)
    monkeypatch.setattr(dmlm, 'get_nieuwetitel', lambda y, x: str(x) + '-0001')
    testobj = dmlm.Actie('', '0')  # gaat nieuw() uitvoeren
    assert testobj.id == '2020-0001'
    assert testobj.datum == '2020-01-01 00:00:00'
    assert not testobj.arch
コード例 #3
0
def test_actie_add_event(monkeypatch, capsys):
    def mock_read(*args):
        print('called Actie.read()')

    monkeypatch.setattr(dmlm.dt, 'datetime', MockDatetime)
    monkeypatch.setattr(dmlm, 'Settings', MockSettings)
    monkeypatch.setattr(dmlm.Actie, 'read', mock_read)
    testobj = dmlm.Actie('', 'x')
    assert testobj.events == []
    testobj.add_event('some text')
    assert testobj.events == [('01-01-2020 00:12:00', 'some text')]
    assert capsys.readouterr().out == 'called Actie.read()\n'
コード例 #4
0
def test_actie_read(monkeypatch, capsys):
    def mock_find_one(self, *args, **kwargs):
        return {
            '_id': 100,
            'jaar': '2020',
            'nummer': '0001',
            'gemeld': 'vandaag',
            'status': 0,
            'soort': 'A',
            'bijgewerkt': 'ook vandaag',
            'onderwerp': 'it',
            'titel': 'whatever',
            'melding': 'dit',
            'archived': True,
            'events': [('zonet', 'iets'), ('straks', 'nog iets')]
        }

    def mock_find_none(self, *args, **kwargs):
        return None

    monkeypatch.setattr(dmlm, 'Settings', MockSettings)
    monkeypatch.setattr(MockColl, 'find_one', mock_find_one)
    monkeypatch.setattr(dmlm, 'coll', MockColl())
    testobj = dmlm.Actie('', '2020-0001')  # read is executed during __init__
    assert testobj.exists
    assert testobj.id == '2020-0001'
    assert testobj.datum == 'vandaag'
    assert testobj.status == 0
    assert testobj.soort == 'A'
    assert testobj.updated == 'ook vandaag'
    assert testobj.titel == 'whatever'
    assert testobj.melding == 'dit'
    assert testobj.arch
    assert testobj.events == [('zonet', 'iets'), ('straks', 'nog iets')]
    monkeypatch.setattr(MockColl, 'find_one', mock_find_none)
    monkeypatch.setattr(dmlm, 'coll', MockColl())
    with pytest.raises(dmlm.DataError) as excinfo:
        testobj = dmlm.Actie('', '1-1')  # read is executed during __init__
    assert str(excinfo.value) == 'Actie object does not exist'
コード例 #5
0
def test_actie_get_soorttext(monkeypatch, capsys):
    def mock_read(*args):
        print('called Actie.read()')

    monkeypatch.setattr(dmlm, 'Settings', MockSettings)
    monkeypatch.setattr(dmlm.Actie, 'read', mock_read)
    testobj = dmlm.Actie('', '1')
    testobj.settings.cat = {'N': ('nieuw', 0)}
    testobj.soort = 'N'
    assert testobj.get_soorttext() == 'nieuw'
    assert capsys.readouterr().out == 'called Actie.read()\n'
    testobj.soort = 'Q'
    with pytest.raises(dmlm.DataError) as excinfo:
        testobj.get_soorttext()
    assert str(excinfo.value) == 'Geen tekst gevonden bij soortcode Q'
コード例 #6
0
def test_actie_cleanup(monkeypatch, capsys):
    def mock_read(*args):
        print('called Actie.read()')

    def mock_remove(*args):
        print('called os.remove() with args', args)

    monkeypatch.setattr(dmlm.os, 'remove', mock_remove)
    monkeypatch.setattr(dmlm, 'Settings', MockSettings)
    monkeypatch.setattr(dmlm.Actie, 'read', mock_read)
    testobj = dmlm.Actie('', '1')
    testobj.imagelist = ['image1', 'image2']
    testobj.cleanup()
    assert capsys.readouterr().out == (
        'called Actie.read()\n'
        "called os.remove() with args ('image1',)\n"
        "called os.remove() with args ('image2',)\n")
コード例 #7
0
def test_actie_write(monkeypatch, capsys):
    def mock_nieuw(*args):
        print('called Actie.nieuw()')

    def mock_read(*args):
        print('called Actie.read()')

    def mock_insert_one(self, *args):
        print('called coll.insert_one() with args', args)
        return types.SimpleNamespace(inserted_id='5')

    def mock_update_one(self, *args):
        print('called coll.update_one() with args', args)

    monkeypatch.setattr(dmlm.dt, 'datetime', MockDatetime)
    monkeypatch.setattr(dmlm, 'Settings', MockSettings)
    monkeypatch.setattr(dmlm.Actie, 'nieuw', mock_nieuw)
    monkeypatch.setattr(dmlm.Actie, 'read', mock_read)
    monkeypatch.setattr(MockColl, 'insert_one', mock_insert_one)
    monkeypatch.setattr(MockColl, 'update_one', mock_update_one)
    monkeypatch.setattr(dmlm, 'coll', MockColl())
    testobj = dmlm.Actie('', '0')
    testobj.exists = False
    testobj.id = '2020-0001'
    testobj.datum = 'vandaag'
    testobj.status = 0
    testobj.soort = 'A'
    # testobj.updated = 'ook vandaag'
    testobj.over = 'it'
    testobj.titel = 'whatever'
    testobj.melding = 'dit'
    testobj.arch = False
    testobj.events = [('zonet', 'iets'), ('straks', 'nog iets')]
    testobj.write()
    assert testobj.settings.startitem == '5'
    assert capsys.readouterr().out == (
        'called Actie.nieuw()\n'
        "called coll.insert_one() with args ({'jaar': 2020, 'nummer': 1},)\n"
        'called Settings.write()\n'
        "called coll.update_one() with args ({'_id': '5'}, {'$set': {'gemeld': 'vandaag',"
        " 'status': 0, 'soort': 'A', 'bijgewerkt': '2020-01-01 00:00:00',"
        " 'onderwerp': 'it', 'titel': 'whatever', 'melding': 'dit', 'archived': False,"
        " 'events': [('zonet', 'iets'), ('straks', 'nog iets')]}})\n")
    testobj = dmlm.Actie('', '1')
    testobj.actie_id = '10'
    testobj.exists = True
    testobj.id = '2020-0001'
    testobj.datum = 'vandaag'
    testobj.status = 0
    testobj.soort = 'A'
    # testobj.updated = 'ook vandaag'
    testobj.over = 'it'
    testobj.titel = 'whatever'
    testobj.melding = 'dit'
    testobj.arch = True
    testobj.events = [('zonet', 'iets'), ('straks', 'nog iets')]
    testobj.write()
    assert testobj.settings.startitem == '10'
    assert capsys.readouterr().out == (
        'called Actie.read()\n'
        'called Settings.write()\n'
        "called coll.update_one() with args ({'_id': '10'}, {'$set': {'gemeld': 'vandaag',"
        " 'status': 0, 'soort': 'A', 'bijgewerkt': '2020-01-01 00:00:00',"
        " 'onderwerp': 'it', 'titel': 'whatever', 'melding': 'dit', 'archived': True,"
        " 'events': [('zonet', 'iets'), ('straks', 'nog iets')]}})\n")