def test_share_items(client, app): user_ids = app.data.insert('users', [{ 'email': '*****@*****.**', 'first_name': 'Foo', 'last_name': 'Bar', }]) with app.mail.record_messages() as outbox: resp = client.post('/wire_share?type=factcheck', data=json.dumps({ 'items': [item['_id'] for item in items], 'users': [str(user_ids[0])], 'message': 'Some info message', }), content_type='application/json') assert resp.status_code == 201, resp.get_data().decode('utf-8') assert len(outbox) == 1 assert outbox[0].recipients == ['*****@*****.**'] assert outbox[0].sender == 'newsroom@localhost' assert outbox[0].subject == 'From AAP Newsroom: %s' % items[0]['headline'] assert 'Hi Foo Bar' in outbox[0].body assert 'admin admin ([email protected]) shared ' in outbox[0].body assert items[0]['headline'] in outbox[0].body assert items[1]['headline'] in outbox[0].body assert 'http://localhost:5050/factcheck?item=%s' % parse.quote(items[0]['_id']) in outbox[0].body assert 'http://localhost:5050/factcheck?item=%s' % parse.quote(items[1]['_id']) in outbox[0].body assert 'Some info message' in outbox[0].body resp = client.get('/factcheck/{}?format=json'.format(items[0]['_id'])) data = json.loads(resp.get_data()) assert 'shares' in data user_id = get_admin_user_id(app) assert str(user_id) in data['shares']
def test_item_copy(client, app): resp = client.post('/aapX/{}/copy'.format(items[0]['_id']), content_type='application/json') assert resp.status_code == 200 resp = client.get('/aapX/tag:foo?format=json') data = json.loads(resp.get_data()) assert 'copies' in data user_id = get_admin_user_id(app) assert str(user_id) in data['copies']
def test_bookmarks(client, app): user_id = get_admin_user_id(app) assert user_id assert 0 == get_bookmarks_count(client, user_id) resp = client.post('/factcheck_bookmark', data=json.dumps({ 'items': [items[0]['_id']], }), content_type='application/json') assert resp.status_code == 200 assert 1 == get_bookmarks_count(client, user_id) client.delete('/factcheck_bookmark', data=json.dumps({ 'items': [items[0]['_id']], }), content_type='application/json') assert resp.status_code == 200 assert 0 == get_bookmarks_count(client, user_id)