def _ignored__should_update_existing_data_records(self):
        mocked_form_model = Mock(spec=FormModel)
        mocked_form_model.is_registration_form.return_value = False
        mocked_form_model.entity_type = "clinic"
        form_submission = FormSubmissionFactory().get_form_submission(mocked_form_model, OrderedDict(), None)

        form_submission._values.insert(0,(u'What are symptoms?', ['High Fever']))

        mock_dbm = Mock(DatabaseManager)
        data_record = DataRecord(mock_dbm)
        data_record._doc = DataRecordDocument(entity_doc=EntityDocument())
        data_record._doc.entity['data'] = {u'What are symptoms?': {'value': ['Dry cough', 'Memory loss']}}

        data_record_id = 'abcdefgh1234jklmnop'
        submission = DocumentBase(document_type=(Mock(Document)))
        submission._data['data_record_id'] = data_record_id

        with patch('mangrove.datastore.database.DatabaseManager._load_document') as load_document:
            with patch('mangrove.datastore.database.DataObject.get') as get_data_record:
                load_document.return_value = data_record_id
                get_data_record.return_value = data_record

                form_submission.update_existing_data_records(mock_dbm,'8765gjngtbhjmk4567hloub')

        data_record.save().assert_called_once()
Example #2
0
 def handle(self,
            form_model,
            cleaned_data,
            errors,
            reporter_names=[],
            location_tree=None):
     form_submission = FormSubmissionFactory().get_form_submission(
         form_model, cleaned_data, errors, location_tree=location_tree)
     if form_submission.is_valid:
         form_submission.save(self.dbm)
     return create_response_from_form_submission(
         reporters=reporter_names, form_submission=form_submission)
Example #3
0
    def test_should_create_global_form_submission_location_tree(self):
        form_model = self._construct_global_registration_form()
        submission = OrderedDict({"s": "1", "t": "Reporter", "l": "pune", "m": "1212121212"})
        with patch('mangrove.form_model.form_submission.GlobalRegistrationFormSubmission.create_entity') as create_entity:
            entity_mock = Mock(spec=Contact)
            entity_mock.add_data.return_value = 1
            create_entity.return_value = entity_mock

            location_tree = {1: 2}
            form_submission = FormSubmissionFactory().get_form_submission(form_model, submission,
                                                                          location_tree=location_tree)
            data_record_id = form_submission.save(self.dbm)
            self.assertEqual(1, data_record_id)
            self.assertEqual(form_submission.location_tree, location_tree)
 def test_should_give_entity_specific_registration_form_submission(self):
     mocked_form_model = Mock(spec=EntityFormModel)
     mocked_form_model.is_entity_registration_form.return_value = True
     mocked_form_model.is_global_registration_form.return_value = False
     mocked_form_model.entity_type = "clinic"
     mocked_form_model.entity_questions = [ShortCodeField('name','code','label')]
     form_submission = FormSubmissionFactory().get_form_submission(mocked_form_model, OrderedDict(), None)
     self.assertEqual(type(form_submission), EntityRegistrationFormSubmission)
Example #5
0
    def test_should_create_form_submission_with_entity_id(self):
        form_model = self._create_data_submission_form()
        answers = OrderedDict({"id": "1", "q1": "My Name"})

        form_submission = FormSubmissionFactory().get_form_submission(form_model, answers)

        self.assertEqual(form_submission.form_code, "AIDS")
        self.assertEqual(form_submission.short_code, "1")
        self.assertEqual(form_submission.entity_type, [each.lower() for each in ENTITY_TYPE])
Example #6
0
 def handle(self, form_model, cleaned_data, errors, reporter_names,
            location_tree):
     form_submission = FormSubmissionFactory().get_form_submission(
         form_model, cleaned_data, errors, location_tree=location_tree)
     if form_submission.is_valid:
         form_submission.void_existing_data_records(self.dbm,
                                                    form_model.form_code)
         form_submission.update(self.dbm)
     return create_response_from_form_submission(
         reporters=reporter_names, form_submission=form_submission)
 def test_should_give_data_form_submission(self):
     mocked_form_model = MagicMock(spec=FormModel)
     mocked_form_model.entity_type = []
     mocked_form_model.is_entity_registration_form.return_value =False
     form_submission = FormSubmissionFactory().get_form_submission(mocked_form_model, OrderedDict(), None)
     self.assertEqual(type(form_submission), DataFormSubmission)