def test_edit_updated_geopoint_cache(self):
     query_args = {
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'query': '{}',
         'fields': '[]',
         'sort': '[]',
         'count': True
     }
     xml_submission_file_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "..", "fixtures",
         "tutorial", "instances", "tutorial_2012-06-27_11-27-53_w_uuid.xml")
     self._make_submission(xml_submission_file_path)
     self.assertEqual(self.response.status_code, 201)
     # query mongo for the _geopoint field
     query_args['count'] = False
     records = ParsedInstance.query_mongo(**query_args)
     self.assertEqual(len(records), 1)
     # submit the edited instance
     xml_submission_file_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "..", "fixtures",
         "tutorial", "instances",
         "tutorial_2012-06-27_11-27-53_w_uuid_edited.xml")
     self._make_submission(xml_submission_file_path)
     self.assertEqual(self.response.status_code, 201)
     records = ParsedInstance.query_mongo(**query_args)
     self.assertEqual(len(records), 1)
     cached_geopoint = records[0][GEOLOCATION]
     # the cached geopoint should equal the gps field
     gps = records[0]['gps'].split(" ")
     self.assertEqual(float(gps[0]), float(cached_geopoint[0]))
     self.assertEqual(float(gps[1]), float(cached_geopoint[1]))
 def test_edit_updated_geopoint_cache(self):
     query_args = {
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'query': '{}',
         'fields': '[]',
         'sort': '[]',
         'count': True
     }
     xml_submission_file_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         "..", "fixtures", "tutorial", "instances",
         "tutorial_2012-06-27_11-27-53_w_uuid.xml"
     )
     self._make_submission(xml_submission_file_path)
     self.assertEqual(self.response.status_code, 201)
     # query mongo for the _geopoint field
     query_args['count'] = False
     records = ParsedInstance.query_mongo(**query_args)
     self.assertEqual(len(records), 1)
     # submit the edited instance
     xml_submission_file_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         "..", "fixtures", "tutorial", "instances",
         "tutorial_2012-06-27_11-27-53_w_uuid_edited.xml"
     )
     self._make_submission(xml_submission_file_path)
     self.assertEqual(self.response.status_code, 201)
     records = ParsedInstance.query_mongo(**query_args)
     self.assertEqual(len(records), 1)
     cached_geopoint = records[0][GEOLOCATION]
     # the cached geopoint should equal the gps field
     gps = records[0]['gps'].split(" ")
     self.assertEqual(float(gps[0]), float(cached_geopoint[0]))
     self.assertEqual(float(gps[1]), float(cached_geopoint[1]))
 def test_edited_submission(self):
     """
     Test submissions that have been edited
     """
     xml_submission_file_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         "..", "fixtures", "tutorial", "instances",
         "tutorial_2012-06-27_11-27-53_w_uuid.xml"
     )
     num_instances_history = InstanceHistory.objects.count()
     num_instances = Instance.objects.count()
     query_args = {
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'query': '{}',
         'fields': '[]',
         'sort': '[]',
         'count': True
     }
     cursor = ParsedInstance.query_mongo(**query_args)
     num_mongo_instances = cursor[0]['count']
     # make first submission
     self._make_submission(xml_submission_file_path)
     self.assertEqual(self.response.status_code, 201)
     self.assertEqual(Instance.objects.count(), num_instances + 1)
     # no new record in instances history
     self.assertEqual(
         InstanceHistory.objects.count(), num_instances_history)
     # check count of mongo instances after first submission
     cursor = ParsedInstance.query_mongo(**query_args)
     self.assertEqual(cursor[0]['count'], num_mongo_instances + 1)
     # edited submission
     xml_submission_file_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         "..", "fixtures", "tutorial", "instances",
         "tutorial_2012-06-27_11-27-53_w_uuid_edited.xml"
     )
     self._make_submission(xml_submission_file_path)
     self.assertEqual(self.response.status_code, 201)
     # we must have the same number of instances
     self.assertEqual(Instance.objects.count(), num_instances + 1)
     # should be a new record in instances history
     self.assertEqual(
         InstanceHistory.objects.count(), num_instances_history + 1)
     cursor = ParsedInstance.query_mongo(**query_args)
     self.assertEqual(cursor[0]['count'], num_mongo_instances + 1)
     # make sure we edited the mongo db record and NOT added a new row
     query_args['count'] = False
     cursor = ParsedInstance.query_mongo(**query_args)
     record = cursor[0]
     with open(xml_submission_file_path, "r") as f:
         xml_str = f.read()
     xml_str = clean_and_parse_xml(xml_str).toxml()
     edited_name = re.match(ur"^.+?<name>(.+?)</name>", xml_str).groups()[0]
     self.assertEqual(record['name'], edited_name)
 def test_edited_submission(self):
     """
     Test submissions that have been edited
     """
     xml_submission_file_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "..", "fixtures",
         "tutorial", "instances", "tutorial_2012-06-27_11-27-53_w_uuid.xml")
     num_instances_history = InstanceHistory.objects.count()
     num_instances = Instance.objects.count()
     query_args = {
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'query': '{}',
         'fields': '[]',
         'sort': '[]',
         'count': True
     }
     cursor = ParsedInstance.query_mongo(**query_args)
     num_mongo_instances = cursor[0]['count']
     # make first submission
     self._make_submission(xml_submission_file_path)
     self.assertEqual(self.response.status_code, 201)
     self.assertEqual(Instance.objects.count(), num_instances + 1)
     # no new record in instances history
     self.assertEqual(InstanceHistory.objects.count(),
                      num_instances_history)
     # check count of mongo instances after first submission
     cursor = ParsedInstance.query_mongo(**query_args)
     self.assertEqual(cursor[0]['count'], num_mongo_instances + 1)
     # edited submission
     xml_submission_file_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "..", "fixtures",
         "tutorial", "instances",
         "tutorial_2012-06-27_11-27-53_w_uuid_edited.xml")
     self._make_submission(xml_submission_file_path)
     self.assertEqual(self.response.status_code, 201)
     # we must have the same number of instances
     self.assertEqual(Instance.objects.count(), num_instances + 1)
     # should be a new record in instances history
     self.assertEqual(InstanceHistory.objects.count(),
                      num_instances_history + 1)
     cursor = ParsedInstance.query_mongo(**query_args)
     self.assertEqual(cursor[0]['count'], num_mongo_instances + 1)
     # make sure we edited the mongo db record and NOT added a new row
     query_args['count'] = False
     cursor = ParsedInstance.query_mongo(**query_args)
     record = cursor[0]
     with open(xml_submission_file_path, "r") as f:
         xml_str = f.read()
     xml_str = clean_and_parse_xml(xml_str).toxml()
     edited_name = re.match(ur"^.+?<name>(.+?)</name>", xml_str).groups()[0]
     self.assertEqual(record['name'], edited_name)
    def test_owner_can_delete(self):
        #Test if Form owner can delete
        #check record exist before delete and after delete
        json = '{"transport/available_transportation_types_to_referral_facility":"none"}'
        data = {'query': json}
        args = {'username': self.user.username, 'id_string':
                    self.xform.id_string, 'query': json, 'limit': 1, 'sort':
                        '{"_id":-1}', 'fields': '["_id"]'}

        #check if record exist before delete
        before = ParsedInstance.query_mongo(**args)
        self.assertEqual(before.count(), 1)

        #Delete
        response = self.client.get(self.delete_url, data)
        self.assertEqual(response.status_code, 200)

        #check if it exist after delete
        after = ParsedInstance.query_mongo(**args)
        self.assertEqual(after.count(), 0)
