当前位置: 首页>>代码示例>>Python>>正文


Python utils.isoformat函数代码示例

本文整理汇总了Python中marshmallow.utils.isoformat函数的典型用法代码示例。如果您正苦于以下问题:Python isoformat函数的具体用法?Python isoformat怎么用?Python isoformat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isoformat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_committee_date_filters

 def test_committee_date_filters(self):
     [
         factories.CommitteeFactory(first_file_date=datetime.datetime(2015, 1, 1)),
         factories.CommitteeFactory(first_file_date=datetime.datetime(2015, 2, 1)),
         factories.CommitteeFactory(first_file_date=datetime.datetime(2015, 3, 1)),
         factories.CommitteeFactory(first_file_date=datetime.datetime(2015, 4, 1)),
     ]
     results = self._results(api.url_for(CommitteeList, min_first_file_date='02/01/2015'))
     self.assertTrue(all(each['first_file_date'] >= isoformat(datetime.datetime(2015, 2, 1)) for each in results))
     results = self._results(api.url_for(CommitteeList, max_first_file_date='02/03/2015'))
     self.assertTrue(all(each['first_file_date'] <= isoformat(datetime.datetime(2015, 3, 1)) for each in results))
     results = self._results(
         api.url_for(
             CommitteeList,
             min_first_file_date='02/01/2015',
             max_first_file_date='02/03/2015',
         )
     )
     self.assertTrue(
         all(
             isoformat(datetime.datetime(2015, 2, 1))
             <= each['first_file_date']
             <= isoformat(datetime.datetime(2015, 3, 1))
             for each in results
         )
     )
开发者ID:EricSchles,项目名称:openFEC,代码行数:26,代码来源:committee_tests.py

示例2: _check_reports

 def _check_reports(self, committee_type, factory, schema):
     committee = factories.CommitteeFactory(committee_type=committee_type)
     factories.CommitteeHistoryFactory(
         committee_id=committee.committee_id,
         committee_key=committee.committee_key,
         committee_type=committee_type,
         cycle=2012,
     )
     end_dates = [datetime.datetime(2012, 1, 1), datetime.datetime(2008, 1, 1)]
     committee_id = committee.committee_id
     committee_key = committee.committee_key
     db.session.flush()
     [
         factory(
             committee_id=committee_id,
             committee_key=committee_key,
             coverage_end_date=end_date,
             report_year=2011,
         )
         for end_date in end_dates
     ]
     response = self._results(api.url_for(ReportsView, committee_id=committee_id))
     self.assertEqual(len(response), 2)
     self.assertEqual(response[0]['coverage_end_date'], isoformat(end_dates[0]))
     self.assertEqual(response[1]['coverage_end_date'], isoformat(end_dates[1]))
     assert response[0].keys() == schema().fields.keys()
开发者ID:srinivasmalladi,项目名称:openFEC,代码行数:26,代码来源:test_reports.py

示例3: test_meta_serializer_fields

def test_meta_serializer_fields():
    u = User("John", age=42.3, email="[email protected]",
             homepage="http://john.com")
    s = UserMetaSchema().dump(u)
    assert s.data['name'] == u.name
    assert s.data['balance'] == "100.00"
    assert s.data['uppername'] == "JOHN"
    assert s.data['is_old'] is False
    assert s.data['created'] == utils.isoformat(u.created)
    assert s.data['updated_local'] == utils.isoformat(u.updated, localtime=True)
    assert s.data['finger_count'] == 10
开发者ID:svenstaro,项目名称:marshmallow,代码行数:11,代码来源:test_schema.py

示例4: get

    def get(self, task_id=None):
        user = self.get_current_user()
        c = self.db.cursor()
        if task_id:
            # Get one task
            c.execute(
                'SELECT * FROM tasks WHERE id = ? AND user_id = ?',
                (task_id, user['id'],)
            )
        else:
            # List of user's tasks
            c.execute(
                'SELECT * FROM tasks WHERE user_id = ? ORDER BY created DESC',
                (user['id'], )
            )

        tasks = [dict(zip(t.keys(), t)) for t in c.fetchall()]

        if task_id and len(tasks) > 1:
            self.send_error(500,
                            message='Founded multiple tasks with the same ID.')
            return
        elif task_id and not tasks:
            self.send_error(400, message='Task is not found.')
            return

        for task in tasks:
            task['result'] = json_decode(task['result'])
            task['status'] = TaskStatus(task['status']).name
            for date_field in ('created', 'started', 'finished'):
                if task[date_field]:
                    task[date_field] = isoformat(task[date_field])
        self.finish(json_encode(tasks[0] if task_id else tasks))
开发者ID:vovanbo,项目名称:vm-manager-proto,代码行数:33,代码来源:tasks.py

