Merge branch 'master' into nanterre-recette

This commit is contained in:
Benjamin Dauvergne 2017-11-30 11:50:54 +01:00
commit 84f6883614
3 changed files with 39 additions and 5 deletions

View File

@ -3,10 +3,11 @@ import copy
from django.core.urlresolvers import reverse
from zoo.zoo_nanterre.models import Duplicate
from zoo.zoo_data.models import Log
def test_list_doublons(nanterre_classic_family, app):
from zoo.zoo_nanterre.models import Duplicate
e = nanterre_classic_family
url = reverse('rsu-api-doublons')
@ -35,7 +36,7 @@ def test_list_doublons(nanterre_classic_family, app):
Duplicate.objects.create(
first=new[-1],
second=e['marie'],
score=(100-i/2)/100.0)
score=(100 - i / 2) / 100.0)
response = app.get(url)
assert response.json['err'] == 0
@ -51,6 +52,7 @@ def test_list_doublons(nanterre_classic_family, app):
assert response.json['data'][0]['score'] == 100
first_data = response.json['data'][0]
second_data = response.json['data'][1]
third_data = response.json['data'][2]
url = reverse('rsu-api-doublons') + '?limit=100'
response = app.get(url)
@ -85,6 +87,10 @@ def test_list_doublons(nanterre_classic_family, app):
response = app.post(false_positive_url)
assert response.json['err'] == 0
assert Duplicate.objects.get(id=second_data['id']).state == Duplicate.STATE_FALSE_POSITIVE
log = Log.objects.filter(entity_id=second_data['individu_1']['id']).latest('id')
assert 'non doublon de' in log.content['text']
log = Log.objects.filter(entity_id=second_data['individu_2']['id']).latest('id')
assert 'non doublon de' in log.content['text']
url = reverse('rsu-api-doublons') + '?false_positive=1'
response = app.get(url)
@ -121,3 +127,19 @@ def test_list_doublons(nanterre_classic_family, app):
assert 'more' not in response.json
assert 'cookie' not in response.json
assert len(response.json['data']) == 89
false_positive_url = reverse('rsu-api-doublon-false-positive', kwargs={
'doublon_id': '%s %s' % (
third_data['individu_1']['id'],
third_data['individu_2']['id'],
)
})
response = app.post_json(false_positive_url, params={'journal_form_id': 103})
assert response.json['err'] == 0
assert Duplicate.objects.get(id=third_data['id']).state == Duplicate.STATE_FALSE_POSITIVE
log = Log.objects.filter(entity_id=third_data['individu_1']['id']).latest('id')
assert 'non doublon de' in log.content['text']
assert log.content['meta']['form_id'] == 103
log = Log.objects.filter(entity_id=third_data['individu_2']['id']).latest('id')
assert 'non doublon de' in log.content['text']
assert log.content['meta']['form_id'] == 103

View File

@ -26,7 +26,7 @@ deps =
pytest-cov
pytest-django
mock
pytest
pytest>=3.3.0
lxml
cssselect
pylint
@ -35,7 +35,6 @@ deps =
WebTest
pyquery
httmock
pytest-catchlog
pytz
faker
commands =

View File

@ -1989,8 +1989,21 @@ class DoublonActionView(DoublonMixin, TransactionalView):
class FalsePositiveView(DoublonActionView):
def action(self, request, duplicate):
serializer = JournalSerializerMixin(data=request.data)
try:
duplicate.false_positive()
utils.journalize(
duplicate.first,
transaction=self.transaction,
meta=serializer.journal_meta,
faux_positif=duplicate.second.id,
text=u'Déclaré comme non doublon de #%d' % duplicate.second.id)
utils.journalize(
duplicate.second,
transaction=self.transaction,
meta=serializer.journal_meta,
faux_positif=duplicate.first.id,
text=u'Déclaré comme non doublon de #%d' % duplicate.first.id)
return Response({
'err': 0,
})