Beispiel #6
0
 def test_edit_url(self):
     instance = Instance.objects.all().reverse()[0]
     query = json.dumps({'_uuid': instance.uuid})
     cursor = ParsedInstance.query_mongo(self.user.username,
         self.xform.id_string, query, '[]', '{}')
     records = [record for record in cursor]
     self.assertTrue(len(records) > 0)
     edit_url = reverse(edit_data, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'data_id': records[0]['_id']
     })
     response = self.client.get(edit_url)
     self.assertEqual(response.status_code, 302)
 def test_owner_can_delete(self):
     #Test if Form owner can delete
     #check record exist before delete and after delete
     count = Instance.objects.filter(deleted_at=None).count()
     records = self._get_data()
     self.assertTrue(records.__len__() > 0)
     query = '{"_id": %s}' % records[0]["_id"]
     response = self.client.post(self.delete_url, {'query': query})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         Instance.objects.filter(deleted_at=None).count(), count - 1)
     uuid = records[0]['_uuid']
     instance  = Instance.objects.get(uuid=uuid, xform=self.xform)
     self.assertNotEqual(instance.deleted_at, None)
     self.assertTrue(isinstance(instance.deleted_at, datetime))
     self.mongo_args.update({"query": query})
     #check if it exist after delete
     after = ParsedInstance.query_mongo(**self.mongo_args)
     self.assertEqual(after.count(), 0)
 def test_owner_can_delete(self):
     #Test if Form owner can delete
     #check record exist before delete and after delete
     count = Instance.objects.filter(deleted_at=None).count()
     instance = Instance.objects.filter(
         xform=self.xform).latest('date_created')
     # delete
     params = {'id': instance.id}
     response = self.client.post(self.delete_url, params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         Instance.objects.filter(deleted_at=None).count(), count - 1)
     instance  = Instance.objects.get(id=instance.id)
     self.assertTrue(isinstance(instance.deleted_at, datetime))
     query = '{"_id": %s}' % instance.id
     self.mongo_args.update({"query": query})
     #check that query_mongo will not return the deleted record
     after = ParsedInstance.query_mongo(**self.mongo_args)
     self.assertEqual(len(after), count - 1)
 def test_owner_can_delete(self):
     #Test if Form owner can delete
     #check record exist before delete and after delete
     count = Instance.objects.filter(deleted_at=None).count()
     instance = Instance.objects.filter(
         xform=self.xform).latest('date_created')
     # delete
     params = {'id': instance.id}
     response = self.client.post(self.delete_url, params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         Instance.objects.filter(deleted_at=None).count(), count - 1)
     instance = Instance.objects.get(id=instance.id)
     self.assertTrue(isinstance(instance.deleted_at, datetime))
     self.assertTrue(instance.is_deleted, True)
     query = '{"_id": %s}' % instance.id
     self.mongo_args.update({"query": query})
     #check that query_mongo will not return the deleted record
     after = ParsedInstance.query_mongo(**self.mongo_args)
     self.assertEqual(len(after), count - 1)
 def _get_data(self):
     cursor = ParsedInstance.query_mongo(**self.mongo_args)
     records = list(record for record in cursor)
     return records
Beispiel #11
0
 def _get_data(self):
     cursor = ParsedInstance.query_mongo(**self.mongo_args)
     records = list(record for record in cursor)
     return records