Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken test build #1191

Open
wants to merge 1 commit into
base: lockhart
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/tests-py38.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ jobs:
python-version: 3.8

- name: docker-compose
run: docker-compose -f .actions-docker-compose.yml up -d
run: docker compose -f .actions-docker-compose.yml up -d

- run: |
sudo apt-get update
sudo apt-get install pkg-config libxml2-dev libxmlsec1-dev libxmlsec1-openssl

- name: cache pip
uses: actions/cache@v2
Expand All @@ -30,7 +34,7 @@ jobs:

- name: pip install
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install --upgrade pip==24.0 wheel setuptools
pip install -r dev-requirements.txt

- name: flake8
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: 3.6

- name: docker-compose
run: docker-compose -f .actions-docker-compose.yml up -d
run: docker compose -f .actions-docker-compose.yml up -d

- run: |
sudo apt-get update
Expand Down Expand Up @@ -76,4 +76,4 @@ jobs:
run: npm run test

- name: build
run: npm run build
run: npm run build
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flake8
sphinx
sphinx-autobuild
pytest==3.10.0
pytest==7.0.0
pytest-cov==2.6.1
pytest-mock==1.10.1
responses>=0.10.6,<0.11
Expand Down
2 changes: 1 addition & 1 deletion features/news_api_auth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Feature: News API Authorization
"product_type": "news_api"
}]
"""
When we set header "X-Forwarded-For" to value "123.123.123.001, 192.192.192.192"
When we set header "X-Forwarded-For" to value "123.123.123.1, 192.192.192.192"
When we get "news/search?q=fish&include_fields=body_html"
Then we get list with 1 items
"""
Expand Down
22 changes: 22 additions & 0 deletions tests/test_agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .utils import post_json, delete_json, get_json, get_admin_user_id, mock_send_email
from copy import deepcopy
from bson import ObjectId
from pytest import fixture

date_time_format = '%Y-%m-%dT%H:%M:%S'

Expand Down Expand Up @@ -79,13 +80,15 @@ def mock_utcnow():
return datetime.strptime('2018-11-23T22:00:00', date_time_format)


@fixture
def test_item_detail(client):
resp = client.get('/agenda/urn:conference')
assert resp.status_code == 200
assert 'urn:conference' in resp.get_data().decode()
assert 'Conference Planning' in resp.get_data().decode()


@fixture
def test_item_json(client):
resp = client.get('/agenda/urn:conference?format=json')
data = json.loads(resp.get_data())
Expand All @@ -96,6 +99,7 @@ def test_item_json(client):
assert 'internal_note' in data['coverages'][0]['planning']


@fixture
def test_item_json_does_not_return_files(client, app):
# public user
with client.session_transaction() as session:
Expand All @@ -110,13 +114,15 @@ def test_item_json_does_not_return_files(client, app):
assert 'internal_note' not in data['coverages'][0]['planning']


@fixture
def get_bookmarks_count(client, user):
resp = client.get('/agenda/search?bookmarks=%s' % str(user))
assert resp.status_code == 200
data = json.loads(resp.get_data())
return data['_meta']['total']


@fixture
def test_bookmarks(client, app):
user_id = get_admin_user_id(app)
assert user_id
Expand All @@ -138,6 +144,7 @@ def test_bookmarks(client, app):
assert 0 == get_bookmarks_count(client, user_id)


@fixture
def test_item_copy(client, app):
resp = client.post('/wire/{}/copy?type=agenda'.format('urn:conference'), content_type='application/json')
assert resp.status_code == 200
Expand All @@ -150,6 +157,7 @@ def test_item_copy(client, app):
assert str(user_id) in data['copies']


