コード例 #1
0
ファイル: tests.py プロジェクト: etalab/udata-gouvfr
 def feed(self, feed_title, title, content, url, published=None, summary=None,
          enclosure=None, media_thumbnail=None):
     feed = AtomFeed(feed_title, feed_url=WP_FEED_URL)
     tz = pytz.timezone(faker.timezone())
     published = published or faker.date_time(tzinfo=tz)
     kwargs = {
         'content_type': 'html',
         'author': faker.name(),
         'url': url,
         'updated': faker.date_time_between(start_date=published, tzinfo=tz),
         'published': published
     }
     if summary:
         kwargs['summary'] = summary
     if enclosure:
         kwargs['links'] = [{
             'type': enclosure['type'],
             'href': enclosure['url'],
             'rel': 'enclosure',
             'length': faker.pyint(),
         }]
     feed.add(title, content, **kwargs)
     out = feed.to_string()
     if media_thumbnail:
         el = '<media:thumbnail url="{0}" />'.format(media_thumbnail)
         out = out.replace('<feed', '<feed xmlns:media="http://search.yahoo.com/mrss/"')
         out = out.replace('</entry>', '{0}</entry>'.format(el))
     return out
コード例 #2
0
ファイル: tests.py プロジェクト: etalab/udata-gouvfr
    def feed(self, feed_title, title, content, url, published=None, summary=None,
             enclosure=None, media_thumbnail=None):
        feed = FeedGenerator()
        feed.title(feed_title)
        feed.description(faker.sentence())
        feed.link({'href': WP_FEED_URL})

        entry = feed.add_entry()
        entry.title(title)
        entry.link({'href': url})
        entry.author(name=faker.name())
        entry.content(content, type="cdata")
        if summary:
            entry.description(summary)
        if enclosure:
            entry.enclosure(url=enclosure['url'],
                            type=enclosure['type'],
                            length=str(faker.pyint()))
        if media_thumbnail:
            feed.load_extension('media')
            entry.media.thumbnail({'url': media_thumbnail})
        tz = pytz.timezone(faker.timezone())
        published = published or faker.date_time(tzinfo=tz)
        entry.published(published)
        entry.updated(faker.date_time_between(start_date=published, tzinfo=tz))

        return feed.rss_str().decode('utf8')
コード例 #3
0
ファイル: tests.py プロジェクト: quaxsze/udata-gouvfr
    def feed(self,
             feed_title,
             title,
             content,
             url,
             published=None,
             summary=None,
             enclosure=None,
             media_thumbnail=None):
        feed = FeedGenerator()
        feed.title(feed_title)
        feed.description(faker.sentence())
        feed.link({'href': WP_FEED_URL})

        entry = feed.add_entry()
        entry.title(title)
        entry.link({'href': url})
        entry.author(name=faker.name())
        entry.content(content, type="cdata")
        if summary:
            entry.description(summary)
        if enclosure:
            entry.enclosure(url=enclosure['url'],
                            type=enclosure['type'],
                            length=str(faker.pyint()))
        if media_thumbnail:
            feed.load_extension('media')
            entry.media.thumbnail({'url': media_thumbnail})
        tz = pytz.timezone(faker.timezone())
        published = published or faker.date_time(tzinfo=tz)
        entry.published(published)
        entry.updated(faker.date_time_between(start_date=published, tzinfo=tz))

        return feed.rss_str().decode('utf8')
コード例 #4
0
 def feed(self, feed_title, title, content, url, published=None, summary=None,
          enclosure=None, media_thumbnail=None):
     feed = AtomFeed(feed_title, feed_url=WP_FEED_URL)
     tz = pytz.timezone(faker.timezone())
     published = published or faker.date_time(tzinfo=tz)
     kwargs = {
         'content_type': 'html',
         'author': faker.name(),
         'url': url,
         'updated': faker.date_time_between(start_date=published, tzinfo=tz),
         'published': published
     }
     if summary:
         kwargs['summary'] = summary
     if enclosure:
         kwargs['links'] = [{
             'type': enclosure['type'],
             'href': enclosure['url'],
             'rel': 'enclosure',
             'length': faker.pyint(),
         }]
     feed.add(title, content, **kwargs)
     out = feed.to_string()
     if media_thumbnail:
         el = '<media:thumbnail url="{0}" />'.format(media_thumbnail)
         out = out.replace('<feed', '<feed xmlns:media="http://search.yahoo.com/mrss/"')
         out = out.replace('</entry>', '{0}</entry>'.format(el))
     return out
