예제 #1
0
def test_update_users_does_not_remove_users(roster):
    evan = User('1', 'Evan', '1', 'avatar1')
    steve = User('2', 'Steve', '1', 'avatar2')
    roster.set_user_attendance(evan, True)
    roster.set_user_attendance(steve, True)

    roster.update_users([evan])
    assert list(roster.attending_users()) == [evan, steve]
예제 #2
0
def test_set_user_attendance_updates_user(roster):
    steve = User('1', 'Steve', '1', 'avatar1')
    roster.set_user_attendance(steve, True)

    steve2 = steve._replace(avatar='avatar2')
    roster.set_user_attendance(steve2, True)

    assert list(roster.attending_users()) == [steve2]
예제 #3
0
def test_attending_users_sorted_by_nick(roster):
    steve = User('1', 'Steve', '1', 'avatar1')
    jay = User('2', 'Jay', '1', 'avatar2')
    bob = User('3', 'Bob', '1', 'avatar3')
    evan = User('4', 'evan', '1', 'avatar4')
    cara = User('5', 'Cara', '1', 'avatar5')
    for user in [steve, jay, bob, evan, cara]:
        roster.set_user_attendance(user, True)

    assert list(roster.attending_users()) == [bob, cara, evan, jay, steve]
예제 #4
0
def test_update_users_preserves_attendance(roster):
    bob = User('1', 'Bob', '1', 'avatar1')
    roster.set_user_attendance(bob, True)

    bob2 = bob._replace(avatar='avatar2')
    roster.update_users([bob2])
    assert list(roster.attending_users()) == [bob2]

    roster.set_user_attendance(bob, False)
    bob3 = bob2._replace(nick='Robert')
    roster.update_users([bob3])
    assert list(roster.attending_users()) == []
예제 #5
0
def test_set_user_attendance(roster):
    bob = User('1', 'Bob', '1', 'avatar1')
    jay = User('2', 'Jay', '1', 'avatar2')
    cara = User('3', 'Cara', '1', 'avatar3')

    roster.set_user_attendance(bob, True)
    roster.set_user_attendance(jay, True)
    roster.set_user_attendance(cara, False)
    assert list(roster.attending_users()) == [bob, jay]

    roster.set_user_attendance(jay, False)
    roster.set_user_attendance(cara, True)
    assert list(roster.attending_users()) == [bob, cara]
예제 #6
0
파일: chat.py 프로젝트: mshroyer/nametagbot
def _nametagbot_user(discord_user):
    nick = discord_user.name
    if discord_user.nick is not None:
        nick = discord_user.nick

    return User(discord_user.id, nick, discord_user.discriminator,
                discord_user.avatar)
예제 #7
0
def test_not_found_avatar_raises_exception(cache, tmpdir):
    responses.add(responses.GET,
                  CDN_PREFIX + 'avatars/123/avatar1.png',
                  status=404)

    user = User('123', 'foo', '1', 'avatar1')
    output_path = os.path.join(str(tmpdir), 'out.png')
    with pytest.raises(ValueError):
        cache.get_avatar(user, output_path)
예제 #8
0
def test_unexpected_content_type_raises_exception(cache, tmpdir):
    responses.add(responses.GET,
                  CDN_PREFIX + 'avatars/123/avatar1.png',
                  status=200,
                  content_type='image/jpeg')

    user = User('123', 'foo', '1', 'avatar1')
    output_path = os.path.join(str(tmpdir), 'out.png')
    with pytest.raises(ValueError):
        cache.get_avatar(user, output_path)
예제 #9
0
def test_does_not_request_cached_avatars(cache, tmpdir):
    responses.add(responses.GET,
                  CDN_PREFIX + 'avatars/123/avatar1.png',
                  status=200,
                  content_type='image/png')

    user = User('123', 'foo', '1', 'avatar1')
    for i in range(3):
        cache.get_avatar(user, os.path.join(str(tmpdir),
                                            'out{}.png'.format(i)))

    assert len(responses.calls) == 1
예제 #10
0
def test_fetches_default_for_user_without_avatar(cache, tmpdir):
    responses.add(responses.GET,
                  CDN_PREFIX + 'embed/avatars/1.png',
                  status=200,
                  content_type='image/png',
                  body=b'default_avatar_1')

    user = User('123', 'foo', '1', '')
    output_path = os.path.join(str(tmpdir), 'out.png')
    cache.get_avatar(user, output_path)

    with open(output_path, 'rb') as f:
        data = f.read()

    assert data == b'default_avatar_1'
예제 #11
0
파일: data.py 프로젝트: mshroyer/nametagbot
    def attending_users(self):
        cur = self.db.cursor()
        cur.execute('''
            SELECT user_id, nick, discriminator, avatar
            FROM Attendance NATURAL LEFT JOIN User
            ORDER BY nick COLLATE NOCASE ASC;
        ''')

        while True:
            rows = cur.fetchmany()
            if not rows:
                break
            for row in rows:
                yield User(*row)

        cur.close()
예제 #12
0
def test_accepts_multi_digit_user_id(roster):
    user = User('123', 'Bob', '456', 'avatar1')
    roster.set_user_attendance(user, True)
    assert list(roster.attending_users()) == [user]
예제 #13
0
def test_update_users_accepts_unknown_users(roster):
    user1 = User('1', 'Bob', '1', 'avatar1')
    roster.update_users([user1])