Projet

Général

Profil

0001-do-not-add-an-evolution-on-static-jump-22236.patch

Thomas Noël, 01 mai 2018 12:25

Télécharger (4,95 ko)

Voir les différences:

Subject: [PATCH] do not add an evolution on static jump (#22236)

 tests/test_form_pages.py | 33 ++++++++++++++++++++++++++++++---
 tests/test_sql.py        |  2 ++
 wcs/formdata.py          | 15 +++++++++++++--
 3 files changed, 45 insertions(+), 5 deletions(-)
tests/test_form_pages.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3
import datetime
3 4
import json
4 5
import pytest
5 6
import hashlib
......
3766 3767
    user.roles = [role.id]
3767 3768
    user.store()
3768 3769

  
3770
    assert len(formdef.data_class().get(formdata.id).evolution) == 1
3771
    formdata.evolution[0].time = datetime.datetime(1980, 1, 1, 0, 0, 0).timetuple()
3772
    formdata.store()
3773
    assert formdef.data_class().get(formdata.id).evolution[0].time.tm_year == 1980
3774

  
3769 3775
    login(app, username='foo', password='foo')
3770 3776
    resp = app.post(formdata.get_url() + 'jump/trigger/XXX', status=302)
3777
    formdata = formdef.data_class().get(formdata.id)
3778
    # status is not changed, no new evolution, update last time
3779
    assert len(formdata.evolution) == 1
3780
    assert formdata.status == 'wf-st1'
3781
    assert formdata.evolution[0].time.tm_year != 1980
3782

  
3783
    # add a comment to last evolution, force create a new one
3784
    formdata.evolution[-1].comment = "new-evolution-1"
3785
    formdata.store()
3786
    resp = app.post(formdata.get_url() + 'jump/trigger/XXX', status=302)
3787
    formdata = formdef.data_class().get(formdata.id)
3788
    assert len(formdata.evolution) == 2
3789
    assert formdata.status == 'wf-st1'
3790

  
3791
    # again
3792
    formdata.evolution[-1].comment = "new-evolution-2"
3793
    formdata.store()
3771 3794
    resp = app.post(formdata.get_url() + 'jump/trigger/XXX', status=302)
3795

  
3796
    # last evolution is empty, this last trigger does not create a new one
3772 3797
    resp = app.post(formdata.get_url() + 'jump/trigger/XXX', status=302)
3773 3798

  
3774
    assert len(formdef.data_class().get(formdata.id).evolution) == 4
3799
    assert len(formdef.data_class().get(formdata.id).evolution) == 3
3775 3800
    assert formdef.data_class().get(formdata.id).status == 'wf-st1'
3776 3801

  
3777 3802
    resp = app.get(formdata.get_url())
3778
    assert resp.body.count('Status1') == 2 # once in summary and once in journal
3779
    assert resp.body.count('CSS-STATUS1') == 1
3803
    assert resp.body.count('Status1') == 3 # once in summary and two in journal
3804
    assert resp.body.count('CSS-STATUS1') == 2
3805
    assert resp.body.count('new-evolution-1') == 1
3806
    assert resp.body.count('new-evolution-2') == 1
3780 3807

  
3781 3808
def test_display_message(pub):
3782 3809
    user = create_user(pub)
tests/test_sql.py
1456 1456
    formdata1 = data_class()
1457 1457
    formdata1.status = 'wf-st1'
1458 1458
    formdata1.just_created()
1459
    formdata1.evolution[0].comment = 'comment'
1459 1460
    formdata1.jump_status('st1') # will add another evolution entry
1460 1461
    formdata1.evolution[0].time = datetime.datetime(2015, 1, 1, 0, 0, 0).timetuple()
1461 1462
    formdata1.evolution[1].time = datetime.datetime(2015, 1, 2, 0, 0, 0).timetuple()
......
1464 1465
    formdata2 = data_class()
1465 1466
    formdata2.status = 'wf-st1'
1466 1467
    formdata2.just_created()
1468
    formdata2.evolution[0].comment = 'comment'
1467 1469
    formdata2.jump_status('st1') # will add another evolution entry
1468 1470
    formdata2.evolution[0].time = datetime.datetime(2015, 1, 3, 0, 0, 0).timetuple()
1469 1471
    formdata2.evolution[1].time = datetime.datetime(2015, 1, 4, 0, 0, 0).timetuple()
wcs/formdata.py
536 536
            previous_status = self.pop_previous_marked_status()
537 537
            assert previous_status, 'failed to compute previous status'
538 538
            status_id = previous_status.id
539
        status = 'wf-%s' % status_id
540
        if not self.evolution:
541
            self.evolution = []
542
        elif (self.status == status and self.evolution[-1].status == status
543
              and not self.evolution[-1].comment
544
              and not self.evolution[-1].display_parts()):
545
            # if the status do not change and the last evolution is empty,
546
            # just update the last evolution time, do not add one
547
            self.evolution[-1].time = time.localtime()
548
            self.store()
549
            return
539 550
        evo = Evolution(self)
540 551
        evo.time = time.localtime()
541
        evo.status = 'wf-%s' % status_id
552
        evo.status = status
542 553
        if not self.evolution:
543 554
            self.evolution = []
544 555
        self.evolution.append(evo)
545
        self.status = evo.status
556
        self.status = status
546 557
        self.store()
547 558

  
548 559
    def get_url(self, backoffice = False):
549
-