-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7678 from readthedocs/delete-external-after-x-days
External versions: delete after 3 months of being merged/closed
- Loading branch information
Showing
14 changed files
with
195 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from django.test import TestCase | ||
from django_dynamic_fixture import get | ||
|
||
from readthedocs.builds.constants import BRANCH, EXTERNAL, TAG | ||
from readthedocs.builds.models import Version | ||
from readthedocs.builds.tasks import delete_inactive_external_versions | ||
from readthedocs.projects.models import Project | ||
|
||
|
||
class TestTasks(TestCase): | ||
|
||
def test_delete_inactive_external_versions(self): | ||
project = get(Project) | ||
project.versions.all().delete() | ||
get( | ||
Version, | ||
project=project, | ||
slug='branch', | ||
type=BRANCH, | ||
active=False, | ||
modified=datetime.now() - timedelta(days=7), | ||
) | ||
get( | ||
Version, | ||
project=project, | ||
slug='tag', | ||
type=TAG, | ||
active=True, | ||
modified=datetime.now() - timedelta(days=7), | ||
) | ||
get( | ||
Version, | ||
project=project, | ||
slug='external-active', | ||
type=EXTERNAL, | ||
active=True, | ||
modified=datetime.now() - timedelta(days=7), | ||
) | ||
get( | ||
Version, | ||
project=project, | ||
slug='external-inactive', | ||
type=EXTERNAL, | ||
active=False, | ||
modified=datetime.now() - timedelta(days=3), | ||
) | ||
get( | ||
Version, | ||
project=project, | ||
slug='external-inactive-old', | ||
type=EXTERNAL, | ||
active=False, | ||
modified=datetime.now() - timedelta(days=7), | ||
) | ||
|
||
self.assertEqual(Version.objects.all().count(), 5) | ||
self.assertEqual(Version.external.all().count(), 3) | ||
|
||
# We don't have inactive external versions from 9 days ago. | ||
delete_inactive_external_versions(days=9) | ||
self.assertEqual(Version.objects.all().count(), 5) | ||
self.assertEqual(Version.external.all().count(), 3) | ||
|
||
# We have one inactive external versions from 6 days ago. | ||
delete_inactive_external_versions(days=6) | ||
self.assertEqual(Version.objects.all().count(), 4) | ||
self.assertEqual(Version.external.all().count(), 2) | ||
self.assertFalse(Version.objects.filter(slug='external-inactive-old').exists()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.