Skip to content

Commit

Permalink
Merge branch 'update-testmon' of https://github.com/johnetordoff/osf.io
Browse files Browse the repository at this point in the history
… into fix-pip

# Conflicts:
#	.travis.yml
#	requirements/dev.txt
  • Loading branch information
John Tordoff committed Dec 28, 2020
2 parents f66d1ec + 2252890 commit eb66b68
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 205 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ script:
# Testmon will run for PRs, but will be disabled when merging into master or develop
- export TESTMON=`if [[ "$TRAVIS_PULL_REQUEST_BRANCH" == "" && "$TRAVIS_BRANCH" == "develop" || "$TRAVIS_PULL_REQUEST_BRANCH" == "" && "$TRAVIS_BRANCH" == "master" ]]; then echo ""; else echo "--testmon"; fi`
- export TESTMON_DATAFILE=$HOME/.cache/testmon/.testmondata_$TEST_BUILD
- rm $HOME/.cache/testmon/.testmondata_$TEST_BUILD
- invoke test_travis_$TEST_BUILD -n 1 $COVERAGE
- invoke test_travis_$TEST_BUILD -n 1 $COVERAGE $TESTMON

after_success:
- if [[ "$TRAVIS_BRANCH" == "master-w-coverage" ]]; then coveralls; fi
Expand Down
7 changes: 3 additions & 4 deletions api_tests/crossref/views/test_crossref_email_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def success_xml(self, preprint):
</doi_batch_diagnostic>
""".format(preprint._id, preprint._id)

@pytest.fixture()
def update_success_xml(self, preprint):
return """
<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -177,7 +176,7 @@ def test_success_response_sets_doi(self, app, url, preprint, success_xml):
assert preprint.get_identifier_value('doi')
assert preprint.preprint_doi_created

def test_update_success_response(self, app, preprint, url, update_success_xml):
def test_update_success_response(self, app, preprint, url):
initial_value = 'TempDOIValue'
preprint.set_identifier_value(category='doi', value=initial_value)
update_xml = self.update_success_xml(preprint)
Expand All @@ -189,7 +188,7 @@ def test_update_success_response(self, app, preprint, url, update_success_xml):
assert not mock_send_mail.called
assert preprint.get_identifier_value(category='doi') != initial_value

def test_update_success_does_not_set_preprint_doi_created(self, app, preprint, url, update_success_xml):
def test_update_success_does_not_set_preprint_doi_created(self, app, preprint, url):
preprint.set_identifier_value(category='doi', value='test')
preprint.preprint_doi_created = timezone.now()
preprint.save()
Expand All @@ -215,7 +214,7 @@ def test_success_batch_response(self, app, url):
for preprint in preprint_list:
assert preprint.get_identifier_value('doi') == settings.DOI_FORMAT.format(prefix=provider.doi_prefix, guid=preprint._id)

def test_confirmation_marks_legacy_doi_as_deleted(self, app, url, preprint, update_success_xml):
def test_confirmation_marks_legacy_doi_as_deleted(self, app, url, preprint):
legacy_value = 'IAmALegacyDOI'
preprint.set_identifier_value(category='legacy_doi', value=legacy_value)
update_xml = self.update_success_xml(preprint)
Expand Down
8 changes: 5 additions & 3 deletions api_tests/users/views/test_user_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class TestReviewActionFilters(ReviewActionFilterMixin):
def url(self):
return '/{}actions/reviews/'.format(API_BASE)

def get_expected_actions(self, all_actions, allowed_providers):
provider_ids = set([p.id for p in allowed_providers])
return [a for a in all_actions if a.target.provider_id in provider_ids]

@pytest.fixture()
def expected_actions(self, all_actions, allowed_providers):
actions = super(
TestReviewActionFilters, self
).expected_actions(all_actions, allowed_providers)
actions = self.get_expected_actions(all_actions, allowed_providers)
node = actions[0].target.node
node.is_public = False
node.save()
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _test_speedups():
def _test_speedups_disable(request, settings, _test_speedups):
patchers = []
for target, config in _MOCKS.items():
if not request.node.get_marker(config['mark']):
if not request.node.get_closest_marker(config['mark']):
continue
patchers.append(_test_speedups[target])
patchers[-1].stop()
Expand Down
1 change: 0 additions & 1 deletion osf_tests/management_commands/test_migrate_deleted_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def setUp(self):
super(TestMigrateDeletedDate, self).setUp()
self.region_us = RegionFactory(_id='US', name='United States')

@pytest.fixture()
def project(self, user, is_public=True, is_deleted=False, region=None, parent=None):
if region is None:
region = self.region_us
Expand Down
2 changes: 0 additions & 2 deletions osf_tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def add_file_version(file_to_version, user, size, version=1):
'contentType': 'img/png'
}).save()

