Skip to content

Commit 56c0107

Browse files
committed
Chore: a simple template change
And remove duplications in some tests
1 parent bebc032 commit 56c0107

File tree

3 files changed

+83
-161
lines changed

3 files changed

+83
-161
lines changed

template/index.html.j2

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ body {
1818
<hr/>
1919
<main>
2020
<ul style="list-style: none outside;" id="contents">
21-
{% for item in index.items %}{% if item.endswith("/") %}
22-
<li><a href="{{ item }}index.html" title="{{ item }}">{{ item }}</a></li>
23-
{% else %}
21+
{% for item in index.items %}
2422
<li><a href="{{ item }}" title="{{ item }}">{{ item }}</a></li>
25-
{% endif %}{% endfor%}
23+
{% endfor%}
2624
</ul>
2725
</main>
2826
<hr/>

tests/test_maven_del.py

Lines changed: 42 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -31,80 +31,16 @@
3131
@mock_s3
3232
class MavenDeleteTest(PackageBaseTest):
3333
def test_maven_deletion(self):
34-
self.__prepare_content()
35-
36-
test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip")
37-
product_456 = "commons-client-4.5.6"
38-
handle_maven_del(
39-
test_zip, product_456,
40-
bucket_name=TEST_BUCKET, dir_=self.tempdir,
41-
do_index=False
42-
)
43-
44-
test_bucket = self.mock_s3.Bucket(TEST_BUCKET)
45-
objs = list(test_bucket.objects.all())
46-
actual_files = [obj.key for obj in objs]
47-
self.assertEqual(
48-
COMMONS_CLIENT_459_MVN_NUM * 2 + COMMONS_CLIENT_META_NUM,
49-
len(actual_files)
50-
)
51-
52-
for f in COMMONS_CLIENT_456_FILES:
53-
self.assertNotIn(f, actual_files)
54-
55-
file_set = [
56-
*COMMONS_CLIENT_METAS, *ARCHETYPE_CATALOG_FILES,
57-
*COMMONS_LOGGING_FILES, *COMMONS_LOGGING_METAS
58-
]
34+
self.__test_prefix_deletion("")
5935

60-
for f in file_set:
61-
self.assertIn(f, actual_files)
62-
63-
for obj in objs:
64-
if not obj.key.endswith(PROD_INFO_SUFFIX):
65-
self.assertIn(CHECKSUM_META_KEY, obj.Object().metadata)
66-
self.assertNotEqual("", obj.Object().metadata[CHECKSUM_META_KEY].strip())
67-
68-
product_459 = "commons-client-4.5.9"
69-
meta_obj_client = test_bucket.Object(COMMONS_CLIENT_METAS[0])
70-
meta_content_client = str(meta_obj_client.get()["Body"].read(), "utf-8")
71-
self.assertIn(
72-
"<groupId>org.apache.httpcomponents</groupId>", meta_content_client
73-
)
74-
self.assertIn("<artifactId>httpclient</artifactId>", meta_content_client)
75-
self.assertNotIn("<version>4.5.6</version>", meta_content_client)
76-
self.assertNotIn("<latest>4.5.6</latest>", meta_content_client)
77-
self.assertNotIn("<release>4.5.6</release>", meta_content_client)
78-
self.assertIn("<latest>4.5.9</latest>", meta_content_client)
79-
self.assertIn("<release>4.5.9</release>", meta_content_client)
80-
self.assertIn("<version>4.5.9</version>", meta_content_client)
81-
82-
meta_obj_cat = test_bucket.Object(ARCHETYPE_CATALOG)
83-
meta_content_cat = str(meta_obj_cat.get()["Body"].read(), "utf-8")
84-
self.assertIn(
85-
"<groupId>org.apache.httpcomponents</groupId>", meta_content_cat
86-
)
87-
self.assertIn("<artifactId>httpclient</artifactId>", meta_content_cat)
88-
self.assertNotIn("<version>4.5.6</version>", meta_content_cat)
89-
90-
meta_obj_logging = test_bucket.Object(COMMONS_LOGGING_METAS[0])
91-
self.assertNotIn(PRODUCT_META_KEY, meta_obj_logging.metadata)
92-
meta_content_logging = str(meta_obj_logging.get()["Body"].read(), "utf-8")
93-
self.assertIn("<groupId>commons-logging</groupId>", meta_content_logging)
94-
self.assertIn("<artifactId>commons-logging</artifactId>", meta_content_logging)
95-
self.assertIn("<version>1.2</version>", meta_content_logging)
96-
self.assertIn("<latest>1.2</latest>", meta_content_logging)
97-
self.assertIn("<release>1.2</release>", meta_content_logging)
36+
def test_short_prefix_deletion(self):
37+
self.__test_prefix_deletion(SHORT_TEST_PREFIX)
9838

99-
test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip")
100-
handle_maven_del(
101-
test_zip, product_459,
102-
bucket_name=TEST_BUCKET, dir_=self.tempdir,
103-
do_index=False
104-
)
39+
def test_long_prefix_deletion(self):
40+
self.__test_prefix_deletion(LONG_TEST_PREFIX)
10541

106-
objs = list(test_bucket.objects.all())
107-
self.assertEqual(0, len(objs))
42+
def test_root_prefix_deletion(self):
43+
self.__test_prefix_deletion("/")
10844

10945
def test_ignore_del(self):
11046
self.__prepare_content()
@@ -159,15 +95,6 @@ def test_ignore_del(self):
15995
for f in non_sha1_files:
16096
self.assertNotIn(f, actual_files)
16197

162-
def test_short_prefix_deletion(self):
163-
self.__test_prefix_deletion(SHORT_TEST_PREFIX)
164-
165-
def test_long_prefix_deletion(self):
166-
self.__test_prefix_deletion(LONG_TEST_PREFIX)
167-
168-
def test_root_prefix_deletion(self):
169-
self.__test_prefix_deletion("/")
170-
17198
def __test_prefix_deletion(self, prefix: str):
17299
self.__prepare_content(prefix)
173100

@@ -183,6 +110,7 @@ def __test_prefix_deletion(self, prefix: str):
183110
test_bucket = self.mock_s3.Bucket(TEST_BUCKET)
184111
objs = list(test_bucket.objects.all())
185112
actual_files = [obj.key for obj in objs]
113+
# need to double mvn num because of .prodinfo files
186114
self.assertEqual(
187115
COMMONS_CLIENT_459_MVN_NUM * 2 + COMMONS_CLIENT_META_NUM,
188116
len(actual_files)
@@ -193,18 +121,20 @@ def __test_prefix_deletion(self, prefix: str):
193121
os.path.join(prefix_, f) for f in COMMONS_CLIENT_456_FILES]
194122
for f in PREFIXED_COMMONS_CLIENT_456_FILES:
195123
self.assertNotIn(f, actual_files)
124+
196125
PREFIXED_COMMONS_CLIENT_METAS = [
197126
os.path.join(prefix_, f) for f in COMMONS_CLIENT_METAS]
198-
for f in PREFIXED_COMMONS_CLIENT_METAS:
199-
self.assertIn(f, actual_files)
200-
201127
PREFIXED_COMMONS_LOGGING_FILES = [
202128
os.path.join(prefix_, f) for f in COMMONS_LOGGING_FILES]
203-
for f in PREFIXED_COMMONS_LOGGING_FILES:
204-
self.assertIn(f, actual_files)
205129
PREFIXED_COMMONS_LOGGING_METAS = [
206130
os.path.join(prefix_, f) for f in COMMONS_LOGGING_METAS]
207-
for f in PREFIXED_COMMONS_LOGGING_METAS:
131+
PREFIXED_ARCHE_CATALOG_FILES = [
132+
os.path.join(prefix_, f) for f in ARCHETYPE_CATALOG_FILES]
133+
file_set = [
134+
*PREFIXED_COMMONS_CLIENT_METAS, *PREFIXED_ARCHE_CATALOG_FILES,
135+
*PREFIXED_COMMONS_LOGGING_FILES, *PREFIXED_COMMONS_LOGGING_METAS
136+
]
137+
for f in file_set:
208138
self.assertIn(f, actual_files)
209139

210140
for obj in objs:
@@ -214,10 +144,35 @@ def __test_prefix_deletion(self, prefix: str):
214144

215145
product_459 = "commons-client-4.5.9"
216146
meta_obj_client = test_bucket.Object(PREFIXED_COMMONS_CLIENT_METAS[0])
217-
self.assertNotIn(PRODUCT_META_KEY, meta_obj_client.metadata)
147+
meta_content_client = str(meta_obj_client.get()["Body"].read(), "utf-8")
148+
self.assertIn(
149+
"<groupId>org.apache.httpcomponents</groupId>", meta_content_client
150+
)
151+
self.assertIn("<artifactId>httpclient</artifactId>", meta_content_client)
152+
self.assertNotIn("<version>4.5.6</version>", meta_content_client)
153+
self.assertNotIn("<latest>4.5.6</latest>", meta_content_client)
154+
self.assertNotIn("<release>4.5.6</release>", meta_content_client)
155+
self.assertIn("<latest>4.5.9</latest>", meta_content_client)
156+
self.assertIn("<release>4.5.9</release>", meta_content_client)
157+
self.assertIn("<version>4.5.9</version>", meta_content_client)
158+
159+
PREFIXED_ARCHE_CATALOG = os.path.join(prefix_, ARCHETYPE_CATALOG)
160+
meta_obj_cat = test_bucket.Object(PREFIXED_ARCHE_CATALOG)
161+
meta_content_cat = str(meta_obj_cat.get()["Body"].read(), "utf-8")
162+
self.assertIn(
163+
"<groupId>org.apache.httpcomponents</groupId>", meta_content_cat
164+
)
165+
self.assertIn("<artifactId>httpclient</artifactId>", meta_content_cat)
166+
self.assertNotIn("<version>4.5.6</version>", meta_content_cat)
218167

219168
meta_obj_logging = test_bucket.Object(PREFIXED_COMMONS_LOGGING_METAS[0])
220169
self.assertNotIn(PRODUCT_META_KEY, meta_obj_logging.metadata)
170+
meta_content_logging = str(meta_obj_logging.get()["Body"].read(), "utf-8")
171+
self.assertIn("<groupId>commons-logging</groupId>", meta_content_logging)
172+
self.assertIn("<artifactId>commons-logging</artifactId>", meta_content_logging)
173+
self.assertIn("<version>1.2</version>", meta_content_logging)
174+
self.assertIn("<latest>1.2</latest>", meta_content_logging)
175+
self.assertIn("<release>1.2</release>", meta_content_logging)
221176

222177
test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.9.zip")
223178
handle_maven_del(

tests/test_maven_upload.py

Lines changed: 39 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,16 @@
3030
@mock_s3
3131
class MavenUploadTest(PackageBaseTest):
3232
def test_fresh_upload(self):
33-
test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip")
34-
product = "commons-client-4.5.6"
35-
handle_maven_uploading(
36-
test_zip, product,
37-
bucket_name=TEST_BUCKET, dir_=self.tempdir,
38-
do_index=False
39-
)
40-
41-
objs = list(self.test_bucket.objects.all())
42-
actual_files = [obj.key for obj in objs]
43-
self.assertEqual(
44-
COMMONS_CLIENT_456_MVN_NUM * 2 + COMMONS_CLIENT_META_NUM,
45-
len(actual_files)
46-
)
47-
48-
filesets = [
49-
COMMONS_CLIENT_METAS, COMMONS_CLIENT_456_FILES,
50-
COMMONS_LOGGING_FILES, COMMONS_LOGGING_METAS,
51-
ARCHETYPE_CATALOG_FILES
52-
]
53-
54-
for fileset in filesets:
55-
for f in fileset:
56-
self.assertIn(f, actual_files)
33+
self.__test_prefix_upload("")
5734

58-
for f in NON_MVN_FILES:
59-
self.assertNotIn(f, actual_files)
60-
61-
self.check_content(objs, [product])
62-
63-
meta_obj_client = self.test_bucket.Object(COMMONS_CLIENT_METAS[0])
64-
meta_content_client = str(meta_obj_client.get()["Body"].read(), "utf-8")
65-
self.assertIn(
66-
"<groupId>org.apache.httpcomponents</groupId>", meta_content_client
67-
)
68-
self.assertIn("<artifactId>httpclient</artifactId>", meta_content_client)
69-
self.assertIn("<version>4.5.6</version>", meta_content_client)
70-
self.assertIn("<latest>4.5.6</latest>", meta_content_client)
71-
self.assertIn("<release>4.5.6</release>", meta_content_client)
72-
self.assertNotIn("<version>4.5.9</version>", meta_content_client)
35+
def test_short_prefix_upload(self):
36+
self.__test_prefix_upload(SHORT_TEST_PREFIX)
7337

74-
meta_obj_logging = self.test_bucket.Object(COMMONS_LOGGING_METAS[0])
75-
meta_content_logging = str(meta_obj_logging.get()["Body"].read(), "utf-8")
76-
self.assertIn("<groupId>commons-logging</groupId>", meta_content_logging)
77-
self.assertIn("<artifactId>commons-logging</artifactId>", meta_content_logging)
78-
self.assertIn("<version>1.2</version>", meta_content_logging)
79-
self.assertIn("<latest>1.2</latest>", meta_content_logging)
80-
self.assertIn("<release>1.2</release>", meta_content_logging)
38+
def test_long_prefix_upload(self):
39+
self.__test_prefix_upload(LONG_TEST_PREFIX)
8140

82-
catalog = self.test_bucket.Object(ARCHETYPE_CATALOG)
83-
cat_content = str(catalog.get()["Body"].read(), "utf-8")
84-
self.assertIn("<version>4.5.6</version>", cat_content)
85-
self.assertIn("<artifactId>httpclient</artifactId>", cat_content)
86-
self.assertIn("<groupId>org.apache.httpcomponents</groupId>", cat_content)
41+
def test_root_prefix_upload(self):
42+
self.__test_prefix_upload("/")
8743

8844
def test_overlap_upload(self):
8945
test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip")
@@ -102,6 +58,7 @@ def test_overlap_upload(self):
10258

10359
objs = list(self.test_bucket.objects.all())
10460
actual_files = [obj.key for obj in objs]
61+
# need to double mvn num because of .prodinfo files
10562
self.assertEqual(
10663
COMMONS_CLIENT_MVN_NUM * 2 + COMMONS_CLIENT_META_NUM,
10764
len(actual_files)
@@ -169,22 +126,14 @@ def test_ignore_upload(self):
169126
not_ignored = [e for e in COMMONS_CLIENT_456_FILES if e not in ignored_files]
170127
not_ignored.extend(
171128
[e for e in COMMONS_LOGGING_FILES if e not in ignored_files])
129+
# need to double mvn num because of .prodinfo files
172130
self.assertEqual(
173131
len(not_ignored) * 2 + COMMONS_CLIENT_META_NUM, len(actual_files))
174132
for f in not_ignored:
175133
self.assertIn(f, actual_files)
176134
for f in ignored_files:
177135
self.assertNotIn(f, actual_files)
178136

179-
def test_short_prefix_upload(self):
180-
self.__test_prefix_upload(SHORT_TEST_PREFIX)
181-
182-
def test_long_prefix_upload(self):
183-
self.__test_prefix_upload(LONG_TEST_PREFIX)
184-
185-
def test_root_prefix_upload(self):
186-
self.__test_prefix_upload("/")
187-
188137
def __test_prefix_upload(self, prefix: str):
189138
test_zip = os.path.join(os.getcwd(), "tests/input/commons-client-4.5.6.zip")
190139
product = "commons-client-4.5.6"
@@ -198,6 +147,7 @@ def __test_prefix_upload(self, prefix: str):
198147

199148
objs = list(self.test_bucket.objects.all())
200149
actual_files = [obj.key for obj in objs]
150+
# need to double mvn num because of .prodinfo files
201151
self.assertEqual(
202152
COMMONS_CLIENT_456_MVN_NUM * 2 + COMMONS_CLIENT_META_NUM,
203153
len(actual_files)
@@ -206,20 +156,20 @@ def __test_prefix_upload(self, prefix: str):
206156
prefix_ = remove_prefix(prefix, "/")
207157
PREFIXED_COMMONS_CLIENT_456_FILES = [
208158
os.path.join(prefix_, f) for f in COMMONS_CLIENT_456_FILES]
209-
for f in PREFIXED_COMMONS_CLIENT_456_FILES:
210-
self.assertIn(f, actual_files)
211159
PREFIXED_COMMONS_CLIENT_METAS = [
212160
os.path.join(prefix_, f) for f in COMMONS_CLIENT_METAS]
213-
for f in PREFIXED_COMMONS_CLIENT_METAS:
214-
self.assertIn(f, actual_files)
215-
216161
PREFIXED_COMMONS_LOGGING_FILES = [
217162
os.path.join(prefix_, f) for f in COMMONS_LOGGING_FILES]
218-
for f in PREFIXED_COMMONS_LOGGING_FILES:
219-
self.assertIn(f, actual_files)
220163
PREFIXED_COMMONS_LOGGING_METAS = [
221164
os.path.join(prefix_, f) for f in COMMONS_LOGGING_METAS]
222-
for f in PREFIXED_COMMONS_LOGGING_METAS:
165+
PREFIXED_ARCHETYPE_CATALOG_FILES = [
166+
os.path.join(prefix_, f) for f in ARCHETYPE_CATALOG_FILES]
167+
file_set = [
168+
*PREFIXED_COMMONS_CLIENT_456_FILES, *PREFIXED_COMMONS_CLIENT_METAS,
169+
*PREFIXED_COMMONS_LOGGING_FILES, *PREFIXED_COMMONS_LOGGING_METAS,
170+
*PREFIXED_ARCHETYPE_CATALOG_FILES
171+
]
172+
for f in file_set:
223173
self.assertIn(f, actual_files)
224174

225175
PREFIXED_NON_MVN_FILES = [
@@ -230,7 +180,26 @@ def __test_prefix_upload(self, prefix: str):
230180
self.check_content(objs, [product])
231181

232182
meta_obj_client = self.test_bucket.Object(PREFIXED_COMMONS_CLIENT_METAS[0])
233-
self.assertIsNotNone(meta_obj_client)
183+
meta_content_client = str(meta_obj_client.get()["Body"].read(), "utf-8")
184+
self.assertIn(
185+
"<groupId>org.apache.httpcomponents</groupId>", meta_content_client
186+
)
187+
self.assertIn("<artifactId>httpclient</artifactId>", meta_content_client)
188+
self.assertIn("<version>4.5.6</version>", meta_content_client)
189+
self.assertIn("<latest>4.5.6</latest>", meta_content_client)
190+
self.assertIn("<release>4.5.6</release>", meta_content_client)
191+
self.assertNotIn("<version>4.5.9</version>", meta_content_client)
234192

235193
meta_obj_logging = self.test_bucket.Object(PREFIXED_COMMONS_LOGGING_METAS[0])
236-
self.assertIsNotNone(meta_obj_logging)
194+
meta_content_logging = str(meta_obj_logging.get()["Body"].read(), "utf-8")
195+
self.assertIn("<groupId>commons-logging</groupId>", meta_content_logging)
196+
self.assertIn("<artifactId>commons-logging</artifactId>", meta_content_logging)
197+
self.assertIn("<version>1.2</version>", meta_content_logging)
198+
self.assertIn("<latest>1.2</latest>", meta_content_logging)
199+
self.assertIn("<release>1.2</release>", meta_content_logging)
200+
201+
catalog = self.test_bucket.Object(PREFIXED_ARCHETYPE_CATALOG_FILES[0])
202+
cat_content = str(catalog.get()["Body"].read(), "utf-8")
203+
self.assertIn("<version>4.5.6</version>", cat_content)
204+
self.assertIn("<artifactId>httpclient</artifactId>", cat_content)
205+
self.assertIn("<groupId>org.apache.httpcomponents</groupId>", cat_content)

0 commit comments

Comments
 (0)