示例5: test_candidate

    def test_candidate(self):
        """Compare results to expected fields."""
        candidate_old = factories.CandidateDetailFactory(
            load_date=datetime.datetime(2014, 1, 2),
            **fields
        )
        candidate = factories.CandidateDetailFactory(
            load_date=datetime.datetime(2014, 1, 3),
            **fields
        )
        response = self._response(
            api.url_for(CandidateView, candidate_id=candidate.candidate_id)
        )
        self.assertResultsEqual(
            response['pagination'],
            {'count': 1, 'page': 1, 'pages': 1, 'per_page': 20})
        # we are showing the full history rather than one result
        self.assertEqual(len(response['results']), 1)

        result = response['results'][0]
        self.assertEqual(result['candidate_id'], candidate.candidate_id)
        self.assertEqual(result['form_type'], 'F2')
        # @todo - check for a value for expire_data
        self.assertEqual(result['expire_date'], None)
        # # most recent record should be first
        self.assertEqual(result['load_date'], isoformat(candidate.load_date))
        self.assertNotEqual(result['load_date'], isoformat(candidate_old.load_date))
        self.assertResultsEqual(result['name'], candidate.name)
        # #address
        self.assertEqual(result['address_city'], candidate.address_city)
        self.assertEqual(result['address_state'], candidate.address_state)
        self.assertEqual(result['address_street_1'], candidate.address_street_1)
        self.assertEqual(result['address_zip'], candidate.address_zip)
        # # office
        self.assertResultsEqual(result['office'], candidate.office)
        self.assertResultsEqual(result['district'], candidate.district)
        self.assertResultsEqual(result['state'], candidate.state)
        self.assertResultsEqual(result['office_full'], candidate.office_full)
        # # From party_mapping
        self.assertResultsEqual(result['party'], candidate.party)
        self.assertResultsEqual(result['party_full'], candidate.party_full)
        # From status_mapping
        self.assertResultsEqual(result['active_through'], candidate.active_through)
        self.assertResultsEqual(result['candidate_inactive'], candidate.candidate_inactive)
        self.assertResultsEqual(result['candidate_status'], candidate.candidate_status)
        self.assertResultsEqual(result['incumbent_challenge'], candidate.incumbent_challenge)
        self.assertResultsEqual(result['candidate_status_full'], candidate.candidate_status_full)
开发者ID:srinivasmalladi,项目名称:openFEC,代码行数:47,代码来源:test_candidates.py

示例6: isoformat

def isoformat(dt, localtime=False, *args, **kwargs):
    """ISO8601-formatted UTC representation of a datetime object.
    The timezone offset portion of the string will be replaced with a "Z" if the UTC offset is 0.
    """
    value = ma_utils.isoformat(dt, localtime=localtime, *args, **kwargs)
    if value.endswith('+00:00'):
        return "{}Z".format(value[:-6])
    return value
开发者ID:Catalant,项目名称:ct-flask-api-breakout,代码行数:8,代码来源:json_utils.py

示例7: __repr__

 def __repr__(self):
     return ('<User id={id}, name={name}, created_at={created_at}, '
             'creator_email={creator_email}, contacts=[{contacts}]>').format(
                 id=self.id,
                 name=self.name,
                 created_at=utils.isoformat(self.created_at),
                 creator_email=self.creator_email,
                 contacts=', '.join((repr(c) for c in self.contacts)))
开发者ID:croshchupkin,项目名称:fooapi,代码行数:8,代码来源:models.py

示例8: test_default_dateformat

def test_default_dateformat(user):
    class DateFormatSchema(Schema):
        updated = fields.DateTime(format="%m-%d")

        class Meta:
            fields = ('created', 'updated')
    serialized = DateFormatSchema().dump(user)
    assert serialized.data['created'] == utils.isoformat(user.created)
    assert serialized.data['updated'] == user.updated.strftime("%m-%d")
开发者ID:svenstaro,项目名称:marshmallow,代码行数:9,代码来源:test_schema.py

示例9: test_get

 def test_get(self, wt):
     author = AuthorFactory()
     url = url_for('books.AuthorDetail:get', id=author.id)
     res = wt.get(url)
     assert res.status_code == http.OK
     data = res.json['result']
     assert data['first'] == author.first
     assert data['last'] == author.last
     assert data['created'] == isoformat(author.date_created)
     assert 'books' in data
开发者ID:sloria,项目名称:scribnote,代码行数:10,代码来源:test_api.py