コード例 #5
0
    def test_render_display_with_siblings(self, client, templates):
        '''It should render the post page with sibling links'''
        previous_date = faker.date_time_between(start_date='-3d',
                                                end_date='-2d')
        date = faker.date_time_between(start_date='-2d', end_date='-1d')
        next_date = faker.date_time_between(start_date='-1d', end_date='now')
        other_date = faker.date_time_between(start_date='-1y', end_date='-3d')

        previous_post = PostFactory(published=previous_date)
        post = PostFactory(published=date)
        next_post = PostFactory(published=next_date)
        PostFactory.create_batch(3, published=other_date)

        response = client.get(url_for('posts.show', post=post))

        assert200(response)
        assert templates.get_context_variable('previous_post') == previous_post
        assert templates.get_context_variable('next_post') == next_post
コード例 #6
0
ファイル: test_frontend.py プロジェクト: odtvince/udata
    def test_render_display_with_siblings(self, client, templates):
        '''It should render the post page with sibling links'''
        previous_date = faker.date_time_between(start_date='-3d',
                                                end_date='-2d')
        date = faker.date_time_between(start_date='-2d', end_date='-1d')
        next_date = faker.date_time_between(start_date='-1d', end_date='now')
        other_date = faker.date_time_between(start_date='-1y', end_date='-3d')

        previous_post = PostFactory(published=previous_date)
        post = PostFactory(published=date)
        next_post = PostFactory(published=next_date)
        PostFactory.create_batch(3, published=other_date)

        response = client.get(url_for('posts.show', post=post))

        assert200(response)
        assert templates.get_context_variable('previous_post') == previous_post
        assert templates.get_context_variable('next_post') == next_post
コード例 #7
0
    def test_render_display_with_siblings(self):
        '''It should render the post page with sibling links'''
        previous_date = faker.date_time_between(start_date='-3d',
                                                end_date='-2d')
        date = faker.date_time_between(start_date='-2d', end_date='-1d')
        next_date = faker.date_time_between(start_date='-1d', end_date='now')
        other_date = faker.date_time_between(start_date='-1y', end_date='-3d')

        previous_post = PostFactory(created_at=previous_date)
        post = PostFactory(created_at=date)
        next_post = PostFactory(created_at=next_date)
        PostFactory.create_batch(3, created_at=other_date)

        response = self.get(url_for('posts.show', post=post))

        self.assert200(response)
        self.assertEqual(self.get_context_variable('previous_post'),
                         previous_post)
        self.assertEqual(self.get_context_variable('next_post'), next_post)
コード例 #8
0
ファイル: test_ckan_backend.py プロジェクト: seiteta/udata
def tag_factory(tag):
    timestamp = faker.date_time_between(start_date='-1y', end_date='-1d')
    return {
        "id": str(uuid4()),
        "vocabulary_id": None,
        "display_name": tag,
        "name": tag,
        "revision_timestamp": timestamp.isoformat(),
        "state": "active",
    }
コード例 #9
0
    def test_dont_overwrite_last_modified(self, mocker):
        last_modified = faker.date_time_between(start_date='-30y',
                                                end_date='-1y')
        source = HarvestSourceFactory(config={
            'nb_datasets': 1,
            'last_modified': last_modified
        })
        backend = FakeBackend(source)

        backend.harvest()

        dataset = Dataset.objects.first()

        assert dataset.last_modified == last_modified
        harvest_last_update = parse(dataset.extras['harvest:last_update'])
        assert_equal_dates(harvest_last_update, datetime.now())
