def testForwardNoLastSample(self, collectorsdb, _getLatestSample,
                              urllib2, metricDataBatchWriter):

    _getLatestSample.return_value = None

    data = [
      {
          "StartDate": "1/15/2015",
          "StartTime": "9:30:00 AM",
          "EndDate": "1/15/2015",
          "EndTime": "9:35:00 AM",
          "UTCOffset": -5,
          "Open": 46.225,
          "High": 46.38,
          "Low": 45.955,
          "Close": 45.96,
          "Volume": 504494,
          "Trades": 2414,
          "TWAP": 46.1765,
          "VWAP": 46.1756
      },
      {
          "StartDate": "1/15/2015",
          "StartTime": "9:35:00 AM",
          "EndDate": "1/15/2015",
          "EndTime": "9:40:00 AM",
          "UTCOffset": -5,
          "Open": 45.97,
          "High": 46.025,
          "Low": 45.64,
          "Close": 45.79,
          "Volume": 492621,
          "Trades": 2621,
          "TWAP": 45.8574,
          "VWAP": 45.8569
      }
    ]

    security = {
      "CIK": "0000789019",
      "CUSIP": None,
      "Symbol": "MSFT",
      "ISIN": None,
      "Valoren": "951692",
      "Name": "Microsoft Corp",
      "Market": "NASDAQ",
      "MarketIdentificationCode": "XNAS",
      "MostLiquidExchange": True,
      "CategoryOrIndustry": "InformationTechnologyServices"
    }


    collectorsdb.retryOnTransientErrors.side_effect = [
      Mock(),
      Mock(),
      Mock(return_value = [Mock(StartDate=datetime.date(2015, 1, 15),
                                StartTime=datetime.time(9, 30),
                                EndDate=datetime.date(2015, 1, 15),
                                EndTime=datetime.time(9, 35),
                                UTCOffset=-5.0,
                                Volume=504494,
                                Close=45.96,
                                Close_sent=None,
                                Volume_sent=None,
                                __getitem__ = Mock(side_effect = {
                                  "Close_sent": None,
                                  "Volume_sent": None,
                                  "Volume": 504494}.__getitem__),
                                __contains__ = Mock(side_effect={
                                  "Volume": None
                                  }.__contains__)),
                           Mock(StartDate=datetime.date(2015, 1, 15),
                                StartTime=datetime.time(9, 35),
                                EndDate=datetime.date(2015, 1, 15),
                                EndTime=datetime.time(9, 40),
                                UTCOffset=-5.0,
                                Volume=492621,
                                Close=45.79,
                                Close_sent=None,
                                Volume_sent=None,
                                __getitem__ = Mock(side_effect = {
                                  "Close_sent": None,
                                  "Volume_sent": None,
                                  "Volume": 492621}.__getitem__),
                                __contains__ = Mock(side_effect={
                                  "Volume": None
                                  }.__contains__))
                          ])
    ]


    msft = xignite_stock_agent.StockMetricSpec(
      metricName="XIGNITE.MSFT.VOLUME",
      symbol="MSFT",
      stockExchange="NASDAQ",
      sampleKey="Volume")

    xignite_stock_agent.forward((msft,), data, security)

    metricDataBatchWriter.return_value.__enter__.return_value.call_args_list
    self.assertEqual(
      metricDataBatchWriter.return_value.__enter__.return_value.call_count, 2)
    metricDataBatchWriter.return_value.__enter__.return_value.assert_has_calls(
      [call(metricName="XIGNITE.MSFT.VOLUME",
            value=504494,
            epochTimestamp=1421332200.0),
       call(metricName="XIGNITE.MSFT.VOLUME",
            value=492621,
            epochTimestamp=1421332500.0)])
  def testForwardAfterHours(self, collectorsdb, _getLatestSample,
                            transmitMetricData, urllib2,
                            metricDataBatchWriter):
    """ After-hours data should be silenty ignored.
    """

    mockSample = Mock(EndDate=datetime.date(2015, 1, 15),
                      EndTime=datetime.time(17, 30, 0))
    _getLatestSample.return_value = mockSample

    data = [
      {
          "StartDate": "1/15/2015",
          "StartTime": "5:30:00 PM",
          "EndDate": "1/15/2015",
          "EndTime": "5:35:00 PM",
          "UTCOffset": -5,
          "Open": 46.225,
          "High": 46.38,
          "Low": 45.955,
          "Close": 45.96,
          "Volume": 504494,
          "Trades": 2414,
          "TWAP": 46.1765,
          "VWAP": 46.1756
      }
    ]

    security = {
      "CIK": "0000789019",
      "CUSIP": None,
      "Symbol": "MSFT",
      "ISIN": None,
      "Valoren": "951692",
      "Name": "Microsoft Corp",
      "Market": "NASDAQ",
      "MarketIdentificationCode": "XNAS",
      "MostLiquidExchange": True,
      "CategoryOrIndustry": "InformationTechnologyServices"
    }


    collectorsdb.retryOnTransientErrors.side_effect = [
      Mock(),
      Mock(),
      Mock(return_value = [Mock(StartDate=datetime.date(2015, 1, 15),
                                StartTime=datetime.time(17, 30),
                                EndDate=datetime.date(2015, 1, 15),
                                EndTime=datetime.time(17, 35),
                                UTCOffset=-5.0,
                                Volume=504494,
                                Close=45.96,
                                Close_sent=None,
                                Volume_sent=None,
                                __getitem__ = Mock(side_effect = {
                                  "Close_sent": None,
                                  "Volume_sent": None,
                                  "Volume": 504494}.__getitem__),
                                __contains__ = Mock(side_effect={
                                  "Volume": None
                                  }.__contains__))
                          ])
    ]


    msft = xignite_stock_agent.StockMetricSpec(
      metricName="XIGNITE.MSFT.VOLUME",
      symbol="MSFT",
      stockExchange="NASDAQ",
      sampleKey="Volume")

    with patch.object(
        xignite_stock_agent,
        "g_opMode",
        new=taurus_metric_collectors.ApplicationConfig.OP_MODE_ACTIVE):
      xignite_stock_agent.forward((msft,), data, security)

    self.assertEqual(
      collectorsdb.engineFactory.return_value.execute.call_count,
      0,
      "Unexpected database query issued for after-hours record. xignite_stock_"
      "agent.forward() should silently ignore after-hours data.")

    self.assertNotEqual(
      transmitMetricData.call_count,
      0,
      "transmitMetricData() was not called as expected.")