@pytest.fixture()
def project(self, creator, is_public=True, is_deleted=False, region=None, parent=None):
if region is None:
region = self.region_us
Expand All @@ -66,7 +65,6 @@ def project(self, creator, is_public=True, is_deleted=False, region=None, parent

return project

@pytest.fixture()
def registration(self, project, creator, withdrawn=False):
schema = RegistrationSchema.objects.first()
draft_reg = DraftRegistrationFactory(branched_from=project)
Expand Down
2 changes: 0 additions & 2 deletions osf_tests/test_preprint_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ def preprint(preprint_provider):
return PreprintFactory._build(Preprint, provider=preprint_provider)


@pytest.fixture()
def right_before_my_birthday():
return {'run_date': datetime.datetime(year=1991, month=9, day=25, hour=23, minute=59, second=59, tzinfo=pytz.utc),
'preprint_date_created': datetime.datetime(year=1991, month=9, day=25, hour=22, minute=59, second=59, tzinfo=pytz.utc)
}

@pytest.fixture()
def my_birthday_at_midnight():
return {'run_date': datetime.datetime(year=1991, month=9, day=25, hour=0, tzinfo=pytz.utc),
'preprint_date_created': datetime.datetime(year=1991, month=9, day=24, hour=23, tzinfo=pytz.utc)
Expand Down
22 changes: 19 additions & 3 deletions osf_tests/test_registration_moderation_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@
from website.reviews import listeners


def get_moderator(provider):
user = AuthUserFactory()
provider.add_to_group(user, 'moderator')
return user


def get_daily_moderator(provider):
user = AuthUserFactory()
provider.add_to_group(user, 'moderator')
for subscription_type in provider.DEFAULT_SUBSCRIPTIONS:
subscription = provider.notification_subscriptions.get(event_name=subscription_type)
subscription.add_user_to_subscription(user, 'email_digest')
return user


# Set USE_EMAIL to true and mock out the default mailer for consistency with other mocked settings
@mock.patch('website.mails.settings.USE_EMAIL', True)
@mock.patch('website.mails.tasks.send_email', mock.MagicMock())
Expand Down Expand Up @@ -522,12 +537,13 @@ def test_withdrawal_registration_force_notifications(self, registration_with_ret

@pytest.mark.parametrize(
'digest_type, expected_recipient',
[('email_transactional', moderator), ('email_digest', daily_moderator)]
[('email_transactional', get_moderator), ('email_digest', get_daily_moderator)]
)
def test_submissions_and_withdrawals_both_appear_in_moderator_digest(self, digest_type, expected_recipient, registration, admin, provider):
# Invoke the fixture function to get the recipient because parametrize
expected_recipient = expected_recipient(self, provider)
notify_submit(registration, admin)
expected_recipient = expected_recipient(provider)
with mock.patch('website.reviews.listeners.mails.send_mail'):
notify_submit(registration, admin)
notify_moderator_registration_requests_withdrawal(registration, admin)

# One user, one provider => one email
Expand Down
4 changes: 2 additions & 2 deletions osf_tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,10 @@ def test_change_password_invalid(self, old_password=None, new_password=None, con
user = UserFactory()
user.set_password('password')
user.save()
with pytest.raises(ChangePasswordError) as excinfo:
with pytest.raises(ChangePasswordError, match=error_message):
user.change_password(old_password, new_password, confirm_password)
user.save()
assert error_message in str(excinfo)

assert bool(user.check_password(new_password)) is False

def test_change_password_invalid_old_password(self):
Expand Down
8 changes: 4 additions & 4 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Requirements that are used in the development environment only

# Testing
pytest==4.6.11
pytest==5.0.0
pytest-socket==0.3.5
pytest-xdist==1.15.0
pytest-django==3.10.0
pytest-cov==2.10.1
python-coveralls==2.9.3
pytest-testmon==0.9.16
pytest-cov==2.5.1
python-coveralls==2.9.1
pytest-testmon==1.0.3
nose
factory-boy==2.10.0
webtest-plus==0.3.3
Expand Down
15 changes: 1 addition & 14 deletions tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ def test_module(ctx, module=None, numprocesses=None, nocapture=False, params=Non
"""Helper for running tests.
"""
from past.builtins import basestring
from testmon.testmon_core import TestmonData
os.environ['DJANGO_SETTINGS_MODULE'] = 'osf_tests.settings'
import pytest
if not numprocesses:
Expand Down Expand Up @@ -322,19 +321,7 @@ def test_module(ctx, module=None, numprocesses=None, nocapture=False, params=Non
params = [params] if isinstance(params, basestring) else params
args.extend(params)

try:
retcode = pytest.main(args)
except sqlite3.OperationalError as e:
# Unsticks stuck travis caches that were stuck during migration.
if ' no such table' in str(e):
os.remove(os.environ.get('TESTMON_DATAFILE')) # set in .travis.yml, meant to rm pre-1.0.0 cached DB
TestmonData(os.environ.get('TESTMON_DATAFILE')).init_tables()
retcode = pytest.main(args)
elif 'already exists' in str(e):
os.remove(os.environ.get('TESTMON_DATAFILE')) # set in .travis.yml
retcode = pytest.main(args)
else:
raise e
retcode = pytest.main(args)

# exit code 5 is all tests skipped which is the same as passing with testmon
sys.exit(0 if retcode == NO_TESTS_COLLECTED else retcode)
Expand Down
12 changes: 7 additions & 5 deletions tests/identifiers/test_datacite.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
def override_doi_settings():
settings.DOI_FORMAT = '{prefix}/FK2osf.io/{guid}'


def datacite_metadata_response():
with open(os.path.join(FIXTURES, 'datacite_post_metadata_response.xml'), 'r') as fp:
return fp.read()


@pytest.fixture()
def datacite_client(registration):
class MockDataciteClient(object):
Expand All @@ -44,15 +50,11 @@ def __init__(self, *arg, **kwargs):
client=MockDataciteClient()
)


@pytest.fixture()
def registration():
return RegistrationFactory(is_public=True)

@pytest.fixture()
def datacite_metadata_response():
with open(os.path.join(FIXTURES, 'datacite_post_metadata_response.xml'), 'r') as fp:
return fp.read()


@pytest.mark.django_db
class TestDataCiteClient:
Expand Down
Loading

0 comments on commit eb66b68

Please sign in to comment.