1
1
# coding=utf-8
2
2
"""Tests that sync npm plugin repositories."""
3
+ import pytest
3
4
import unittest
5
+ import uuid
6
+
7
+ from pulpcore .client .pulp_npm import RepositorySyncURL
4
8
5
9
from pulp_smash import api , cli , config
6
10
from pulp_smash .exceptions import TaskReportError
7
11
from pulp_smash .pulp3 .constants import MEDIA_PATH
8
12
from pulp_smash .pulp3 .utils import (
9
13
gen_repo ,
10
- get_added_content_summary ,
11
- get_content_summary ,
12
14
sync ,
13
15
)
14
16
15
17
from pulp_npm .tests .functional .constants import (
16
- NPM_FIXTURE_SUMMARY ,
17
18
NPM_INVALID_FIXTURE_URL ,
18
19
NPM_REMOTE_PATH ,
19
20
NPM_REPO_PATH ,
20
21
)
21
22
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
23
23
24
24
25
25
class BasicSyncTestCase (unittest .TestCase ):
@@ -31,50 +31,6 @@ def setUpClass(cls):
31
31
cls .cfg = config .get_config ()
32
32
cls .client = api .Client (cls .cfg , api .json_handler )
33
33
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
-
78
34
# This test may not make sense for all plugins, but is likely to be useful
79
35
# for most. Check that it makes sense for yours before enabling it.
80
36
@unittest .skip ("FIXME: plugin writer action required" )
@@ -140,7 +96,7 @@ def test_invalid_npm_content(self):
140
96
keywords related to the reason of the failure. See :meth:`do_test`.
141
97
"""
142
98
context = self .do_test (NPM_INVALID_FIXTURE_URL )
143
- for key in ("mismached " , "empty" ):
99
+ for key in ("mismatched " , "empty" ):
144
100
self .assertIn (key , context .exception .task ["error" ]["description" ])
145
101
146
102
def do_test (self , url ):
@@ -155,3 +111,25 @@ def do_test(self, url):
155
111
with self .assertRaises (TaskReportError ) as context :
156
112
sync (self .cfg , remote , repo )
157
113
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