Skip to content
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
28 changes: 28 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,31 @@ jobs:
- name: Upload report
if: (github.event_name != 'pull_request') && (success() || failure()) # run this step even if previous step failed
uses: ./.github/actions/gen-report

scripts:
runs-on: ubuntu-22.04
permissions:
checks: write
needs: build-cache
services:
postgres:
image: postgres

env:
POSTGRES_PASSWORD: ${{ env.OSF_DB_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/start-build
- name: Run tests
run: poetry run python3 -m invoke test-ci-scripts -n 1 --junit
- name: Upload report
if: (github.event_name != 'pull_request') && (success() || failure()) # run this step even if previous step failed
uses: ./.github/actions/gen-report
3 changes: 0 additions & 3 deletions scripts/normalize_user_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

CAMPAIGN_SOURCE_TAGS = [
('erp_challenge_campaign', CampaignSourceTags.ErpChallenge.value),
('prereg_challenge_campaign', CampaignSourceTags.PreregChallenge.value),
('osf_registered_reports', CampaignSourceTags.OsfRegisteredReports.value),
('osf4m', CampaignSourceTags.Osf4m.value),
]
Expand Down Expand Up @@ -82,8 +81,6 @@

CAMPAIGN_CLAIMED_TAGS = [
CampaignClaimedTags.ErpChallenge.value,
CampaignClaimedTags.PreregChallenge.value,
CampaignClaimedTags.Prereg.value,
CampaignClaimedTags.OsfRegisteredReports.value,
CampaignClaimedTags.Osf4m.value,
]
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/test_add_preprint_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


from tests.base import OsfTestCase
from website.models import PreprintProvider
from osf.models import PreprintProvider
from scripts.update_taxonomies import main as taxonomy_main
from scripts.populate_preprint_providers import main as populate_main
from scripts.populate_preprint_providers import STAGING_PREPRINT_PROVIDERS, PROD_PREPRINT_PROVIDERS
Expand Down
2 changes: 2 additions & 0 deletions scripts/tests/test_approve_embargo_terminations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest import mock
from datetime import timedelta
import pytest

from django.utils import timezone

Expand Down Expand Up @@ -56,6 +57,7 @@ def test_get_pending_embargo_termination_requests_returns_only_unapproved(self):
assert targets.count() == 1
assert targets.first()._id == self.registration2.embargo_termination_approval._id

@pytest.mark.usefixtures('mock_gravy_valet_get_verified_links')
def test_main_auto_approves_embargo_termination_request(self):
for node in self.registration2.node_and_primary_descendants():
assert not node.is_public
Expand Down
4 changes: 3 additions & 1 deletion scripts/tests/test_embargo_registrations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import timedelta

import pytest
from django.utils import timezone

from tests.base import OsfTestCase
Expand Down Expand Up @@ -65,6 +65,7 @@ def test_should_activate_pending_embargo_more_than_48_hours_old(self):
assert not self.registration.is_pending_embargo
assert self.registration.embargo_end_date

@pytest.mark.usefixtures('mock_gravy_valet_get_verified_links')
def test_embargo_past_end_date_should_be_completed(self):
self.registration.embargo.accept()
assert self.registration.embargo_end_date
Expand Down Expand Up @@ -110,6 +111,7 @@ def test_embargo_approval_adds_to_parent_projects_log(self):
action=NodeLog.EMBARGO_APPROVED
).exists()

@pytest.mark.usefixtures('mock_gravy_valet_get_verified_links')
def test_embargo_completion_adds_to_parent_projects_log(self):
assert not self.registration.registered_from.logs.filter(
action=NodeLog.EMBARGO_COMPLETED
Expand Down
13 changes: 9 additions & 4 deletions scripts/tests/test_find_spammy_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)

from scripts.find_spammy_content import manage_spammy_content
from tests.utils import capture_notifications


@pytest.mark.django_db
Expand Down Expand Up @@ -85,7 +86,8 @@ def test_get_recent_spam(self, kombat_node, spam_node_but_old):
assert spam_node_but_old not in spam_guids

def test_ban_all_node_spam(self, user, user_two, kombat_node, node_two):
manage_spammy_content('Kombat', models=[Node, ], ban=True)
with capture_notifications():
manage_spammy_content('Kombat', models=[Node, ], ban=True)
user.reload()
kombat_node.reload()
node_two.reload()
Expand All @@ -96,7 +98,8 @@ def test_ban_all_node_spam(self, user, user_two, kombat_node, node_two):
assert not user_two.is_disabled

def test_ban_all_preprint_spam(self, user, user_two, kombat_preprint, preprint_two):
manage_spammy_content('Kombat', models=[Preprint, ], ban=True)
with capture_notifications():
manage_spammy_content('Kombat', models=[Preprint, ], ban=True)
kombat_preprint.reload()
preprint_two.reload()
user.reload()
Expand All @@ -107,7 +110,8 @@ def test_ban_all_preprint_spam(self, user, user_two, kombat_preprint, preprint_t
assert not user_two.is_disabled

def test_ban_all_registration_spam(self, user, user_two, kombat_registration, registration_two):
manage_spammy_content('Kombat', models=[Registration, ], ban=True)
with capture_notifications():
manage_spammy_content('Kombat', models=[Registration, ], ban=True)
user.reload()
user_two.reload()
kombat_registration.reload()
Expand All @@ -118,7 +122,8 @@ def test_ban_all_registration_spam(self, user, user_two, kombat_registration, re
assert not user_two.is_disabled

def test_ban_recent_spam(self, kombat_node, spam_node_but_old, user, user_two):
manage_spammy_content('Kombat', models=[Node, ], ban=True)
with capture_notifications():
manage_spammy_content('Kombat', models=[Node, ], ban=True)
kombat_node.reload()
spam_node_but_old.reload()
user.reload()
Expand Down
71 changes: 0 additions & 71 deletions scripts/tests/test_fix_draft_node_permissions.py

This file was deleted.

1 change: 1 addition & 0 deletions scripts/tests/test_fix_registration_unclaimed_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def registration(self, project, contributor_unregistered, contributor_unregister
with mock_archive(project, autoapprove=True) as registration:
return registration

@pytest.mark.usefixtures('mock_gravy_valet_get_verified_links')
def test_migrate_bad_data(self, user, project, registration, contributor_unregistered, contributor_unregistered_no_email):
contributor_unregistered.refresh_from_db()
contributor_unregistered_no_email.refresh_from_db()
Expand Down
77 changes: 0 additions & 77 deletions scripts/tests/test_fix_unmerged_preprints.py

This file was deleted.

26 changes: 13 additions & 13 deletions scripts/tests/test_refresh_addon_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from dateutil.relativedelta import relativedelta

from website.oauth.models import ExternalAccount
from osf.models import ExternalAccount

from scripts.refresh_addon_tokens import (
get_targets, main, look_up_provider, PROVIDER_CLASSES
Expand All @@ -38,12 +38,12 @@ def test_look_up_provider(self):
def test_get_targets(self):
now = timezone.now()
records = [
BoxAccountFactory(date_last_refreshed=now - datetime.timedelta(days=4)),
BoxAccountFactory(date_last_refreshed=now - datetime.timedelta(days=2)),
GoogleDriveAccountFactory(date_last_refreshed=now - datetime.timedelta(days=4)),
GoogleDriveAccountFactory(date_last_refreshed=now - datetime.timedelta(days=2)),
MendeleyAccountFactory(date_last_refreshed=now - datetime.timedelta(days=4)),
MendeleyAccountFactory(date_last_refreshed=now - datetime.timedelta(days=2)),
BoxAccountFactory(expires_at=now - datetime.timedelta(days=4), date_last_refreshed=now - datetime.timedelta(days=4)),
BoxAccountFactory(expires_at=now - datetime.timedelta(days=2), date_last_refreshed=now - datetime.timedelta(days=2)),
GoogleDriveAccountFactory(expires_at=now - datetime.timedelta(days=4), date_last_refreshed=now - datetime.timedelta(days=4)),
GoogleDriveAccountFactory(expires_at=now - datetime.timedelta(days=2), date_last_refreshed=now - datetime.timedelta(days=2)),
MendeleyAccountFactory(expires_at=now - datetime.timedelta(days=4), date_last_refreshed=now - datetime.timedelta(days=4)),
MendeleyAccountFactory(expires_at=now - datetime.timedelta(days=2), date_last_refreshed=now - datetime.timedelta(days=2)),
]
box_targets = list(get_targets(delta=relativedelta(days=3), addon_short_name='box'))
drive_targets = list(get_targets(delta=relativedelta(days=3), addon_short_name='googledrive'))
Expand All @@ -59,12 +59,12 @@ def test_get_targets(self):
@mock.patch('scripts.refresh_addon_tokens.GoogleDriveProvider.refresh_oauth_key')
@mock.patch('scripts.refresh_addon_tokens.Box.refresh_oauth_key')
def test_refresh(self, mock_box_refresh, mock_drive_refresh, mock_mendeley_refresh):
fake_authorized_box_account = BoxAccountFactory(date_last_refreshed=timezone.now())
fake_authorized_drive_account = GoogleDriveAccountFactory(date_last_refreshed=timezone.now())
fake_authorized_mendeley_account = MendeleyAccountFactory(date_last_refreshed=timezone.now())
fake_unauthorized_box_account = BoxAccountFactory(date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
fake_unauthorized_drive_account = GoogleDriveAccountFactory(date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
fake_unauthorized_mendeley_account = MendeleyAccountFactory(date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
fake_authorized_box_account = BoxAccountFactory(expires_at=timezone.now(), date_last_refreshed=timezone.now())
fake_authorized_drive_account = GoogleDriveAccountFactory(expires_at=timezone.now(), date_last_refreshed=timezone.now())
fake_authorized_mendeley_account = MendeleyAccountFactory(expires_at=timezone.now(), date_last_refreshed=timezone.now())
fake_unauthorized_box_account = BoxAccountFactory(expires_at=timezone.now() - datetime.timedelta(days=4), date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
fake_unauthorized_drive_account = GoogleDriveAccountFactory(expires_at=timezone.now() - datetime.timedelta(days=4), date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
fake_unauthorized_mendeley_account = MendeleyAccountFactory(expires_at=timezone.now() - datetime.timedelta(days=4), date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
for addon in self.addons:
Provider = look_up_provider(addon)
main(delta=relativedelta(days=3), Provider=Provider, rate_limit=(5, 1), dry_run=False)
Expand Down
Loading
Loading