'Test write points from df with time precision.'

def test_write_points_from_dataframe_with_time_precision(self):

    now = pd.Timestamp(u'1970-01-01    00:00+00:00')
    dataframe = pd.DataFrame(data=[[u'1', 1, 1.0], [u'2', 2, 2.0]], index=[now, (now + timedelta(hours=1))], columns=[u'column_one', u'column_two', u'column_three'])
    with requests_mock.Mocker() as m:
        m.register_uri(requests_mock.POST, u'http://localhost:8086/write', status_code=204)
        cli = DataFrameClient(database=u'db')
        measurement = u'foo'
        cli.write_points(dataframe, measurement, time_precision=u'h')
        self.assertEqual(m.last_request.qs[u'precision'], [u'h'])
        self.assertEqual('foo    column_one="1",column_two=1i,column_three=1.0    0\nfoo    column_one="2",column_two=2i,column_three=2.0    1\n', m.last_request.body)
        cli.write_points(dataframe, measurement, time_precision=u'm')
        self.assertEqual(m.last_request.qs[u'precision'], [u'm'])
        self.assertEqual('foo    column_one="1",column_two=1i,column_three=1.0    0\nfoo    column_one="2",column_two=2i,column_three=2.0    60\n', m.last_request.body)
        cli.write_points(dataframe, measurement, time_precision=u's')
        self.assertEqual(m.last_request.qs[u'precision'], [u's'])
        self.assertEqual('foo    column_one="1",column_two=1i,column_three=1.0    0\nfoo    column_one="2",column_two=2i,column_three=2.0    3600\n', m.last_request.body)
        cli.write_points(dataframe, measurement, time_precision=u'ms')
        self.assertEqual(m.last_request.qs[u'precision'], [u'ms'])
        self.assertEqual('foo    column_one="1",column_two=1i,column_three=1.0    0\nfoo    column_one="2",column_two=2i,column_three=2.0    3600000\n', m.last_request.body)
        cli.write_points(dataframe, measurement, time_precision=u'u')
        self.assertEqual(m.last_request.qs[u'precision'], [u'u'])
        self.assertEqual('foo    column_one="1",column_two=1i,column_three=1.0    0\nfoo    column_one="2",column_two=2i,column_three=2.0    3600000000\n', m.last_request.body)
        cli.write_points(dataframe, measurement, time_precision=u'n')
        self.assertEqual(m.last_request.qs[u'precision'], [u'n'])
        self.assertEqual('foo    column_one="1",column_two=1i,column_three=1.0    0\nfoo    column_one="2",column_two=2i,column_three=2.0    3600000000000\n', m.last_request.body)
