def test_enkel_initiele_status_met_scope_aanmaken(self): """ Met de scope zaken.aanmaken mag je enkel een status aanmaken als er nog geen status was. """ zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak_url = reverse('zaak-detail', kwargs={'uuid': zaak.uuid}) status_list_url = reverse('status-list') # initiele status response = self.client.post( status_list_url, { 'zaak': zaak_url, 'statusType': 'http://example.com/ztc/api/v1/catalogussen/1/zaaktypen/1/statustypen/1', 'datumStatusGezet': isodatetime(2018, 10, 1, 10, 00, 00), }) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # extra status - mag niet, onafhankelijk van de data response = self.client.post( status_list_url, { 'zaak': zaak_url, 'statusType': 'http://example.com/ztc/api/v1/catalogussen/1/zaaktypen/1/statustypen/1', 'datumStatusGezet': isodatetime(2018, 10, 2, 10, 00, 00), }) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(zaak.status_set.count(), 1)
def test_statustype_zaaktype_mismatch(self, *mocks): responses = { STATUSTYPE: { "url": STATUSTYPE, "zaaktype": "http://example.com/zaaktypen/1234", "volgnummer": 1, "isEindstatus": False, } } zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak_url = reverse("zaak-detail", kwargs={"uuid": zaak.uuid}) list_url = reverse("status-list") with mock_client(responses): response = self.client.post( list_url, { "zaak": zaak_url, "statustype": STATUSTYPE, "datumStatusGezet": isodatetime(2018, 10, 1, 10, 00, 00), }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "zaaktype-mismatch")
def test_statustype_valid_resource(self, *mocks): zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak_url = reverse("zaak-detail", kwargs={"uuid": zaak.uuid}) list_url = reverse("status-list") with mock_client(RESPONSES): response = self.client.post( list_url, { "zaak": zaak_url, "statustype": STATUSTYPE, "datumStatusGezet": isodatetime(2018, 10, 1, 10, 00, 00), }, ) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_zaak_afsluiten(self): zaak = ZaakFactory.create() zaak_url = reverse('zaak-detail', kwargs={'uuid': zaak.uuid}) status_list_url = reverse('status-list') token = generate_jwt([SCOPE_STATUSSEN_TOEVOEGEN]) self.client.credentials(HTTP_AUTHORIZATION=token) # Validate StatusTypes from Mock client ztc_mock_client = ZTCMockClient() status_type_1 = ztc_mock_client.retrieve('statustype', uuid=1) self.assertFalse(status_type_1['isEindstatus']) status_type_2 = ztc_mock_client.retrieve('statustype', uuid=2) self.assertTrue(status_type_2['isEindstatus']) # Set initial status response = self.client.post( status_list_url, { 'zaak': zaak_url, 'statusType': 'http://example.com/ztc/api/v1/catalogussen/1/zaaktypen/1/statustypen/1', 'datumStatusGezet': isodatetime(2018, 10, 1, 10, 00, 00), }) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content) zaak.refresh_from_db() self.assertIsNone(zaak.einddatum) # Set eindstatus datum_status_gezet = utcdatetime(2018, 10, 22, 10, 00, 00) response = self.client.post( status_list_url, { 'zaak': zaak_url, 'statusType': 'http://example.com/ztc/api/v1/catalogussen/1/zaaktypen/1/statustypen/2', 'datumStatusGezet': datum_status_gezet.isoformat(), }) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content) zaak.refresh_from_db() self.assertEqual(zaak.einddatum, datum_status_gezet.date())
def test_status_datum_status_gezet_cannot_be_in_future(self, *mocks): zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak_url = reverse("zaak-detail", kwargs={"uuid": zaak.uuid}) list_url = reverse("status-list") with mock_client(RESPONSES): response = self.client.post( list_url, { "zaak": zaak_url, "statustype": STATUSTYPE, "datumStatusGezet": isodatetime(2019, 7, 22, 13, 00, 00), }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) validation_error = get_validation_errors(response, "datumStatusGezet") self.assertEqual(validation_error["code"], "date-in-future")
def test_statustype_invalid_resource(self, *mocks): responses = {STATUSTYPE: {"some": "incorrect property"}} zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak_url = reverse("zaak-detail", kwargs={"uuid": zaak.uuid}) list_url = reverse("status-list") with mock_client(responses): response = self.client.post( list_url, { "zaak": zaak_url, "statustype": STATUSTYPE, "datumStatusGezet": isodatetime(2018, 10, 1, 10, 00, 00), }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "statustype") self.assertEqual(error["code"], "invalid-resource")
def test_zaak_afsluiten(self): zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak_url = reverse('zaak-detail', kwargs={'uuid': zaak.uuid}) responses = { RESULTAATTYPE: { 'url': RESULTAATTYPE, 'archiefactietermijn': 'P10Y', 'archiefnominatie': Archiefnominatie.blijvend_bewaren, 'brondatumArchiefprocedure': { 'afleidingswijze': BrondatumArchiefprocedureAfleidingswijze.afgehandeld, 'datumkenmerk': None, 'objecttype': None, 'procestermijn': None, } }, STATUSTYPE: { 'url': STATUSTYPE, 'volgnummer': 1, 'isEindstatus': False, }, STATUSTYPE2: { 'url': STATUSTYPE2, 'volgnummer': 2, 'isEindstatus': True, } } # Set initial status status_list_url = reverse('status-list') with mock_client(responses): response = self.client.post( status_list_url, { 'zaak': zaak_url, 'statusType': STATUSTYPE, 'datumStatusGezet': isodatetime(2018, 10, 1, 10, 00, 00), }) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content) zaak.refresh_from_db() self.assertIsNone(zaak.einddatum) # add a result for the case resultaat_create_url = get_operation_url('resultaat_create') data = { 'zaak': zaak_url, 'resultaatType': RESULTAATTYPE, 'toelichting': '', } response = self.client.post(resultaat_create_url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) # Set eindstatus datum_status_gezet = utcdatetime(2018, 10, 22, 10, 00, 00) with mock_client(responses): response = self.client.post( status_list_url, { 'zaak': zaak_url, 'statusType': STATUSTYPE2, 'datumStatusGezet': datum_status_gezet.isoformat(), }) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content) zaak.refresh_from_db() self.assertEqual(zaak.einddatum, datum_status_gezet.date()) self.assertEqual(zaak.archiefactiedatum, zaak.einddatum + relativedelta(years=10))