'Verify stored visit counts from mocked analytics data.
It has some nasty non-ASCII chars in it.'

@patch.object(models, 'close_old_connections')
@patch.object(googleanalytics, '_build_request')
def test_visit_count_from_analytics(self, _build_request, close_old_connections):

    execute = _build_request.return_value.get.return_value.execute
    execute.return_value = PAGEVIEWS_BY_DOCUMENT_RESPONSE
    d1 = ApprovedRevisionFactory(document__slug=u'hell\u1ed7').document
    d2 = ApprovedRevisionFactory(document__slug=u'there').document
    WikiDocumentVisits.reload_period_from_analytics(LAST_7_DAYS)
    eq_(2, WikiDocumentVisits.objects.count())
    wdv1 = WikiDocumentVisits.objects.get(document=d1)
    eq_(27, wdv1.visits)
    eq_(LAST_7_DAYS, wdv1.period)
    wdv2 = WikiDocumentVisits.objects.get(document=d2)
    eq_(LAST_7_DAYS, wdv2.period)
