forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes: pulp#351
- Loading branch information
Showing
8 changed files
with
152 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Added ``last_serial`` sync optimization to Python repositories. | ||
Subsequent syncs will use ``last_serial`` to get the changed packages since the previous sync. |
18 changes: 18 additions & 0 deletions
18
pulp_python/app/migrations/0011_pythonrepository_last_serial.py
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,18 @@ | ||
# Generated by Django 3.2.8 on 2021-10-21 20:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('python', '0010_update_json_field'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='pythonrepository', | ||
name='last_serial', | ||
field=models.IntegerField(default=0), | ||
), | ||
] |
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
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 |
---|---|---|
@@ -1,9 +1,53 @@ | ||
from django.test import TestCase | ||
|
||
from pulp_python.app.models import PythonRemote, PythonRepository | ||
from pulp_python.app.tasks import update_remote | ||
|
||
|
||
DEFAULT_SERIAL = 10000 | ||
MAX_SERIAL = 20000 | ||
|
||
|
||
class TestNothing(TestCase): | ||
"""Test Nothing (placeholder).""" | ||
|
||
def test_nothing_at_all(self): | ||
"""Test that the tests are running and that's it.""" | ||
self.assertTrue(True) | ||
|
||
|
||
class TestRepositoryLastSerial(TestCase): | ||
"""Tests `last_serial` gets properly set and reset with syncs and remote changes.""" | ||
|
||
def setUp(self): | ||
self.remote = PythonRemote.objects.create(name="test", url="https://pypi.org") | ||
self.repo = PythonRepository.objects.create(name="test", remote=self.remote, last_serial=DEFAULT_SERIAL) | ||
|
||
def test_remote_change(self): | ||
"""Test that `last_serial` gets reset upon remote change.""" | ||
self.assertEqual(self.repo.remote.pk, self.remote.pk) | ||
self.assertEqual(self.repo.last_serial, DEFAULT_SERIAL) | ||
self.repo.remote = None | ||
self.repo.save() | ||
self.repo.refresh_from_db() | ||
self.assertEqual(self.repo.last_serial, 0) | ||
|
||
def test_remote_update(self): | ||
"""Test that updating a remote will reset `last_serial`.""" | ||
self.assertEqual(self.repo.remote.pk, self.remote.pk) | ||
self.assertEqual(self.repo.last_serial, DEFAULT_SERIAL) | ||
# Remote is only updated through update task | ||
new_body = {"url": "https://test.pypi.org"} | ||
update_remote(self.remote.pk, data=new_body, partial=True) | ||
self.repo.refresh_from_db() | ||
self.assertEqual(self.repo.last_serial, 0) | ||
|
||
def test_remote_update_no_change(self): | ||
"""Test that changing 'includes' field doesn't reset `last_serial`.""" | ||
self.assertEqual(self.repo.remote.pk, self.remote.pk) | ||
self.assertEqual(self.repo.last_serial, DEFAULT_SERIAL) | ||
new_body = {"includes": ["shelf-reader"]} | ||
update_remote(self.remote.pk, data=new_body, partial=True) | ||
self.repo.refresh_from_db() | ||
self.assertEqual(self.repo.last_serial, DEFAULT_SERIAL) | ||
|