def test_json_stores_user_attribute(self, mock_time):
mock_time.return_value = datetime.utcnow().replace(tzinfo=utc)
self._publish_transportation_form()
# make account require phone auth
self.user.profile.require_auth = True
self.user.profile.save()
# submit instance with a request user
path = os.path.join(
self.this_directory, 'fixtures', 'transportation', 'instances',
self.surveys[0], self.surveys[0] + '.xml')
auth = DigestAuth(self.login_username, self.login_password)
self._make_submission(path, auth=auth)
instances = Instance.objects.filter(xform_id=self.xform).all()
self.assertTrue(len(instances) > 0)
for instance in instances:
self.assertEqual(instance.json[SUBMITTED_BY], 'bob')
# check that the parsed instance's to_dict_for_mongo also contains
# the _user key, which is what's used by the JSON REST service
pi = ParsedInstance.objects.get(instance=instance)
self.assertEqual(pi.to_dict_for_mongo()[SUBMITTED_BY], 'bob')
评论列表
文章目录