def test_get_audusd_when_loaded_returns_expected_instrument(self):
        # Arrange
        mock_client = MagicMock()

        with open(TEST_PATH + "instruments.json") as response:
            instruments = json.load(response)

        mock_client.request.return_value = instruments

        provider = OandaInstrumentProvider(client=mock_client,
                                           account_id="001",
                                           load_all=True)

        symbol = Symbol("AUD/USD", Venue("OANDA"))

        # Act
        instrument = provider.get(symbol)

        # Assert
        self.assertEqual(Instrument, type(instrument))
        self.assertEqual(AssetClass.FX, instrument.asset_class)
        self.assertEqual(AssetType.SPOT, instrument.asset_type)
        self.assertEqual(AUD, instrument.base_currency)
        self.assertEqual(USD, instrument.quote_currency)
        self.assertEqual(USD, instrument.settlement_currency)
    def test_get_all_when_not_loaded_returns_empty_dict(self):
        # Arrange
        mock_client = MagicMock()

        provider = OandaInstrumentProvider(client=mock_client, account_id="001")

        # Act
        instruments = provider.get_all()

        # Assert
        self.assertEqual({}, instruments)
    def test_load_all(self):
        # Arrange
        mock_client = MagicMock()

        with open(TEST_PATH + "instruments.json") as response:
            instruments = json.load(response)

        mock_client.request.return_value = instruments

        provider = OandaInstrumentProvider(client=mock_client, account_id="001")

        # Act
        provider.load_all()

        # Assert
        self.assertTrue(provider.count > 0)  # No exceptions raised
    def test_get_audusd_when_not_loaded_returns_none(self):
        # Arrange
        mock_client = MagicMock()

        with open(TEST_PATH + "instruments.json") as response:
            instruments = json.load(response)

        mock_client.request.return_value = instruments

        provider = OandaInstrumentProvider(client=mock_client, account_id="001")

        instrument_id = InstrumentId(Symbol("AUD/USD"), Venue("OANDA"))

        # Act
        instrument = provider.find(instrument_id)

        # Assert
        self.assertIsNone(instrument)
    def test_get_all_when_loaded_returns_instruments(self):
        # Arrange
        mock_client = MagicMock()

        with open(TEST_PATH + "instruments.json") as response:
            instruments = json.load(response)

        mock_client.request.return_value = instruments

        provider = OandaInstrumentProvider(client=mock_client, account_id="001")
        provider.load_all()

        # Act
        instruments = provider.get_all()

        # Assert
        self.assertTrue(len(instruments) > 0)
        self.assertEqual(dict, type(instruments))
        self.assertEqual(InstrumentId, type(next(iter(instruments))))