예제 #1
0
파일: mock.py 프로젝트: vcgato29/intake
def fake_app_submitted(applicant, time=None):
    event = models.ApplicationEvent(
        name=models.ApplicationEvent.APPLICATION_SUBMITTED,
        applicant_id=applicant.id,
        data=dict())
    if time:
        event.time = time
    event.save()
    return event
예제 #2
0
파일: mock.py 프로젝트: vcgato29/intake
def fake_page_complete(applicant, page_name, time=None):
    event = models.ApplicationEvent(
        name=models.ApplicationEvent.APPLICATION_PAGE_COMPLETE,
        applicant_id=applicant.id,
        data=dict(page_name=page_name))
    if time:
        event.time = time
    event.save()
    return event
예제 #3
0
def fake_app_started(
        applicant, counties, referrer=None, ip=None, user_agent=None,
        time=None):
    if not referrer:
        referrer = fake_referrer()
    if not user_agent:
        user_agent = fake_user_agent()
    if not ip:
        ip = fake.ipv4()
    event = models.ApplicationEvent(
        name=models.ApplicationEvent.APPLICATION_STARTED,
        applicant_id=applicant.id,
        data=dict(
            counties=counties, referrer=referrer, ip=ip, user_agent=user_agent)
        )
    if time:
        event.time = time
    event.save()
    return event
예제 #4
0
 def handle(self, *args, **options):
     subs = models.FormSubmission.objects.filter(
         applicant_id__isnull=True)
     backfilled = 0
     for sub in subs:
         if not sub.applicant_id:
             applicant = models.Applicant()
             applicant.save()
             sub.applicant = applicant
             sub.save()
             event = models.ApplicationEvent(
                 applicant_id=applicant.id,
                 name=models.ApplicationEvent.APPLICATION_SUBMITTED,
                 time=sub.date_received,
                 data={})
             event.save()
             backfilled += 1
     self.stdout.write(
         self.style.SUCCESS(
             "Backfilled applicants on {} submissions".format(backfilled))
     )
예제 #5
0
    def test_gets_expected_json(self):
        # applicant with some events
        applicant = models.Applicant.objects.first()
        event = models.ApplicationEvent(
            applicant=applicant,
            name=models.ApplicationEvent.APPLICATION_STARTED,
            data={
                'referrer': 'google.com',
                'ip': '127.0.0.1',
            })
        event.save()

        data = serializers.ApplicantSerializer(applicant).data
        top_keys = [
            'id', 'events', 'started', 'finished', 'had_errors', 'ip',
            'referrer', 'events', 'tried_to_apply', 'is_multicounty'
        ]
        event_keys = ['time', 'name', 'data']
        for key in top_keys:
            self.assertIn(key, data)
        for key in event_keys:
            self.assertIn(key, data['events'][0])
예제 #6
0
def make_error_event(applicant, errors):
    event = models.ApplicationEvent(
        applicant=applicant,
        name=models.ApplicationEvent.APPLICATION_ERRORS,
        data=dict(errors=errors))
    event.save()
예제 #7
0
def make_county_form_completed_event(applicant):
    event = models.ApplicationEvent(
        applicant=applicant,
        name=models.ApplicationEvent.APPLICATION_PAGE_COMPLETE,
        data=dict(page_name='CountyApplication'))
    event.save()