def test_subentry_palette_subreddits_filter(): api = MagicMock() api.user_name = 'username' api.user_subs = ['/r/linux', '/r/gnu'] root = subentry.SubEntry(api) poproot = root._palette # err IDK about this entry = find_widget(root, kind=Gtk.Entry) entry.props.text = '/r/l' # When using the button, all should be visible down_button = find_widget(root, kind=Gtk.Button) down_button.emit('clicked') wait_for(lambda: poproot.props.visible) assert find_widget(poproot, label='/r/linux', many=True) assert find_widget(poproot, label='/r/gnu', many=True) # err IDK about this entry.is_focus = lambda: True entry.props.text = '/r/li' wait_for(lambda: poproot.props.visible) assert find_widget(poproot, label='/r/linux', many=True) assert not find_widget(poproot, label='/r/gnu', many=True)
def test_reply_palette(datadir): api = MagicMock() toplevel_cv = MagicMock() with open(datadir / 'posttopbar--comment.json') as f: data = json.load(f) bar = posttopbar.PostTopBar(api, data, toplevel_cv) bar.get_toplevel = lambda: api poproot = Gtk.Popover() with patch('gi.repository.Gtk.Popover') as Popover: Popover.return_value = poproot bar.do_event(fake_event('r')) wait_for(lambda: Popover.called) assert poproot.props.visible tv = find_widget(poproot, kind=Gtk.TextView) tv.props.buffer.set_text('hello') btn = find_widget(poproot, kind=Gtk.Button, label='Post Reply') btn.emit('clicked') wait_for(lambda: btn.props.sensitive is False) (name, text, cb), _ = api.reply.call_args assert name == 't1_e9nhj7n' assert text == 'hello' cb({'json': {'data': {'things': [{'data': {'id': 'MYID'}}]}}}) assert poproot.props.visible == False
def test_subentry_palette_subreddits_filter(): api = MagicMock() api.user_name = 'username' api.user_subs = ['/r/linux', '/r/gnu'] root = subentry.SubEntry(api) poproot = root._palette # err IDK about this entry = find_widget(root, kind=Gtk.Entry) entry.props.text = '/r/l' # When using the button, all should be visible down_button = find_widget(root, kind=Gtk.Button) down_button.emit('clicked') wait_for(lambda: poproot.props.visible) assert find_widget(poproot, label='/r/linux', many=True) assert find_widget(poproot, label='/r/gnu', many=True) # err IDK about this entry.is_focus = lambda: True entry.props.text = '/r/li' wait_for(lambda: poproot.props.visible) assert find_widget(poproot, label='/r/linux', many=True) assert not find_widget(poproot, label='/r/gnu', many=True)
def test_subreddit_submit(SubmitWindow): api = MagicMock() root = aboutrow.get_about_row(api, '/r/linux') find_widget(root, label='Submit', kind=Gtk.Button).emit('clicked') wait_for(lambda: SubmitWindow.called) SubmitWindow.assert_called_with(api, sub='linux')
def test_subreddit_submit(SubmitWindow): api = MagicMock() root = aboutrow.get_about_row(api, '/r/linux') find_widget(root, label='Submit', kind=Gtk.Button).emit('clicked') wait_for(lambda: SubmitWindow.called) SubmitWindow.assert_called_with(api, sub='linux')
def test_reply_palette(datadir): api = MagicMock() toplevel_cv = MagicMock() with open(datadir / 'posttopbar--comment.json') as f: data = json.load(f) bar = posttopbar.PostTopBar(api, data, toplevel_cv) bar.get_toplevel = lambda: api poproot = Gtk.Popover() with patch('gi.repository.Gtk.Popover') as Popover: Popover.return_value = poproot bar.do_event(fake_event('r')) wait_for(lambda: Popover.called) assert poproot.props.visible tv = find_widget(poproot, kind=Gtk.TextView) tv.props.buffer.set_text('hello') btn = find_widget(poproot, kind=Gtk.Button, label='Post Reply') btn.emit('clicked') wait_for(lambda: btn.props.sensitive is False) (name, text, cb), _ = api.reply.call_args assert name == 't1_e9nhj7n' assert text == 'hello' cb({'json': {'data': {'things': [{'data': {'id': 'MYID'}}]}}}) assert poproot.props.visible == False
def test_submit_empty(): api = MagicMock() window = submit.SubmitWindow(api) root = window.window submit_button = find_widget(root, label='Submit', kind=Gtk.Button) submit_button.emit('clicked') wait_for(lambda: api.submit.called) loading = find_widget(root, label='Submitting...', kind=Gtk.Button) assert loading.props.sensitive == False
def test_submit_empty(): api = MagicMock() window = submit.SubmitWindow(api) root = window.window submit_button = find_widget(root, label='Submit', kind=Gtk.Button) submit_button.emit('clicked') wait_for(lambda: api.submit.called) loading = find_widget(root, label='Submitting...', kind=Gtk.Button) assert loading.props.sensitive == False
def test_user_about_row(): api = MagicMock() root = aboutrow.get_about_row(api, '/u/bob') assert find_widget(root, label='bob') wait_for(lambda: api.get_user_info.called) (name, cb), _ = api.get_user_info.call_args assert name == 'bob' cb({'data': {'link_karma': 2, 'comment_karma': 1}}) assert find_widget(root, label='2l / 1c')
def test_user_about_row(): api = MagicMock() root = aboutrow.get_about_row(api, '/u/bob') assert find_widget(root, label='bob') wait_for(lambda: api.get_user_info.called) (name, cb), _ = api.get_user_info.call_args assert name == 'bob' cb({'data': {'link_karma': 2, 'comment_karma': 1}}) assert find_widget(root, label='2l / 1c')
def test_subreddit_subscribe_button_toggle(): api = MagicMock() root = aboutrow.get_about_row(api, '/r/linux') btn = find_widget(root, label='Subscribe', kind=Gtk.Button) btn.emit('clicked') wait_for(lambda: api.set_subscribed.called) (name, active, cb), _ = api.set_subscribed.call_args assert name == 'linux' assert active == True cb(None) assert btn == find_widget(root, label='Subscribed', kind=Gtk.Button)
def test_subreddit_subscribe_button_toggle(): api = MagicMock() root = aboutrow.get_about_row(api, '/r/linux') btn = find_widget(root, label='Subscribe', kind=Gtk.Button) btn.emit('clicked') wait_for(lambda: api.set_subscribed.called) (name, active, cb), _ = api.set_subscribed.call_args assert name == 'linux' assert active == True cb(None) assert btn == find_widget(root, label='Subscribed', kind=Gtk.Button)
def test_subentry_palette_activate(): api = MagicMock() api.user_name = 'username' root = subentry.SubEntry(api) root.activate = MagicMock() down_button = find_widget(root, kind=Gtk.Button) down_button.emit('clicked') poproot = root._palette # err IDK about this wait_for(lambda: poproot.props.visible) btn = find_widget( poproot, label='/user/username/submitted', kind=Gtk.Button) btn.emit('clicked') wait_for(lambda: root.activate.emit.called) assert root.activate.emit.call_args[0][0] == '/user/username/submitted'
def test_subreddit_info(): api = MagicMock() root = aboutrow.get_about_row(api, '/r/linux') expander = find_widget(root, kind=Gtk.Expander) expander.activate() wait_for(lambda: api.get_subreddit_info.called) (name, cb), _ = api.get_subreddit_info.call_args assert name == 'linux' cb({'data': {'description': 'hello'}}) assert find_widget(root, label='hello').props.visible == True expander.activate() expander.activate() assert api.get_subreddit_info.call_count == 1
def test_subreddit_info(): api = MagicMock() root = aboutrow.get_about_row(api, '/r/linux') expander = find_widget(root, kind=Gtk.Expander) expander.activate() wait_for(lambda: api.get_subreddit_info.called) (name, cb), _ = api.get_subreddit_info.call_args assert name == 'linux' cb({'data': {'description': 'hello'}}) assert find_widget(root, label='hello').props.visible == True expander.activate() expander.activate() assert api.get_subreddit_info.call_count == 1
def test_subentry_palette_activate(): api = MagicMock() api.user_name = 'username' root = subentry.SubEntry(api) root.activate = MagicMock() down_button = find_widget(root, kind=Gtk.Button) down_button.emit('clicked') poproot = root._palette # err IDK about this wait_for(lambda: poproot.props.visible) btn = find_widget(poproot, label='/user/username/submitted', kind=Gtk.Button) btn.emit('clicked') wait_for(lambda: root.activate.emit.called) assert root.activate.emit.call_args[0][0] == '/user/username/submitted'
def test_submit_good(datadir): api = MagicMock() window = submit.SubmitWindow(api) window.done = MagicMock() root = window.window submit_button = find_widget(root, label='Submit', kind=Gtk.Button) submit_button.emit('clicked') wait_for(lambda: api.submit.called) (data, callback), _ = api.submit.call_args with open(datadir / 'submit--good-response.json') as f: callback(json.load(f)) assert window.done.emit.called (sub, uri), _ = window.done.emit.call_args assert uri == 'https://www.reddit.com/r/test/comments/9teb69/test/'
def test_submit_good(datadir): api = MagicMock() window = submit.SubmitWindow(api) window.done = MagicMock() root = window.window submit_button = find_widget(root, label='Submit', kind=Gtk.Button) submit_button.emit('clicked') wait_for(lambda: api.submit.called) (data, callback), _ = api.submit.call_args with open(datadir / 'submit--good-response.json') as f: callback(json.load(f)) assert window.done.emit.called (sub, uri), _ = window.done.emit.call_args assert uri == 'https://www.reddit.com/r/test/comments/9teb69/test/'
def test_submit_error(datadir): api = MagicMock() window = submit.SubmitWindow(api) root = window.window submit_button = find_widget(root, label='Submit', kind=Gtk.Button) submit_button.emit('clicked') wait_for(lambda: api.submit.called) (data, callback), _ = api.submit.call_args with open(datadir / 'submit--ratelimit-response.json') as f: data = json.load(f) msg = data['json']['errors'][0][1] callback(data) assert submit_button.props.sensitive label = find_widget(root, label=msg) assert label.props.visible
def test_submit_link(): api = MagicMock() window = submit.SubmitWindow(api) root = window.window find_widget(root, placeholder='Title').props.text = 'Some Title' find_widget(root, placeholder='Link').props.text = 'example.com' find_widget(root, placeholder='Subreddit').props.text = 'test' find_widget(root, label='Submit', kind=Gtk.Button).emit('clicked') wait_for(lambda: api.submit.called) (data, cb), _ = api.submit.call_args assert data == { 'kind': 'link', 'sr': 'test', 'title': 'Some Title', 'url': 'example.com', }
def test_submit_error(datadir): api = MagicMock() window = submit.SubmitWindow(api) root = window.window submit_button = find_widget(root, label='Submit', kind=Gtk.Button) submit_button.emit('clicked') wait_for(lambda: api.submit.called) (data, callback), _ = api.submit.call_args with open(datadir / 'submit--ratelimit-response.json') as f: data = json.load(f) msg = data['json']['errors'][0][1] callback(data) assert submit_button.props.sensitive label = find_widget(root, label=msg) assert label.props.visible
def test_submit_link(): api = MagicMock() window = submit.SubmitWindow(api) root = window.window find_widget(root, placeholder='Title').props.text = 'Some Title' find_widget(root, placeholder='Link').props.text = 'example.com' find_widget(root, placeholder='Subreddit').props.text = 'test' find_widget(root, label='Submit', kind=Gtk.Button).emit('clicked') wait_for(lambda: api.submit.called) (data, cb), _ = api.submit.call_args assert data == { 'kind': 'link', 'sr': 'test', 'title': 'Some Title', 'url': 'example.com', }
def test_subentry_palette_subreddits(): api = MagicMock() api.user_name = 'username' api.user_subs = ['/r/linux'] root = subentry.SubEntry(api) down_button = find_widget(root, kind=Gtk.Button) down_button.emit('clicked') poproot = root._palette # err IDK about this wait_for(lambda: poproot.props.visible) assert find_widget(poproot, label='/r/linux', many=True) assert not find_widget(poproot, label='/r/gnu', many=True) api.user_subs = ['/r/gnu'] (cb, ), _ = api.subs_changed.connect.call_args cb(api) assert not find_widget(poproot, label='/r/linux', many=True) assert find_widget(poproot, label='/r/gnu', many=True)
def test_subentry_palette_subreddits(): api = MagicMock() api.user_name = 'username' api.user_subs = ['/r/linux'] root = subentry.SubEntry(api) down_button = find_widget(root, kind=Gtk.Button) down_button.emit('clicked') poproot = root._palette # err IDK about this wait_for(lambda: poproot.props.visible) assert find_widget(poproot, label='/r/linux', many=True) assert not find_widget(poproot, label='/r/gnu', many=True) api.user_subs = ['/r/gnu'] (cb,), _ = api.subs_changed.connect.call_args cb(api) assert not find_widget(poproot, label='/r/linux', many=True) assert find_widget(poproot, label='/r/gnu', many=True)
def test_subentry_open_uri(): api = MagicMock() api.user_name = 'username' root = subentry.SubEntry(api) toplevel = MagicMock() entry = find_widget(root, kind=Gtk.Entry) # err IDK about this entry.is_focus = lambda: True entry.props.text = 'https://reddit.com/r/yes' poproot = root._palette # err IDK about this poproot.get_toplevel = lambda: toplevel wait_for(lambda: poproot.props.visible) btn = find_widget(poproot, label='Open this reddit.com URI', kind=Gtk.Button) btn.emit('clicked') wait_for(lambda: toplevel.goto_reddit_uri.called) toplevel.goto_reddit_uri.assert_called_once_with( 'https://reddit.com/r/yes')
def test_subentry_open_uri(): api = MagicMock() api.user_name = 'username' root = subentry.SubEntry(api) toplevel = MagicMock() entry = find_widget(root, kind=Gtk.Entry) # err IDK about this entry.is_focus = lambda: True entry.props.text = 'https://reddit.com/r/yes' poproot = root._palette # err IDK about this poproot.get_toplevel = lambda: toplevel wait_for(lambda: poproot.props.visible) btn = find_widget(poproot, label='Open this reddit.com URI', kind=Gtk.Button) btn.emit('clicked') wait_for(lambda: toplevel.goto_reddit_uri.called) toplevel.goto_reddit_uri.assert_called_once_with( 'https://reddit.com/r/yes')
def test_submit_self(): api = MagicMock() window = submit.SubmitWindow(api) root = window.window self_post = find_widget(root, kind=Gtk.Button, label='Self Post') self_post.props.active = True stack = find_widget(root, kind=Gtk.Stack) wait_for(lambda: stack.props.visible_child_name == 'self') find_widget(root, placeholder='Title').props.text = 'Some Title' find_widget(root, kind=Gtk.TextView).props.buffer.set_text('self') find_widget(root, placeholder='Subreddit').props.text = 'test' find_widget(root, label='Submit', kind=Gtk.Button).emit('clicked') wait_for(lambda: api.submit.called) (data, cb), _ = api.submit.call_args assert data == { 'kind': 'self', 'sr': 'test', 'title': 'Some Title', 'text': 'self', }
def test_submit_self(): api = MagicMock() window = submit.SubmitWindow(api) root = window.window self_post = find_widget(root, kind=Gtk.Button, label='Self Post') self_post.props.active = True stack = find_widget(root, kind=Gtk.Stack) wait_for(lambda: stack.props.visible_child_name == 'self') find_widget(root, placeholder='Title').props.text = 'Some Title' find_widget(root, kind=Gtk.TextView).props.buffer.set_text('self') find_widget(root, placeholder='Subreddit').props.text = 'test' find_widget(root, label='Submit', kind=Gtk.Button).emit('clicked') wait_for(lambda: api.submit.called) (data, cb), _ = api.submit.call_args assert data == { 'kind': 'self', 'sr': 'test', 'title': 'Some Title', 'text': 'self', }
def test_popover_selects_row(): ic = MagicMock() ic.all_tokens = [(1, MagicMock(user_name='user name 1')), (2, MagicMock(user_name='user name 2'))] ic.active_token = ic.all_tokens[0][1] popover = identitybutton._IdentityPopover(ic) def get_row(text: str): label = find_widget(popover, label=text) while not isinstance(label, Gtk.ListBoxRow): assert label label = label.get_parent() return label row1 = get_row('user name 1') row2 = get_row('user name 2') listbox = find_widget(popover, kind=Gtk.ListBox) assert listbox.get_selected_rows() == [row1] listbox.emit('row-selected', row2) wait_for(lambda: ic.switch_account.called) assert ic.switch_account.call_args[0][0] == 2
def test_popover_selects_row(): ic = MagicMock() ic.all_tokens = [ (1, MagicMock(user_name='user name 1')), (2, MagicMock(user_name='user name 2'))] ic.active_token = ic.all_tokens[0][1] popover = identitybutton._IdentityPopover(ic) def get_row(text: str): label = find_widget(popover, label=text) while not isinstance(label, Gtk.ListBoxRow): assert label label = label.get_parent() return label row1 = get_row('user name 1') row2 = get_row('user name 2') listbox = find_widget(popover, kind=Gtk.ListBox) assert listbox.get_selected_rows() == [row1] listbox.emit('row-selected', row2) wait_for(lambda: ic.switch_account.called) assert ic.switch_account.call_args[0][0] == 2
def test_emptyview_with_action(): root = emptyview.EmptyView('yo', action='do') root.action = MagicMock() find_widget(root, label='do', kind=Gtk.Button).emit('clicked') wait_for(lambda: root.action.emit.called)