def test_contains(self):
        """
        Tests the __contains__ method via the 'in' Python keyword.

        __contains__ lookup is based on the order ID, unlike market history,
        which is based off of type ID.
        """
        order_list = MarketOrderList()
        # Order isn't there yet, so this Order ID shouldn't be found.
        self.assertFalse(2413387906 in order_list)
        new_order = MarketOrder(
            order_id=2413387906,
            is_bid=True,
            region_id=10000068,
            solar_system_id=30005316,
            station_id=60011521,
            type_id=10000068,
            price=52875,
            volume_entered=10,
            volume_remaining=4,
            minimum_volume=1,
            order_issue_date=now_dtime_in_utc(),
            order_duration=90,
            order_range=5,
            generated_at=now_dtime_in_utc()
        )
        # Add an order to search for.
        order_list.add_order(new_order)
        # Search by order ID.
        self.assertTrue(2413387906 in order_list)
        # Use the MarketOrder instead of the order ID int.
        self.assertTrue(new_order in order_list)
Esempio n. 2
0
    def setUp(self):
        self.order_list = MarketOrderList()
        self.order1 = MarketOrder(order_id=2413387906,
                                  is_bid=True,
                                  region_id=10000068,
                                  solar_system_id=30005316,
                                  station_id=60011521,
                                  type_id=10000068,
                                  price=52875,
                                  volume_entered=10,
                                  volume_remaining=4,
                                  minimum_volume=1,
                                  order_issue_date=now_dtime_in_utc(),
                                  order_duration=90,
                                  order_range=5,
                                  generated_at=now_dtime_in_utc())
        self.order_list.add_order(self.order1)
        # This order isn't added, but it's here for the test to add.
        self.order2 = MarketOrder(order_id=1234566,
                                  is_bid=False,
                                  region_id=10000032,
                                  solar_system_id=30005312,
                                  station_id=60011121,
                                  type_id=10000067,
                                  price=52,
                                  volume_entered=10,
                                  volume_remaining=500,
                                  minimum_volume=1,
                                  order_issue_date=now_dtime_in_utc(),
                                  order_duration=90,
                                  order_range=5,
                                  generated_at=now_dtime_in_utc())

        self.history = MarketHistoryList()
        self.history1 = MarketHistoryEntry(
            type_id=2413387906,
            region_id=10000068,
            historical_date=now_dtime_in_utc(),
            num_orders=5,
            low_price=5.0,
            high_price=10.5,
            average_price=7.0,
            total_quantity=200,
            generated_at=now_dtime_in_utc(),
        )
        self.history.add_entry(self.history1)
        # This order isn't added, but it's here for the test to add.
        self.history2 = MarketHistoryEntry(
            type_id=1413387203,
            region_id=10000067,
            historical_date=now_dtime_in_utc(),
            num_orders=50,
            low_price=50.0,
            high_price=100.5,
            average_price=70.0,
            total_quantity=2000,
            generated_at=now_dtime_in_utc(),
        )
def serialize_orders(doc_dict, region_data):
    """
    Serializes a GetOrders cache file's contents.

    :param dict doc_dict: The parsed cache document in dict form.
    :rtype: str
    :returns: The UUDIF serialized JSON message.
    """
    order_list = MarketOrderList(
        order_generator=ORDER_GENERATOR,
        upload_keys=UPLOAD_KEYS,
    )
    # timezone-aware datetime.
    generated_at = now_dtime_in_utc()
    region_id = region_data[2]
    type_id = region_data[3]

    for order_item in doc_dict['lret']:
        #print order_item
        for entry in order_item:
            #print entry
            order = MarketOrder(
                order_id=entry['orderID'],
                is_bid=entry['bid'],
                region_id=entry['regionID'],
                solar_system_id=entry['solarSystemID'],
                station_id=entry['stationID'],
                type_id=entry['typeID'],
                price=entry['price'],
                volume_entered=entry['volEntered'],
                volume_remaining=entry['volRemaining'],
                minimum_volume=entry['minVolume'],
                order_issue_date=wintime_to_datetime(entry['issueDate']),
                order_duration=entry['duration'],
                order_range=entry['range'],
                generated_at=generated_at,
            )
            order_list.add_order(order)

    if len(order_list) is 0:
        # There were no orders for this item+region combo.
        order_list.set_empty_region(region_id, type_id, generated_at)

    return encode_to_json(order_list)
 def setUp(self):
     self.order1 = MarketOrder(
         order_id=2413387906,
         is_bid=True,
         region_id=10000068,
         solar_system_id=30005316,
         station_id=60011521,
         type_id=10000068,
         price=52875.0,
         volume_entered=10,
         volume_remaining=4,
         minimum_volume=1,
         order_issue_date=datetime.datetime.utcnow(),
         order_duration=90,
         order_range=5,
         generated_at=datetime.datetime.utcnow(),
     )
     self.order_list = MarketOrderList()
     self.order_list.add_order(self.order1)
