Expose model_version in scanners API response (#14970)
This commit is contained in:
Родитель
442815937c
Коммит
b84b8f9892
|
@ -28,3 +28,4 @@ This endpoint returns a list of labelled scanner results.
|
|||
:>json string label: Either ``good`` or ``bad``.
|
||||
:>json object results: The scanner (raw) results.
|
||||
:>json string created: The date the result was created, formatted with `this format <http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.15>`_.
|
||||
:>json string|null model_version: The model version when applicable, ``null`` otherwise.
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.13 on 2020-07-16 13:24
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('scanners', '0035_delete_versionscannerflags'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='scannerresult',
|
||||
name='model_version',
|
||||
field=models.CharField(max_length=30, null=True),
|
||||
),
|
||||
]
|
|
@ -317,6 +317,7 @@ class ScannerResult(AbstractScannerResult):
|
|||
score = models.DecimalField(
|
||||
null=True, blank=True, max_digits=6, decimal_places=5, default=-1
|
||||
)
|
||||
model_version = models.CharField(max_length=30, null=True)
|
||||
|
||||
class Meta(AbstractScannerResult.Meta):
|
||||
db_table = 'scanners_results'
|
||||
|
|
|
@ -10,7 +10,14 @@ class ScannerResultSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = ScannerResult
|
||||
fields = ('id', 'scanner', 'label', 'results', 'created')
|
||||
fields = (
|
||||
'id',
|
||||
'scanner',
|
||||
'label',
|
||||
'results',
|
||||
'created',
|
||||
'model_version',
|
||||
)
|
||||
|
||||
def get_scanner(self, obj):
|
||||
return obj.get_scanner_name()
|
||||
|
|
|
@ -478,13 +478,13 @@ def call_mad_api(all_results, upload_pk):
|
|||
score=data.get('ensemble', default_score),
|
||||
)
|
||||
|
||||
# Update the individual scanner results scores.
|
||||
customs_score = (
|
||||
data.get('scanners', {})
|
||||
.get('customs', {})
|
||||
.get('score', default_score)
|
||||
# Update the individual scanner results with some info from MAD.
|
||||
customs_data = data.get('scanners', {}).get('customs', {})
|
||||
customs_score = customs_data.get('score', default_score)
|
||||
customs_model_version = customs_data.get('model_version')
|
||||
customs_results.update(
|
||||
score=customs_score, model_version=customs_model_version
|
||||
)
|
||||
customs_results.update(score=customs_score)
|
||||
|
||||
statsd.incr('devhub.mad.success')
|
||||
log.info('Ending scanner "mad" task for FileUpload %s.', upload_pk)
|
||||
|
|
|
@ -8,7 +8,9 @@ from olympia.scanners.serializers import ScannerResultSerializer
|
|||
|
||||
class TestScannerResultSerializer(TestCase):
|
||||
def test_serialize(self):
|
||||
result = ScannerResult.objects.create(scanner=CUSTOMS)
|
||||
result = ScannerResult.objects.create(
|
||||
scanner=CUSTOMS, model_version='some.version'
|
||||
)
|
||||
data = ScannerResultSerializer(instance=result).data
|
||||
assert data == {
|
||||
'id': result.id,
|
||||
|
@ -18,4 +20,5 @@ class TestScannerResultSerializer(TestCase):
|
|||
'created': result.created.strftime(
|
||||
settings.REST_FRAMEWORK['DATETIME_FORMAT']
|
||||
),
|
||||
'model_version': result.model_version,
|
||||
}
|
||||
|
|
|
@ -803,15 +803,19 @@ class TestCallMadApi(UploadTest, TestCase):
|
|||
@mock.patch.object(requests.Session, 'post')
|
||||
def test_call_with_mocks(self, requests_mock, incr_mock, timer_mock,
|
||||
uuid4_mock):
|
||||
model_version = 'x.y.z'
|
||||
ml_results = {
|
||||
'ensemble': 0.56,
|
||||
'scanners': {'customs': {'score': 0.123}},
|
||||
'scanners': {
|
||||
'customs': {'score': 0.123, 'model_version': model_version},
|
||||
},
|
||||
}
|
||||
requests_mock.return_value = self.create_response(data=ml_results)
|
||||
requestId = 'some request id'
|
||||
uuid4_mock.return_value.hex = requestId
|
||||
assert len(ScannerResult.objects.all()) == self.default_results_count
|
||||
assert self.customs_result.score == -1.0
|
||||
assert self.customs_result.model_version is None
|
||||
|
||||
returned_results = call_mad_api(self.results, self.upload.pk)
|
||||
|
||||
|
@ -839,7 +843,9 @@ class TestCallMadApi(UploadTest, TestCase):
|
|||
# returned in the ML response.
|
||||
self.customs_result.refresh_from_db()
|
||||
assert self.customs_result.score == Decimal('0.123')
|
||||
assert self.customs_result.model_version == model_version
|
||||
assert mad_result.score == Decimal('0.56')
|
||||
assert mad_result.model_version is None
|
||||
|
||||
@mock.patch('olympia.scanners.tasks.statsd.incr')
|
||||
@mock.patch.object(requests.Session, 'post')
|
||||
|
|
Загрузка…
Ссылка в новой задаче