def testPillboxCheck(self):
        #check to make sure that 0th and nth elements are where they ought to be
        #hit the VIEW to make sure it's there
        #make sure the pact_dots_data signal is working
        #check no pillbox check entries that entries show up, and NOTHING more.
        #ensure signal works
        #todo: labeling checks

        self.testSignal()
        observations = query_observations(CASE_ID, START_DATE, END_DATE)
        td = END_DATE - START_DATE

        def check_obs_props(obs, props):
            for k, v in props.items():
                if k.endswith("_date"):
                    # datetime check
                    obs_datetime = getattr(obs, k)
                    val_datetime = dateutil.parser.parse(v)
                    if k in ('completed_date', 'created_date'):
                        obs_datetime = ServerTime(obs_datetime).user_time(PACT_TIMEZONE).done()
                    obs_date = obs_datetime.date()
                    val_date = val_datetime.date()
                    self.assertEquals(obs_date, val_date)
                else:
                    self.assertEquals(getattr(obs, k), v,
                                      msg="Error, observation %s\n\t%s didn't match: %s != %s" % (
                                      json.dumps(obs.to_json(), indent=4), k, getattr(obs, k),
                                      v))

        for d in range(td.days):
            this_day = START_DATE + timedelta(days=d)
            day_submissions = filter_obs_for_day(this_day.date(), observations)
            day_data = DOTDay.merge_from_observations(day_submissions)
            if this_day.date() == START_DATE.date():
                art_first = day_data.art.dose_dict[1][0]
                art_first_check_props = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 2,
                    "day_note": "art first noon",
                    "day_index": 20,
                    "note": "",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "pillbox",
                    "observed_date": "2012-11-17T05:00:00Z",
                    #"day_slot": 1,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "partial",
                    "dose_number": 1, #zero indexed
                    #                    "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": True,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(art_first, art_first_check_props)

                non_art_first_1 = day_data.nonart.dose_dict[1][0]
                non_art_first_1_props = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 3,
                    "day_note": "non art first evening",
                    "day_index": 20,
                    "note": "",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "pillbox",
                    "observed_date": "2012-11-17T05:00:00Z",
                    #                    "day_slot": 2,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "partial",
                    "dose_number": 1,
                    #                    "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": False,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(non_art_first_1, non_art_first_1_props)

                non_art_first_2 = day_data.nonart.dose_dict[2][0]
                non_art_first_2_props = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 3,
                    "day_note": "non art bedtime first",
                    "day_index": 20,
                    "note": "",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "pillbox",
                    "observed_date": "2012-11-17T05:00:00Z",
                    #                    "day_slot": 3,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "partial",
                    "dose_number": 2,
                    #                    "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": False,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(non_art_first_2, non_art_first_2_props)

            if this_day.date() == (ANCHOR_DATE - timedelta(days=1)).date():
                self.assertEquals(len(day_data.art.dose_dict.keys()),
                                  2) # two doses, one for the answered, another for unchecked
                art_slast = day_data.art.dose_dict[0][0]
                art_slast_props = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 2,
                    "day_note": "2nd to last last filled by questions",
                    "day_index": 1,
                    "note": "",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "pillbox",
                    "observed_date": "2012-12-06T05:00:00Z",
                    "day_slot": -1,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "partial",
                    "dose_number": 0,
                    #                    "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": True,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(art_slast, art_slast_props)

                nonart_slast0 = day_data.nonart.dose_dict[0][0]
                non_art0 = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 3,
                    "day_note": "",
                    "day_index": 1,
                    "note": "",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "direct",
                    "observed_date": "2012-12-06T05:00:00Z",
                    #                "day_slot": -1,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "empty",
                    "dose_number": 0,
                    #                "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": False,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(nonart_slast0, non_art0)

                nonart_slast1 = day_data.nonart.dose_dict[1][0]
                non_art1 = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 3,
                    "day_note": "non art noon second to last",
                    "day_index": 1,
                    "note": "",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "pillbox",
                    "observed_date": "2012-12-06T05:00:00Z",
                    #                "day_slot": -1,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "partial",
                    "dose_number": 1,
                    #                "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": False,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(nonart_slast1, non_art1)

                nonart_slast2 = day_data.nonart.dose_dict[2][0]
                non_art2 = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 3,
                    "day_note": "art evening second to last",
                    "day_index": 1,
                    "note": "",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "pillbox",
                    "observed_date": "2012-12-06T05:00:00Z",
                    #                "day_slot": -1,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "partial",
                    "dose_number": 2,
                    #                "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": False,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(nonart_slast2, non_art2)

            if this_day.date() == ANCHOR_DATE.date():
                self.assertEqual(len(day_data.nonart.dose_dict[0]), 1)
                non_art_last = day_data.nonart.dose_dict[0][0]
                non_art_last_props = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 3,
                    "day_note": "",
                    "day_index": 0,
                    "note": "Anchor same",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "direct",
                    "observed_date": "2012-12-07T05:00:00Z",
                    #"day_slot": -1,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "partial",
                    "dose_number": 0,
                    #                        "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": False,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(non_art_last, non_art_last_props)

                non_art_last_noon = day_data.nonart.dose_dict[1][0]
                non_art_last_noon_props = {
                    "encounter_date": "2012-12-07T05:00:00Z",
                    "total_doses": 3,
                    "day_note": "non art noon last",
                    "day_index": 0,
                    "note": "Anchor same",
                    "pact_id": "999999",
                    "provider": "ctsims",
                    "method": "pillbox",
                    "observed_date": "2012-12-07T05:00:00Z",
                    #                        "day_slot": -1,
                    "completed_date": "2012-12-16T22:00:28.847000Z",
                    "adherence": "partial",
                    "dose_number": 1,
                    #                        "doc_type": "CObservation",
                    "is_reconciliation": False,
                    "anchor_date": "2012-12-07T05:00:00Z",
                    "created_date": "2012-12-16T21:37:52.771000Z",
                    "is_art": False,
                    "_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759",
                    "doc_id": "a1811d7e-c968-4b63-aea5-6195ce0d8759"
                }
                check_obs_props(non_art_last_noon, non_art_last_noon_props)
                #todo: check reconciliation?
            pass
This test tries to accomplish a few things
dataset/ETHPy150Open dimagi/commcare-hq/custom/_legacy/pact/tests/dot_submission.py/dotsSubmissionTests.testPillboxCheck