示例10: test_filter_date

 def test_filter_date(self):
     [
         factories.FilingsFactory(receipt_date=datetime.datetime(2012, 1, 1)),
         factories.FilingsFactory(receipt_date=datetime.datetime(2013, 1, 1)),
         factories.FilingsFactory(receipt_date=datetime.datetime(2014, 1, 1)),
         factories.FilingsFactory(receipt_date=datetime.datetime(2015, 1, 1)),
     ]
     min_date = datetime.datetime(2013, 1, 1)
     results = self._results(api.url_for(FilingsList, min_receipt_date=min_date))
     self.assertTrue(all(each for each in results if each['receipt_date'] >= isoformat(min_date)))
     max_date = datetime.datetime(2014, 1, 1)
     results = self._results(api.url_for(FilingsList, max_receipt_date=max_date))
     self.assertTrue(all(each for each in results if each['receipt_date'] <= isoformat(max_date)))
     results = self._results(api.url_for(FilingsList, min_receipt_date=min_date, max_receipt_date=max_date))
     self.assertTrue(
         all(
             each for each in results
             if isoformat(min_date) <= each['receipt_date'] <= isoformat(max_date)
         )
     )
开发者ID:EricSchles,项目名称:openFEC,代码行数:20,代码来源:filings_tests.py

示例11: test_committee_detail_fields

 def test_committee_detail_fields(self):
     committee = factories.CommitteeDetailFactory(
         first_file_date=datetime.datetime(1982, 12, 31),
         committee_type="P",
         treasurer_name="Robert J. Lipshutz",
         party="DEM",
         form_type="F1Z",
         load_date=datetime.datetime(1982, 12, 31),
         street_1="1795 Peachtree Road",
         zip="30309",
     )
     response = self._response(api.url_for(CommitteeView, committee_id=committee.committee_id))
     result = response["results"][0]
     # main fields
     self.assertEqual(result["first_file_date"], isoformat(committee.first_file_date))
     self.assertEqual(result["committee_type"], committee.committee_type)
     self.assertEqual(result["treasurer_name"], committee.treasurer_name)
     self.assertEqual(result["party"], committee.party)
     # Things on the detailed view
     self.assertEqual(result["form_type"], committee.form_type)
     self.assertEqual(result["load_date"], isoformat(committee.load_date))
     self.assertEqual(result["street_1"], committee.street_1)
     self.assertEqual(result["zip"], committee.zip)
开发者ID:LetsUnlockiPhone,项目名称:openFEC,代码行数:23,代码来源:committee_tests.py

示例12: test_committee_list_fields

 def test_committee_list_fields(self):
     committee = factories.CommitteeFactory(
         first_file_date=datetime.datetime(1982, 12, 31),
         committee_type="P",
         treasurer_name="Robert J. Lipshutz",
         party="DEM",
     )
     response = self._response(api.url_for(CommitteeView, committee_id=committee.committee_id))
     result = response["results"][0]
     # main fields
     # original registration date doesn't make sense in this example, need to look into this more
     self.assertEqual(result["first_file_date"], isoformat(committee.first_file_date))
     self.assertEqual(result["committee_type"], committee.committee_type)
     self.assertEqual(result["treasurer_name"], committee.treasurer_name)
     self.assertEqual(result["party"], committee.party)
开发者ID:LetsUnlockiPhone,项目名称:openFEC,代码行数:15,代码来源:committee_tests.py

示例13: test_reports_sort_default

 def test_reports_sort_default(self):
     committee = factories.CommitteeFactory(committee_type='H')
     committee_id = committee.committee_id
     factories.CommitteeHistoryFactory(
         committee_id=committee_id,
         committee_type='H',
     )
     dates = [
         datetime.datetime(2015, 7, 4),
         datetime.datetime(2015, 7, 5),
     ]
     dates_formatted = [isoformat(each) for each in dates]
     factories.ReportsHouseSenateFactory(committee_id=committee_id, coverage_end_date=dates[0])
     factories.ReportsHouseSenateFactory(committee_id=committee_id, coverage_end_date=dates[1])
     results = self._results(api.url_for(ReportsView, committee_id=committee_id))
     self.assertEqual([each['coverage_end_date'] for each in results], dates_formatted[::-1])
开发者ID:mulchy,项目名称:openFEC,代码行数:16,代码来源:test_reports.py

示例14: test_datetime_iso8601

 def test_datetime_iso8601(self, fmt, user):
     field = fields.DateTime(format=fmt)
     expected = utils.isoformat(user.created, localtime=False)
     assert field.serialize("created", user) == expected
开发者ID:Ch00k,项目名称:marshmallow,代码行数:4,代码来源:test_serialization.py

示例15: test_datetime_deserializes_to_iso_by_default

 def test_datetime_deserializes_to_iso_by_default(self, user):
     field = fields.DateTime()  # No format specified
     expected = utils.isoformat(user.created, localtime=False)
     assert field.serialize("created", user) == expected
开发者ID:Ch00k,项目名称:marshmallow,代码行数:4,代码来源:test_serialization.py


注:本文中的marshmallow.utils.isoformat函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。