Projet

Général

Profil

0001-foederis-remove-deleted-announces-66506.patch

Nicolas Roche, 24 juin 2022 13:33

Télécharger (2,89 ko)

Voir les différences:

Subject: [PATCH] foederis: remove deleted announces (#66506)

 passerelle/contrib/toulouse_foederis/models.py | 3 +++
 tests/test_toulouse_foederis.py                | 8 ++++++++
 2 files changed, 11 insertions(+)
passerelle/contrib/toulouse_foederis/models.py
153 153
            else:
154 154
                self.logger.info(_('Updated announce %s') % announce_id)
155 155

  
156 156
    def update_announces(self):
157 157
        try:
158 158
            results = self.http_request('GET', 'data/annonce?viewIntegrationName=api_publik')
159 159
        except requests.RequestException:
160 160
            raise UpdateError(_('Service is unavailable'))
161
        announces = []
161 162
        for response_announce in results:
162 163
            self.update_announce(response_announce)
164
            announces.append('announce-%s' % response_announce['id'])
165
        self.announces_documents.exclude(external_id__in=announces).delete()
163 166

  
164 167
    REFERENTIELS = [
165 168
        # document_id, path
166 169
        ('type_emploi', 'type_emploi'),
167 170
        ('categorie', 'categorie1'),
168 171
        ('filiere', 'Filiere'),
169 172
    ]
170 173

  
tests/test_toulouse_foederis.py
126 126
        annonce = get_json_content('annonce')
127 127
        annonce['results'][0]['intitule_annonce'] = 'COIN'
128 128
        with mock_url(url=r'.*annonce$', response=json.dumps(annonce)):
129 129
            resource.hourly()
130 130
            assert 'Created' not in caplog.text
131 131
            assert 'Updated announce 3450231' in caplog.text
132 132
            assert 'Referentials updated.' in caplog.text
133 133

  
134
        # remove announce deleted from foederis
135
        assert Document.objects.filter(external_id__startswith='announce-').count() == 5
136
        annonce = get_json_content('annonce')
137
        del annonce['results'][4]
138
        with mock_url(url=r'.*annonce$', response=json.dumps(annonce)):
139
            resource.hourly()
140
        assert Document.objects.filter(external_id__startswith='announce-').count() == 4
141

  
134 142
    def test_loaded_pdf(self, resource, http_mock):
135 143
        resource.hourly()
136 144
        assert Document.objects.filter(external_id__startswith='announce-', pdf='').count() == 0
137 145
        document = Document.objects.get(external_id='announce-4229013')
138 146
        with document.pdf.open(mode='rb') as fd:
139 147
            assert fd.read() == base64.b64decode(
140 148
                HTTP_MOCKS['pdf']['content']['results'][0]['pdf_ddr']['fileData']
141 149
            )
142
-