@fixture
@mock.patch('newsroom.wire.views.send_email', mock_send_email)
def test_share_items(client, app, mocker):
user_ids = app.data.insert('users', [{
Expand Down Expand Up @@ -183,6 +191,7 @@ def test_share_items(client, app, mocker):
assert str(user_id) in data['shares']


@fixture
def test_agenda_search_filtered_by_query_product(client, app):
app.data.insert('navigations', [{
'_id': 51,
Expand Down Expand Up @@ -233,6 +242,7 @@ def test_agenda_search_filtered_by_query_product(client, app):
assert '_aggregations' in data


@fixture
@mock.patch('newsroom.agenda.email.send_email', mock_send_email)
def test_coverage_request(client, app):
post_json(client, '/settings/general_settings', {'coverage_request_recipients': '[email protected]'})
Expand All @@ -252,6 +262,7 @@ def test_coverage_request(client, app):
assert 'Some info message' in outbox[0].body


@fixture
def test_watch_event(client, app):
user_id = get_admin_user_id(app)
assert 0 == get_bookmarks_count(client, user_id)
Expand All @@ -263,6 +274,7 @@ def test_watch_event(client, app):
assert 0 == get_bookmarks_count(client, user_id)


@fixture
def test_watch_coverages(client, app):
user_id = get_admin_user_id(app)

Expand All @@ -275,6 +287,7 @@ def test_watch_coverages(client, app):
assert after_watch_item['coverages'][0]['watches'] == [user_id]


@fixture
def test_unwatch_coverages(client, app):
user_id = get_admin_user_id(app)

Expand All @@ -295,6 +308,7 @@ def test_unwatch_coverages(client, app):
assert after_watch_item['coverages'][0]['watches'] == []


@fixture
def test_remove_watch_coverages_on_watch_item(client, app):
user_id = ObjectId(get_admin_user_id(app))
other_user_id = PUBLIC_USER_ID
Expand All @@ -318,6 +332,7 @@ def test_remove_watch_coverages_on_watch_item(client, app):
assert after_watch_item['watches'] == [user_id]


@fixture
def test_fail_watch_coverages(client, app):
user_id = get_admin_user_id(app)

Expand All @@ -344,6 +359,7 @@ def test_fail_watch_coverages(client, app):
assert resp.status_code == 403


@fixture
@mock.patch('newsroom.utils.get_utcnow', mock_utcnow)
def test_local_time(client, app, mocker):
# 9 am Sydney Time - day light saving on
Expand Down Expand Up @@ -372,6 +388,7 @@ def test_local_time(client, app, mocker):
assert '2018-12-23T12:59:59' == end_date.strftime(date_time_format)


@fixture
def test_get_location_string():
agenda = {}
assert get_location_string(agenda) == ''
Expand Down Expand Up @@ -402,6 +419,7 @@ def test_get_location_string():
assert get_location_string(agenda) == 'Sydney Opera House, 2 Macquarie Street, Sydney, Sydney, 2000, Australia'


@fixture
def test_get_public_contacts():
agenda = {}
assert get_public_contacts(agenda) == []
Expand Down Expand Up @@ -436,6 +454,7 @@ def test_get_public_contacts():
}]


@fixture
def test_get_agenda_dates():
agenda = {
'dates': {
Expand Down Expand Up @@ -470,6 +489,7 @@ def test_get_agenda_dates():
assert get_agenda_dates(agenda) == '08:00 30/05/2018'


@fixture
def test_filter_agenda_by_coverage_status(client):
client.post('/push', data=json.dumps(test_planning), content_type='application/json')

Expand Down Expand Up @@ -497,6 +517,7 @@ def test_filter_agenda_by_coverage_status(client):
assert 'urn:conference' == data['_items'][2]['_id']


@fixture
def test_filter_events_only(client):
test_planning = {
"description_text": "description here",
Expand Down Expand Up @@ -572,6 +593,7 @@ def test_filter_events_only(client):
assert 'coverages' not in data['_items'][0]


@fixture
def test_related_wire_items(client, app):
test_planning_with_coveragre = deepcopy(test_planning)
test_planning_with_coveragre["coverages"] = [
Expand Down
7 changes: 7 additions & 0 deletions tests/test_agenda_events_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def set_products(app):
}])


@fixture
def test_item_json(client):
# public user
with client.session_transaction() as session:
Expand All @@ -67,6 +68,7 @@ def test_item_json(client):
assert 'coverages' not in data


@fixture
def test_search(client, app):
# public user
set_products(app)
Expand Down Expand Up @@ -114,6 +116,7 @@ def set_watch_products(app):
}])


@fixture
@mock.patch('newsroom.agenda.email.send_email', mock_send_email)
def test_watched_event_sends_notification_for_event_update(client, app, mocker):
event = deepcopy(test_event)
Expand Down Expand Up @@ -148,6 +151,7 @@ def test_watched_event_sends_notification_for_event_update(client, app, mocker):
assert notifications[0]['_id'] == '{}_foo'.format(PUBLIC_USER_ID)


@fixture
@mock.patch('newsroom.agenda.email.send_email', mock_send_email)
def test_watched_event_sends_notification_for_unpost_event(client, app, mocker):
event = deepcopy(test_event)
Expand Down Expand Up @@ -178,6 +182,7 @@ def test_watched_event_sends_notification_for_unpost_event(client, app, mocker):
assert notifications[0]['_id'] == '{}_foo'.format(PUBLIC_USER_ID)


@fixture
@mock.patch('newsroom.email.send_email', mock_send_email)
def test_watched_event_sends_notification_for_added_planning(client, app, mocker):
event = deepcopy(test_event)
Expand Down Expand Up @@ -205,6 +210,7 @@ def test_watched_event_sends_notification_for_added_planning(client, app, mocker
assert len(push_mock.call_args[1]['users']) == 0


@fixture
@mock.patch('newsroom.email.send_email', mock_send_email)
def test_watched_event_sends_notification_for_cancelled_planning(client, app, mocker):
event = deepcopy(test_event)
Expand Down Expand Up @@ -235,6 +241,7 @@ def test_watched_event_sends_notification_for_cancelled_planning(client, app, mo
assert len(push_mock.call_args[1]['users']) == 0


@fixture
@mock.patch('newsroom.email.send_email', mock_send_email)
def test_watched_event_sends_notification_for_added_coverage(client, app, mocker):
event = deepcopy(test_event)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from time import sleep
from datetime import datetime, timedelta
from eve.utils import ParsedRequest
from pytest import fixture

from newsroom.mongo_utils import index_elastic_from_mongo, index_elastic_from_mongo_from_timestamp

Expand All @@ -15,6 +16,7 @@ def remove_elastic_index(app):
es.indices.delete(indices, ignore=[404])


@fixture
def test_item_detail(app, client):
remove_elastic_index(app)
app.data.init_elastic(app)
Expand All @@ -38,6 +40,7 @@ def test_item_detail(app, client):
assert 3 == len(data['_items'])


@fixture
def test_index_from_mongo_hours_from(app, client):
remove_elastic_index(app)
app.data.init_elastic(app)
Expand All @@ -56,6 +59,7 @@ def test_index_from_mongo_hours_from(app, client):
assert 1 == len(data['_items'])


@fixture
def test_index_from_mongo_collection(app, client):
remove_elastic_index(app)
app.data.init_elastic(app)
Expand All @@ -74,6 +78,7 @@ def test_index_from_mongo_collection(app, client):
assert 3 == len(data['_items'])


@fixture
def test_index_from_mongo_from_timestamp(app, client):
app.data.remove('items')
sorted_items = [{
Expand Down
2 changes: 2 additions & 0 deletions tests/test_company_expiry_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from superdesk import get_resource_service
from .fixtures import items, init_items, init_auth # noqa
from unittest import mock
from pytest import fixture


@fixture
@mock.patch('newsroom.email.send_email', mock_send_email)
def test_company_expiry_alerts(client, app):
now = utcnow()
Expand Down
5 changes: 5 additions & 0 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .fixtures import items, init_items, init_auth, agenda_items, init_agenda_items # noqa
from .test_push import upload_binary
from pytest import fixture

items_ids = [item['_id'] for item in items[:2]]
item = items[:2][0]
Expand Down Expand Up @@ -254,6 +255,7 @@ def setup_embeds(client, app):
'<p>Par 4</p>'}, item)


@fixture
def test_download_single(client, app):
setup_image(client, app)
for _format in wire_formats:
Expand All @@ -264,6 +266,7 @@ def test_download_single(client, app):
'attachment; filename="%s"' % _format['filename']]


@fixture
def test_wire_download(client, app):
setup_image(client, app)
for _format in wire_formats:
Expand All @@ -284,6 +287,7 @@ def test_wire_download(client, app):
assert history[0].get('section') == 'wire'


@fixture
def test_ninjs_download(client, app):
setup_embeds(client, app)
app.config['EMBED_PRODUCT_FILTERING'] = True
Expand Down Expand Up @@ -323,6 +327,7 @@ def test_ninjs_download(client, app):
assert history[0].get('section') == 'wire'


@fixture
def test_agenda_download(client, app):
setup_image(client, app)
for _format in agenda_formats:
Expand Down
Loading
Loading