Example #1
0
 def test_datetime_parsing(self):
     """
     Run through a few different scenarios with datetime parsing.
     """
     pdtime = parse_datetime("2012-06-19T22:41:52+01:00")
     # dtime string had +1 tz offset. -1 gets us back to UTC. The parser
     # converts local times to UTC, so make sure this matches up.
     self.assertEqual(pdtime.hour, 21)
     # Make sure it converted to UTC.
     self.assertEqual(pdtime.tzinfo, UTC_TZINFO)
 def test_datetime_parsing(self):
     """
     Run through a few different scenarios with datetime parsing.
     """
     pdtime = parse_datetime("2012-06-19T22:41:52+01:00")
     # dtime string had +1 tz offset. -1 gets us back to UTC. The parser
     # converts local times to UTC, so make sure this matches up.
     self.assertEqual(pdtime.hour, 21)
     # Make sure it converted to UTC.
     self.assertEqual(pdtime.tzinfo, UTC_TZINFO)
def parse_from_dict(json_dict):
    """
    Given a Unified Uploader message, parse the contents and return a
    MarketHistoryList instance.

    :param dict json_dict: A Unified Uploader message as a dict.
    :rtype: MarketOrderList
    :returns: An instance of MarketOrderList, containing the orders
        within.
    """
    history_columns = json_dict['columns']

    history_list = MarketHistoryList(
        upload_keys=json_dict['uploadKeys'],
        history_generator=json_dict['generator'],
    )

    for rowset in json_dict['rowsets']:
        generated_at = parse_datetime(rowset['generatedAt'])
        region_id = rowset['regionID']
        type_id = rowset['typeID']
        history_list.set_empty_region(region_id, type_id, generated_at)

        for row in rowset['rows']:
            history_kwargs = _columns_to_kwargs(
                SPEC_TO_KWARG_CONVERSION, history_columns, row)
            historical_date = parse_datetime(history_kwargs['historical_date'])

            history_kwargs.update({
                'type_id': type_id,
                'region_id': region_id,
                'historical_date': historical_date,
                'generated_at': generated_at,
            })

            history_list.add_entry(MarketHistoryEntry(**history_kwargs))

    return history_list
def parse_from_dict(json_dict):
    """
    Given a Unified Uploader message, parse the contents and return a
    MarketHistoryList instance.

    :param dict json_dict: A Unified Uploader message as a dict.
    :rtype: MarketOrderList
    :returns: An instance of MarketOrderList, containing the orders
        within.
    """
    history_columns = json_dict['columns']

    history_list = MarketHistoryList(
        upload_keys=json_dict['uploadKeys'],
        history_generator=json_dict['generator'],
    )

    for rowset in json_dict['rowsets']:
        generated_at = parse_datetime(rowset['generatedAt'])
        region_id = rowset['regionID']
        type_id = rowset['typeID']
        history_list.set_empty_region(region_id, type_id, generated_at)

        for row in rowset['rows']:
            history_kwargs = _columns_to_kwargs(
                SPEC_TO_KWARG_CONVERSION, history_columns, row)
            historical_date = parse_datetime(history_kwargs['historical_date'])

            history_kwargs.update({
                'type_id': type_id,
                'region_id': region_id,
                'historical_date': historical_date,
                'generated_at': generated_at,
            })

            history_list.add_entry(MarketHistoryEntry(**history_kwargs))

    return history_list
Example #5
0
def parse_from_dict(json_dict):
    """
    Given a Unified Uploader message, parse the contents and return a
    MarketOrderList.

    :param dict json_dict: A Unified Uploader message as a JSON dict.
    :rtype: MarketOrderList
    :returns: An instance of MarketOrderList, containing the orders
        within.
    """
    order_columns = json_dict['columns']

    order_list = MarketOrderList(
        upload_keys=json_dict['uploadKeys'],
        order_generator=json_dict['generator'],
    )

    for rowset in json_dict['rowsets']:
        generated_at = parse_datetime(rowset['generatedAt'])
        region_id = rowset['regionID']
        type_id = rowset['typeID']
        order_list.set_empty_region(region_id, type_id, generated_at)

        for row in rowset['rows']:
            order_kwargs = _columns_to_kwargs(SPEC_TO_KWARG_CONVERSION,
                                              order_columns, row)
            order_kwargs.update({
                'region_id': region_id,
                'type_id': type_id,
                'generated_at': generated_at,
            })

            order_kwargs['order_issue_date'] = parse_datetime(
                order_kwargs['order_issue_date'])

            order_list.add_order(MarketOrder(**order_kwargs))

    return order_list
def parse_from_dict(json_dict):
    """
    Given a Unified Uploader message, parse the contents and return a
    MarketOrderList.

    :param dict json_dict: A Unified Uploader message as a JSON dict.
    :rtype: MarketOrderList
    :returns: An instance of MarketOrderList, containing the orders
        within.
    """
    order_columns = json_dict['columns']

    order_list = MarketOrderList(
        upload_keys=json_dict['uploadKeys'],
        order_generator=json_dict['generator'],
    )

    for rowset in json_dict['rowsets']:
        generated_at = parse_datetime(rowset['generatedAt'])
        region_id = rowset['regionID']
        type_id = rowset['typeID']
        order_list.set_empty_region(region_id, type_id, generated_at)

        for row in rowset['rows']:
            order_kwargs = _columns_to_kwargs(
                SPEC_TO_KWARG_CONVERSION, order_columns, row)
            order_kwargs.update({
                'region_id': region_id,
                'type_id': type_id,
                'generated_at': generated_at,
            })

            order_kwargs['order_issue_date'] = parse_datetime(order_kwargs['order_issue_date'])

            order_list.add_order(MarketOrder(**order_kwargs))

    return order_list
    def test_gen_iso_datetime_str(self):
        """
        Make sure gen_iso_datetime_str() is behaving correctly.
        """

        est = pytz.timezone("EST")
        some_date = datetime.datetime(
            year=1985, month=11, day=15,
            hour=6, minute=0,
            tzinfo=est)

        # Generate an ISO datetime string, and parse it. This will convert it
        # from EST to UTC.
        parsed_dtime = parse_datetime(gen_iso_datetime_str(some_date))
        # EST is -5, so the hour should now be 11.
        self.assertEqual(parsed_dtime.hour, 11)
        # tzinfo will be UTC, since we converted it upon parsing.
        self.assertIs(parsed_dtime.tzinfo, UTC_TZINFO)
Example #8
0
    def test_gen_iso_datetime_str(self):
        """
        Make sure gen_iso_datetime_str() is behaving correctly.
        """

        est = pytz.timezone("EST")
        some_date = datetime.datetime(year=1985,
                                      month=11,
                                      day=15,
                                      hour=6,
                                      minute=0,
                                      tzinfo=est)

        # Generate an ISO datetime string, and parse it. This will convert it
        # from EST to UTC.
        parsed_dtime = parse_datetime(gen_iso_datetime_str(some_date))
        # EST is -5, so the hour should now be 11.
        self.assertEqual(parsed_dtime.hour, 11)
        # tzinfo will be UTC, since we converted it upon parsing.
        self.assertIs(parsed_dtime.tzinfo, UTC_TZINFO)