コード例 #10
0
    def test_all_resource_fields(self):
        node = BNode()
        g = Graph()

        title = faker.sentence()
        url = faker.uri()
        description = faker.paragraph()
        filesize = faker.pyint()
        issued = faker.date_time_between(start_date='-60d', end_date='-30d')
        modified = faker.past_datetime(start_date='-30d')
        mime = faker.mime_type()
        sha1 = faker.sha1()

        g.add((node, RDF.type, DCAT.Distribution))
        g.add((node, DCT.title, Literal(title)))
        g.add((node, DCT.description, Literal(description)))
        g.add((node, DCAT.downloadURL, Literal(url)))
        g.add((node, DCT.issued, Literal(issued)))
        g.add((node, DCT.modified, Literal(modified)))
        g.add((node, DCAT.bytesSize, Literal(filesize)))
        g.add((node, DCAT.mediaType, Literal(mime)))
        g.add((node, DCT.term('format'), Literal('CSV')))

        checksum = BNode()
        g.add((node, SPDX.checksum, checksum))
        g.add((checksum, RDF.type, SPDX.Checksum))
        g.add((checksum, SPDX.algorithm, SPDX.checksumAlgorithm_sha1))
        g.add((checksum, SPDX.checksumValue, Literal(sha1)))

        resource = resource_from_rdf(g)
        resource.validate()

        assert isinstance(resource, Resource)
        assert resource.title == title
        assert resource.url == url
        assert resource.description == description
        assert resource.filesize == filesize
        assert resource.mime == mime
        assert isinstance(resource.checksum, Checksum)
        assert resource.checksum.type == 'sha1'
        assert resource.checksum.value == sha1
        assert resource.published == issued
        assert resource.modified == modified
        assert resource.format == 'csv'
コード例 #11
0
ファイル: test_ckan_backend.py プロジェクト: seiteta/udata
def package_show_factory(name):
    org_id = str(uuid4())
    created = faker.date_time_between(start_date='-3y', end_date='-7d')
    updated = faker.date_time_between(start_date='-7d', end_date='now')
    nb_resources = faker.randomize_nb_elements(4)
    nb_tags = faker.randomize_nb_elements(10)
    return {
        "help": "",
        "success": True,
        "result": {
            "license_title":
            "Licence ouverte / Open license (Etalab)",
            "maintainer":
            None,
            "relationships_as_object": [],
            "private":
            False,
            "maintainer_email":
            None,
            "revision_timestamp":
            updated.isoformat(),
            "id":
            str(uuid4()),
            "metadata_created":
            created.isoformat(),
            "owner_org":
            org_id,
            "metadata_modified":
            updated.isoformat(),
            "author":
            None,
            "author_email":
            None,
            "state":
            "active",
            "version":
            None,
            "license_id":
            "lool",
            "type":
            "dataset",
            "resources": [resource_factory() for _ in range(nb_resources)],
            "num_resources":
            nb_resources,
            "tags": [tag_factory(faker.word()) for _ in range(nb_tags)],
            "tracking_summary": {
                "total": 0,
                "recent": 0
            },
            "groups": [{
                "title": " Actions Région",
                "description":
                "Les actions régionales, l'agriculture, l'aménagement du territoire...",  # noqa
                "name": "actions-region",
                "id": "7859d498-316e-4a31-8487-f7f26df0929e"
            }],
            "relationships_as_subject": [],
            "num_tags":
            nb_tags,
            "name":
            faker.slug(),
            "isopen":
            False,
            "url":
            None,
            "notes":
            faker.paragraph(),
            "title":
            faker.sentence(),
            "extras": [{
                "value": "01/08/2013",
                "key": "date",
                "__extras": {
                    "package_id": "f9f07d12-f810-4cb5-b3c0-52d7b1130c2e",
                    "revision_id": "e108a7c6-0e5f-4714-a8e6-68162c69ae68"
                }
            }, {
                "value": "Annuelle",
                "key": "freqMAJ",
                "__extras": {
                    "revision_id": "e108a7c6-0e5f-4714-a8e6-68162c69ae68",
                    "package_id": "f9f07d12-f810-4cb5-b3c0-52d7b1130c2e"
                }
            }],
            "license_url":
            "http://www.etalab.gouv.fr/pages/Licence_ouverte_Open_licence-5899923.html",  # noqa
            "organization": {
                "description": "",
                "created": "2013-07-18T11:25:15.969631",
                "title": "Conseil Régional Nord-Pas de Calais",
                "name": "conseil-regional-nord-pas-de-calais",
                "revision_timestamp": "2013-07-29T15:25:28.634142",
                "is_organization": True,
                "state": "active",
                "image_url": "/images/npdc-icon.png",
                "revision_id": str(uuid4()),
                "type": "organization",
                "id": org_id,
                "approval_status": "approved"
            },
            "revision_id":
            str(uuid4())
        }
    }