コード例 #1
0
    def test_lastmod(self):
        attachment = AttachmentFileFactory(id=123)
        with freeze_time(datetime(2018, 4, 4, 12, 0, 1, tzinfo=pytz.utc)):
            attachment.title = 'title'
            attachment.save()

        attachment.refresh_from_db()

        expect(AttachmentSitemap().lastmod(attachment)).to.eq(
            datetime(2018, 4, 4, 12, 0, 1, tzinfo=pytz.utc))
コード例 #2
0
    def test_serialization(self):
        user = UserFactory(username='******')
        allegation = AllegationFactory(crid='456')
        attachment = AttachmentFileFactory(
            id=123,
            allegation=allegation,
            title='CR document',
            text_content='CHICAGO POLICE DEPARTMENT RD I HT334604',
            url='http://foo.com',
            preview_image_url=
            'https://assets.documentcloud.org/CRID-456-CR-p1-normal.gif',
            original_url=
            'https://www.documentcloud.org/documents/1-CRID-123456-CR.html',
            source_type='DOCUMENTCLOUD',
            show=True,
            file_type='document',
            pages=10,
            last_updated_by=user,
            views_count=100)
        attachment.created_at = datetime(2017,
                                         8,
                                         4,
                                         14,
                                         30,
                                         00,
                                         tzinfo=pytz.utc)
        with freeze_time('2017-08-05 12:00:01'):
            attachment.save()

        AttachmentFileFactory(
            id=124,
            allegation=allegation,
            show=True,
            file_type='document',
            preview_image_url=
            'https://assets.documentcloud.org/124/CRID-456-CR-p1-normal.gif',
            original_url=
            'https://www.documentcloud.org/documents/1-CRID-123-CR.html',
        )
        AttachmentFileFactory(
            id=125,
            allegation=allegation,
            show=True,
            file_type='document',
            preview_image_url=
            'https://assets.documentcloud.org/125/CRID-456-CR-p1-normal.gif',
            original_url=
            'https://www.documentcloud.org/documents/1-CRID-123-CR.html',
        )
        AttachmentFileFactory(
            id=126,
            allegation=allegation,
            show=False,
            file_type='document',
            preview_image_url=
            'https://assets.documentcloud.org/125/CRID-456-CR-p1-normal.gif',
            original_url=
            'https://www.documentcloud.org/documents/1-CRID-123-CR.html',
        )
        AttachmentFileFactory(
            id=127,
            allegation=allegation,
            show=True,
            file_type='audio',
            preview_image_url='',
            original_url='http://audio_link',
        )

        expected_data = {
            'id':
            123,
            'crid':
            '456',
            'title':
            'CR document',
            'text_content':
            'CHICAGO POLICE DEPARTMENT RD I HT334604',
            'url':
            'http://foo.com',
            'preview_image_url':
            'https://assets.documentcloud.org/CRID-456-CR-p1-normal.gif',
            'original_url':
            'https://www.documentcloud.org/documents/1-CRID-123456-CR.html',
            'created_at':
            '2017-08-04T09:30:00-05:00',
            'updated_at':
            '2017-08-05T07:00:01-05:00',
            'crawler_name':
            'Document Cloud',
            'linked_documents': [{
                'id':
                124,
                'preview_image_url':
                'https://assets.documentcloud.org/124/CRID-456-CR-p1-normal.gif',
            }, {
                'id':
                125,
                'preview_image_url':
                'https://assets.documentcloud.org/125/CRID-456-CR-p1-normal.gif',
            }],
            'pages':
            10,
            'last_updated_by':
            'test user'
        }

        data = AttachmentFileSerializer(attachment).data

        data['linked_documents'] = sorted(data['linked_documents'],
                                          key=itemgetter('id'))

        expect(data).to.eq(expected_data)