class GatewayWSGITests(unittest.TestCase):
    """
    Various tests for the gateway WSGI application.
    """
    def setUp(self):
        self.order1 = MarketOrder(
            order_id=2413387906,
            is_bid=True,
            region_id=10000068,
            solar_system_id=30005316,
            station_id=60011521,
            type_id=10000068,
            price=52875.0,
            volume_entered=10,
            volume_remaining=4,
            minimum_volume=1,
            order_issue_date=datetime.datetime.utcnow(),
            order_duration=90,
            order_range=5,
            generated_at=datetime.datetime.utcnow(),
        )
        self.order_list = MarketOrderList()
        self.order_list.add_order(self.order1)
class GatewayWSGITests(unittest.TestCase):
    """
    Various tests for the gateway WSGI application.
    """
    def setUp(self):
        self.order1 = MarketOrder(
            order_id=2413387906,
            is_bid=True,
            region_id=10000068,
            solar_system_id=30005316,
            station_id=60011521,
            type_id=10000068,
            price=52875.0,
            volume_entered=10,
            volume_remaining=4,
            minimum_volume=1,
            order_issue_date=datetime.datetime.utcnow(),
            order_duration=90,
            order_range=5,
            generated_at=datetime.datetime.utcnow(),
        )
        self.order_list = MarketOrderList()
        self.order_list.add_order(self.order1)
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 setUp(self):
     self.order1 = MarketOrder(
         order_id=2413387906,
         is_bid=True,
         region_id=10000068,
         solar_system_id=30005316,
         station_id=60011521,
         type_id=10000068,
         price=52875.0,
         volume_entered=10,
         volume_remaining=4,
         minimum_volume=1,
         order_issue_date=datetime.datetime.utcnow(),
         order_duration=90,
         order_range=5,
         generated_at=datetime.datetime.utcnow(),
     )
     self.order_list = MarketOrderList()
     self.order_list.add_order(self.order1)
def serialize_orders(doc_dict, region_data):
    """
    Serializes a GetOrders cache file's contents.

    :param dict doc_dict: The parsed cache document in dict form.
    :rtype: str
    :returns: The UUDIF serialized JSON message.
    """
    order_list = MarketOrderList(
        order_generator=ORDER_GENERATOR,
        upload_keys=UPLOAD_KEYS,
    )
    # timezone-aware datetime.
    generated_at = now_dtime_in_utc()
    region_id = region_data[2]
    type_id = region_data[3]

    for order_item in doc_dict['lret']:
        #print order_item
        for entry in order_item:
            #print entry
            order = MarketOrder(
                order_id=entry['orderID'],
                is_bid=entry['bid'],
                region_id=entry['regionID'],
                solar_system_id=entry['solarSystemID'],
                station_id=entry['stationID'],
                type_id=entry['typeID'],
                price=entry['price'],
                volume_entered=entry['volEntered'],
                volume_remaining=entry['volRemaining'],
                minimum_volume=entry['minVolume'],
                order_issue_date=wintime_to_datetime(entry['issueDate']),
                order_duration=entry['duration'],
                order_range=entry['range'],
                generated_at=generated_at,
            )
            order_list.add_order(order)

    if len(order_list) is 0:
        # There were no orders for this item+region combo.
        order_list.set_empty_region(region_id, type_id, generated_at)

    return encode_to_json(order_list)
