Skip to content

Commit 075d671

Browse files
committed
require source when uploading
1 parent c3cc2d2 commit 075d671

6 files changed

Lines changed: 27 additions & 14 deletions

File tree

‎codespeed/results.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def validate_result(item):
3232
'benchmark',
3333
'environment',
3434
'result_value',
35+
'source',
3536
]
3637

3738
error = True
@@ -41,7 +42,7 @@ def validate_result(item):
4142
elif key in item and item[key] == "":
4243
return 'Value for key "' + key + '" empty in request', error
4344

44-
if 'source' in item and item['source'] not in dict(Benchmark.S_TYPES):
45+
if item['source'] not in dict(Benchmark.S_TYPES):
4546
return 'Invalid source "%s"' % item['source'], error
4647

4748
try:
@@ -73,9 +74,8 @@ def save_result(data, update_repo=True):
7374
p, created = Project.objects.get_or_create(name=data["project"])
7475
branch, created = Branch.objects.get_or_create(name=data["branch"],
7576
project=p)
76-
source = data.get("source", "legacy")
7777
b, created = Benchmark.objects.get_or_create(
78-
name=data["benchmark"], source=source)
78+
name=data["benchmark"], source=data["source"])
7979

8080
if created:
8181
if "description" in data:

‎codespeed/tests/test_views.py‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def setUp(self):
2929
'benchmark': 'float',
3030
'environment': 'Dual Core',
3131
'result_value': 456,
32+
'source': 'legacy',
3233
}
3334

3435
def test_add_correct_result(self):
@@ -190,11 +191,13 @@ def test_source_set_on_new_benchmark(self):
190191
b = Benchmark.objects.get(name='newbench')
191192
self.assertEqual(b.source, 'pyperformance')
192193

193-
def test_source_defaults_to_legacy(self):
194-
"""A payload without a source creates a 'legacy' Benchmark"""
195-
self.client.post(self.path, self.data)
196-
b = Benchmark.objects.get(name='float')
197-
self.assertEqual(b.source, 'legacy')
194+
def test_missing_source_rejected(self):
195+
"""A payload without a source is rejected instead of defaulting"""
196+
modified_data = copy.deepcopy(self.data)
197+
del modified_data['source']
198+
response = self.client.post(self.path, modified_data)
199+
self.assertEqual(response.status_code, 400)
200+
self.assertFalse(Benchmark.objects.filter(name='float').exists())
198201

199202
def test_same_name_different_source_are_distinct(self):
200203
"""The same name in a different suite is a separate Benchmark"""
@@ -245,28 +248,32 @@ def setUp(self):
245248
'executable': 'pypy-c',
246249
'benchmark': 'Richards',
247250
'environment': 'bigdog',
248-
'result_value': 456},
251+
'result_value': 456,
252+
'source': 'legacy'},
249253
{'commitid': '456',
250254
'project': 'pypy',
251255
'branch': 'default',
252256
'executable': 'pypy-c',
253257
'benchmark': 'Richards',
254258
'environment': 'bigdog',
255-
'result_value': 457},
259+
'result_value': 457,
260+
'source': 'legacy'},
256261
{'commitid': '456',
257262
'project': 'pypy',
258263
'branch': 'default',
259264
'executable': 'pypy-c',
260265
'benchmark': 'Richards2',
261266
'environment': 'bigdog',
262-
'result_value': 34},
267+
'result_value': 34,
268+
'source': 'legacy'},
263269
{'commitid': '789',
264270
'project': 'pypy',
265271
'branch': 'default',
266272
'executable': 'pypy-c',
267273
'benchmark': 'Richards',
268274
'environment': 'bigdog',
269-
'result_value': 458},
275+
'result_value': 458,
276+
'source': 'legacy'},
270277
]
271278

272279
def test_get_returns_405(self):
@@ -452,6 +459,7 @@ def setUp(self):
452459
'benchmark': 'float',
453460
'environment': 'Dual Core',
454461
'result_value': 200,
462+
'source': 'legacy',
455463
}
456464
resp = self.client.post(reverse('add-result'),
457465
self.data)

‎tools/pypy/savecpython.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def save(project, revision, results, options, executable, host, testing=False):
3131
'environment': host,
3232
'result_value': value,
3333
'result_date': current_date,
34+
'source': 'legacy',
3435
}
3536
if res_type == "ComparisonResult":
3637
data['std_dev'] = results['std_changed']

‎tools/pypy/saveresults.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def save(project, revision, results, executable, host, url, testing=False,
7979
'environment': host,
8080
'result_value': value,
8181
'branch': branch,
82+
'source': 'legacy',
8283
}]
8384
if not value:
8485
print("Ignoring skipped result", data)

‎tools/save_multiple_results.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"executable": "myexe O3 64bits",
1919
"benchmark": "float",
2020
"environment": "Dual Core",
21-
"result_value": 2500.0
21+
"result_value": 2500.0,
22+
"source": "legacy"
2223
},
2324
{
2425
"commitid": "8",
@@ -27,7 +28,8 @@
2728
"executable": "myexe O3 64bits",
2829
"benchmark": "int",
2930
"environment": "Dual Core",
30-
"result_value": 1100
31+
"result_value": 1100,
32+
"source": "legacy"
3133
}
3234
]
3335

‎tools/save_single_result.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'benchmark': 'float',
2121
'environment': "Dual Core",
2222
'result_value': 4000,
23+
'source': 'legacy', # 'legacy' or 'pyperformance'
2324
}
2425

2526
# Optional fields

0 commit comments

Comments
 (0)