Skip to content

Commit 3eb530c

Browse files
deckobmbouter
authored andcommitted
Fixes a sync operation demanding the remote URL when the repository already have one.
Closes #275
1 parent eb3c60c commit 3eb530c

File tree

3 files changed

+33
-52
lines changed

3 files changed

+33
-52
lines changed

CHANGES/275.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes a sync operation demanding the remote URL when the repository already have one.

pulp_npm/app/viewsets.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create(self, request):
5858
"""
5959
Perform bookkeeping when saving Content.
6060
61-
"Artifacts" need to be popped off and saved indpendently, as they are not actually part
61+
"Artifacts" need to be popped off and saved independently, as they are not actually part
6262
of the Content model.
6363
"""
6464
raise NotImplementedError("FIXME")
@@ -146,9 +146,11 @@ def sync(self, request, pk):
146146
Dispatches a sync task.
147147
"""
148148
repository = self.get_object()
149-
serializer = RepositorySyncURLSerializer(data=request.data, context={"request": request})
149+
serializer = RepositorySyncURLSerializer(
150+
data=request.data, context={"request": request, "repository_pk": pk}
151+
)
150152
serializer.is_valid(raise_exception=True)
151-
remote = serializer.validated_data.get("remote")
153+
remote = serializer.validated_data.get("remote", repository.remote)
152154

153155
result = dispatch(
154156
tasks.synchronize,

pulp_npm/tests/functional/api/test_sync.py

+27-49
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# coding=utf-8
22
"""Tests that sync npm plugin repositories."""
3+
import pytest
34
import unittest
5+
import uuid
6+
7+
from pulpcore.client.pulp_npm import RepositorySyncURL
48

59
from pulp_smash import api, cli, config
610
from pulp_smash.exceptions import TaskReportError
711
from pulp_smash.pulp3.constants import MEDIA_PATH
812
from pulp_smash.pulp3.utils import (
913
gen_repo,
10-
get_added_content_summary,
11-
get_content_summary,
1214
sync,
1315
)
1416

1517
from pulp_npm.tests.functional.constants import (
16-
NPM_FIXTURE_SUMMARY,
1718
NPM_INVALID_FIXTURE_URL,
1819
NPM_REMOTE_PATH,
1920
NPM_REPO_PATH,
2021
)
2122
from pulp_npm.tests.functional.utils import gen_npm_remote
22-
from pulp_npm.tests.functional.utils import set_up_module as setUpModule # noqa:F401
2323

2424

2525
class BasicSyncTestCase(unittest.TestCase):
@@ -31,50 +31,6 @@ def setUpClass(cls):
3131
cls.cfg = config.get_config()
3232
cls.client = api.Client(cls.cfg, api.json_handler)
3333

34-
def test_sync(self):
35-
"""Sync repositories with the npm plugin.
36-
37-
In order to sync a repository a remote has to be associated within
38-
this repository. When a repository is created this version field is set
39-
as None. After a sync the repository version is updated.
40-
41-
Do the following:
42-
43-
1. Create a repository, and a remote.
44-
2. Assert that repository version is None.
45-
3. Sync the remote.
46-
4. Assert that repository version is not None.
47-
5. Assert that the correct number of units were added and are present
48-
in the repo.
49-
6. Sync the remote one more time.
50-
7. Assert that repository version is different from the previous one.
51-
8. Assert that the same number of are present and that no units were
52-
added.
53-
"""
54-
repo = self.client.post(NPM_REPO_PATH, gen_repo())
55-
self.addCleanup(self.client.delete, repo["pulp_href"])
56-
57-
body = gen_npm_remote(url="https://registry.npmjs.org/commander/4.0.1")
58-
remote = self.client.post(NPM_REMOTE_PATH, body)
59-
self.addCleanup(self.client.delete, remote["pulp_href"])
60-
61-
# Sync the repository.
62-
self.assertEqual(repo["latest_version_href"], f"{repo['pulp_href']}versions/0/")
63-
sync(self.cfg, remote, repo)
64-
repo = self.client.get(repo["pulp_href"])
65-
66-
self.assertIsNotNone(repo["latest_version_href"])
67-
self.assertDictEqual(get_content_summary(repo), NPM_FIXTURE_SUMMARY)
68-
self.assertDictEqual(get_added_content_summary(repo), NPM_FIXTURE_SUMMARY)
69-
70-
# Sync the repository again.
71-
latest_version_href = repo["latest_version_href"]
72-
sync(self.cfg, remote, repo)
73-
repo = self.client.get(repo["pulp_href"])
74-
75-
self.assertEqual(latest_version_href, repo["latest_version_href"])
76-
self.assertDictEqual(get_content_summary(repo), NPM_FIXTURE_SUMMARY)
77-
7834
# This test may not make sense for all plugins, but is likely to be useful
7935
# for most. Check that it makes sense for yours before enabling it.
8036
@unittest.skip("FIXME: plugin writer action required")
@@ -140,7 +96,7 @@ def test_invalid_npm_content(self):
14096
keywords related to the reason of the failure. See :meth:`do_test`.
14197
"""
14298
context = self.do_test(NPM_INVALID_FIXTURE_URL)
143-
for key in ("mismached", "empty"):
99+
for key in ("mismatched", "empty"):
144100
self.assertIn(key, context.exception.task["error"]["description"])
145101

146102
def do_test(self, url):
@@ -155,3 +111,25 @@ def do_test(self, url):
155111
with self.assertRaises(TaskReportError) as context:
156112
sync(self.cfg, remote, repo)
157113
return context
114+
115+
116+
@pytest.mark.parallel
117+
def test_sync_endpoint_demanding_remote_payload(
118+
npm_bindings, gen_object_with_cleanup, monitor_task
119+
):
120+
remote = gen_object_with_cleanup(
121+
npm_bindings.RemotesNpmApi,
122+
{"name": str(uuid.uuid4()), "url": "https://registry.npmjs.org/commander/4.0.1"},
123+
)
124+
repository = gen_object_with_cleanup(
125+
npm_bindings.RepositoriesNpmApi, {"name": str(uuid.uuid4()), "remote": remote.pulp_href}
126+
)
127+
128+
versions = npm_bindings.RepositoriesNpmVersionsApi.list(repository.pulp_href)
129+
assert versions.count == 1
130+
131+
sync_url = RepositorySyncURL()
132+
monitor_task(npm_bindings.RepositoriesNpmApi.sync(repository.pulp_href, sync_url).task)
133+
134+
new_versions = npm_bindings.RepositoriesNpmVersionsApi.list(repository.pulp_href)
135+
assert new_versions.count > 1

0 commit comments

Comments
 (0)