Esempio n. 10
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
Esempio n. 11
0
class BaseSerializationCase(unittest.TestCase):
    """
    This is a base class that provides some convenient test data for the
    various formats to use in their respective unit tests.
    """
    def setUp(self):
        self.order_list = MarketOrderList()
        self.order1 = MarketOrder(order_id=2413387906,
                                  is_bid=True,
                                  region_id=10000068,
                                  solar_system_id=30005316,
                                  station_id=60011521,
                                  type_id=10000068,
                                  price=52875,
                                  volume_entered=10,
                                  volume_remaining=4,
                                  minimum_volume=1,
                                  order_issue_date=now_dtime_in_utc(),
                                  order_duration=90,
                                  order_range=5,
                                  generated_at=now_dtime_in_utc())
        self.order_list.add_order(self.order1)
        # This order isn't added, but it's here for the test to add.
        self.order2 = MarketOrder(order_id=1234566,
                                  is_bid=False,
                                  region_id=10000032,
                                  solar_system_id=30005312,
                                  station_id=60011121,
                                  type_id=10000067,
                                  price=52,
                                  volume_entered=10,
                                  volume_remaining=500,
                                  minimum_volume=1,
                                  order_issue_date=now_dtime_in_utc(),
                                  order_duration=90,
                                  order_range=5,
                                  generated_at=now_dtime_in_utc())

        self.history = MarketHistoryList()
        self.history1 = MarketHistoryEntry(
            type_id=2413387906,
            region_id=10000068,
            historical_date=now_dtime_in_utc(),
            num_orders=5,
            low_price=5.0,
            high_price=10.5,
            average_price=7.0,
            total_quantity=200,
            generated_at=now_dtime_in_utc(),
        )
        self.history.add_entry(self.history1)
        # This order isn't added, but it's here for the test to add.
        self.history2 = MarketHistoryEntry(
            type_id=1413387203,
            region_id=10000067,
            historical_date=now_dtime_in_utc(),
            num_orders=50,
            low_price=50.0,
            high_price=100.5,
            average_price=70.0,
            total_quantity=2000,
            generated_at=now_dtime_in_utc(),
        )
    def test_order_counting(self):
        """
        Test the various order counting methods.
        """
        order_list = MarketOrderList()
        # There should be no orders so far.
        self.assertEqual(0, len(order_list))
        order_list.add_order(MarketOrder(
            order_id=2413387906,
            is_bid=True,
            region_id=10000068,
            solar_system_id=30005316,
            station_id=60011521,
            type_id=10000068,
            price=52875,
            volume_entered=10,
            volume_remaining=4,
            minimum_volume=1,
            order_issue_date=now_dtime_in_utc(),
            order_duration=90,
            order_range=5,
            generated_at=now_dtime_in_utc()
        ))
        # Added one order.
        self.assertEqual(1, len(order_list))
        # Adding a different item in the same region.
        order_list.add_order(MarketOrder(
            order_id=2413387907,
            is_bid=True,
            region_id=10000068,
            solar_system_id=30005316,
            station_id=60011521,
            type_id=10000067,
            price=52875,
            volume_entered=10,
            volume_remaining=4,
            minimum_volume=1,
            order_issue_date=now_dtime_in_utc(),
            order_duration=90,
            order_range=5,
            generated_at=now_dtime_in_utc()
        ))
        self.assertEqual(2, len(order_list))
        # Adding an item to a different region.
        order_list.add_order(MarketOrder(
            order_id=2413387907,
            is_bid=True,
            region_id=10000067,
            solar_system_id=30005316,
            station_id=60011521,
            type_id=10000067,
            price=52875,
            volume_entered=10,
            volume_remaining=4,
            minimum_volume=1,
            order_issue_date=now_dtime_in_utc(),
            order_duration=90,
            order_range=5,
            generated_at=now_dtime_in_utc()
        ))
        self.assertEqual(3, len(order_list))

        # Make sure that iterating over a MarketOrderList returns the correct
        # instance type.
        for olist in order_list:
            self.assertIsInstance(olist, MarketItemsInRegionList)
