Пример #1
0
def test_get_notes():
    """Assert that the puni get_notes function returns a list of Note objects"""
    un = UserNotes(r, my_sub, lazy_start=True)
    tea_notes = un.get_notes('teaearlgraycold')

    assert isinstance(tea_notes, list)
    assert isinstance(tea_notes[0], Note)
Пример #2
0
def test_get_notes():
    """Assert that the puni get_notes function returns a list of Note objects."""
    un = UserNotes(r, my_sub, lazy_start=True)
    tea_notes = un.get_notes('teaearlgraycold')

    assert isinstance(tea_notes, list)
    assert isinstance(tea_notes[0], Note)
Пример #3
0
def test_remove_note():
    """Assert that notes are removed from the usernotes wiki page"""
    un = UserNotes(r, my_sub, lazy_start=True)
    un.remove_note('teaearlgraycold', 0)

    try:
        un.cached_json['users']['teaearlgraycold']
        assert False  # teaearlgraycold should have no notes, and no entry whatsoever
    except KeyError:
        pass
Пример #4
0
def test_add_note():
    """Assert that notes are added to the usernotes wiki page."""
    un = UserNotes(r, my_sub, lazy_start=True)
    note_message = 'test note {}'.format(random.random())
    new_note = Note('teaearlgraycold', note_message, warning='gooduser')
    un.add_note(new_note)
    stored_json = un.get_json()
    messages = {x['n'] for x in stored_json['users']['teaearlgraycold']['ns']}

    assert note_message in messages
Пример #5
0
def test_remove_note():
    """Assert that notes are removed from the usernotes wiki page"""
    un = UserNotes(r, my_sub, lazy_start=True)
    un.remove_note('teaearlgraycold', 0)

    try:
        un.cached_json['users']['teaearlgraycold']
        assert False  # teaearlgraycold should have no notes, and no entry whatsoever
    except KeyError:
        pass
Пример #6
0
def test_init_notes():
    """Assert that the puni init_notes function sends new JSON to the wiki page"""

    un = UserNotes(r, my_sub)
    un.init_notes()
    stored_json = un.get_json()

    assert stored_json['ver'] == un.schema
    assert stored_json['users'] == {}
    assert stored_json['constants']['users'] == [x.name for x in my_sub.get_moderators()]
    assert stored_json['constants']['warnings'] == Note.warnings
Пример #7
0
def test_init_notes():
    """Assert that the puni init_notes function sends new JSON to the wiki page."""
    un = UserNotes(r, my_sub)
    un._init_notes()
    stored_json = un.get_json()
    moderators = [x.name for x in my_sub.moderator()]

    assert stored_json['ver'] == un.schema
    assert stored_json['users'] == {}
    assert stored_json['constants']['users'] == moderators
    assert stored_json['constants']['warnings'] == Note.warnings
Пример #8
0
def test_add_note():
    """Assert that notes are added to the usernotes wiki page"""
    un = UserNotes(r, my_sub, lazy_start=True)

    note_message = "test note {}".format(random.random())
    new_note = Note("teaearlgraycold", note_message, warning='gooduser')

    un.add_note(new_note)
    stored_json = un.get_json()

    for note in stored_json['users']['teaearlgraycold']['ns']:
        if note['n'] == note_message:
            break
    else:
        assert False  # Did not reach a note with the sent message
Пример #9
0
def test_add_note():
    """Assert that notes are added to the usernotes wiki page"""
    un = UserNotes(r, my_sub, lazy_start=True)

    note_message = "test note {}".format(random.random())
    new_note = Note("teaearlgraycold", note_message, warning='gooduser')

    un.add_note(new_note)
    stored_json = un.get_json()

    for note in stored_json['users']['teaearlgraycold']['ns']:
        if note['n'] == note_message:
            break
    else:
        assert False  # Did not reach a note with the sent message
Пример #10
0
def test_lazy_add_note():
    """Assert that the add_note method will not affect the wiki page contents when lazy."""
    un = UserNotes(r, my_sub)
    un2 = UserNotes(r, my_sub, lazy_start=True)
    new_note = Note('foobar', 'foobar note', warning='gooduser')
    un.add_note(new_note, lazy=True)

    assert 'foobar' in un.get_users(lazy=True)
    assert 'foobar' not in un2.get_users()
Пример #11
0
def test_remove_user():
    """Assert that all user's notes are removed from the usernotes wiki page."""
    un = UserNotes(r, my_sub, lazy_start=True)
    un.remove_user('teaearlgraycold')

    assert un.cached_json['users'].get('teaearlgraycold') is None