'Tests for complex datetime fields - which can handle
microseconds without rounding.'

def test_complexdatetime_storage(self):

    class LogEntry(Document, ):
        date = ComplexDateTimeField()
        date_with_dots = ComplexDateTimeField(separator='.')
    LogEntry.drop_collection()
    d1 = datetime.datetime(1970, 1, 1, 0, 0, 1, 999)
    log = LogEntry()
    log.date = d1
    log.save()
    log.reload()
    self.assertEqual(log.date, d1)
    d1 = datetime.datetime(1970, 1, 1, 0, 0, 1, 9999)
    log.date = d1
    log.save()
    log.reload()
    self.assertEqual(log.date, d1)
    d1 = datetime.datetime(1969, 12, 31, 23, 59, 59, 999)
    log.date = d1
    log.save()
    log.reload()
    self.assertEqual(log.date, d1)
    for i in range(1001, 3113, 33):
        d1 = datetime.datetime(1969, 12, 31, 23, 59, 59, i)
        log.date = d1
        log.save()
        log.reload()
        self.assertEqual(log.date, d1)
        log1 = LogEntry.objects.get(date=d1)
        self.assertEqual(log, log1)
    microsecond = map(int, [math.pow(10, x) for x in range(6)])
    mm = dd = hh = ii = ss = [1, 10]
    for values in itertools.product([2014], mm, dd, hh, ii, ss, microsecond):
        stored = LogEntry(date=datetime.datetime(*values)).to_mongo()['date']
        self.assertTrue((re.match('^\\d{4},\\d{2},\\d{2},\\d{2},\\d{2},\\d{2},\\d{6}$', stored) is not None))
    stored = LogEntry(date_with_dots=datetime.datetime(2014, 1, 1)).to_mongo()['date_with_dots']
    self.assertTrue((re.match('^\\d{4}.\\d{2}.\\d{2}.\\d{2}.\\d{2}.\\d{2}.\\d{6}$', stored) is not None))