Esempio n. 13
0
    def setUp(self):
        self.order_list = MarketOrderList()
        self.order1 = MarketOrder(
            order_id=2413387906,
            is_bid=True,
            region_id=10000068,
            solar_system_id=30005316,
            station_id=60011521,
            type_id=10000068,
            price=52875,
            volume_entered=10,
            volume_remaining=4,
            minimum_volume=1,
            order_issue_date=now_dtime_in_utc(),
            order_duration=90,
            order_range=5,
            generated_at=now_dtime_in_utc()
        )
        self.order_list.add_order(self.order1)
        # This order isn't added, but it's here for the test to add.
        self.order2 = MarketOrder(
            order_id=1234566,
            is_bid=False,
            region_id=10000032,
            solar_system_id=30005312,
            station_id=60011121,
            type_id=10000067,
            price=52,
            volume_entered=10,
            volume_remaining=500,
            minimum_volume=1,
            order_issue_date=now_dtime_in_utc(),
            order_duration=90,
            order_range=5,
            generated_at=now_dtime_in_utc()
        )

        self.history = MarketHistoryList()
        self.history1 = MarketHistoryEntry(
            type_id=2413387906,
            region_id=10000068,
            historical_date=now_dtime_in_utc(),
            num_orders=5,
            low_price=5.0,
            high_price=10.5,
            average_price=7.0,
            total_quantity=200,
            generated_at=now_dtime_in_utc(),
        )
        self.history.add_entry(self.history1)
        # This order isn't added, but it's here for the test to add.
        self.history2 = MarketHistoryEntry(
            type_id=1413387203,
            region_id=10000067,
            historical_date=now_dtime_in_utc(),
            num_orders=50,
            low_price=50.0,
            high_price=100.5,
            average_price=70.0,
            total_quantity=2000,
            generated_at=now_dtime_in_utc(),
        )
Esempio n. 14
0
class BaseSerializationCase(unittest.TestCase):
    """
    This is a base class that provides some convenient test data for the
    various formats to use in their respective unit tests.
    """

    def setUp(self):
        self.order_list = MarketOrderList()
        self.order1 = MarketOrder(
            order_id=2413387906,
            is_bid=True,
            region_id=10000068,
            solar_system_id=30005316,
            station_id=60011521,
            type_id=10000068,
            price=52875,
            volume_entered=10,
            volume_remaining=4,
            minimum_volume=1,
            order_issue_date=now_dtime_in_utc(),
            order_duration=90,
            order_range=5,
            generated_at=now_dtime_in_utc()
        )
        self.order_list.add_order(self.order1)
        # This order isn't added, but it's here for the test to add.
        self.order2 = MarketOrder(
            order_id=1234566,
            is_bid=False,
            region_id=10000032,
            solar_system_id=30005312,
            station_id=60011121,
            type_id=10000067,
            price=52,
            volume_entered=10,
            volume_remaining=500,
            minimum_volume=1,
            order_issue_date=now_dtime_in_utc(),
            order_duration=90,
            order_range=5,
            generated_at=now_dtime_in_utc()
        )

        self.history = MarketHistoryList()
        self.history1 = MarketHistoryEntry(
            type_id=2413387906,
            region_id=10000068,
            historical_date=now_dtime_in_utc(),
            num_orders=5,
            low_price=5.0,
            high_price=10.5,
            average_price=7.0,
            total_quantity=200,
            generated_at=now_dtime_in_utc(),
        )
        self.history.add_entry(self.history1)
        # This order isn't added, but it's here for the test to add.
        self.history2 = MarketHistoryEntry(
            type_id=1413387203,
            region_id=10000067,
            historical_date=now_dtime_in_utc(),
            num_orders=50,
            low_price=50.0,
            high_price=100.5,
            average_price=70.0,
            total_quantity=2000,
            generated_at=now_dtime_in_utc(),
        )