Пример #1
0
    def test_should_return_submissions_filter_by_test_datasender(self):
        test_submission1 = Submission(self.dbm,
                                      transport_info=TransportInfo(
                                          'web', '127359085', 'destination'),
                                      form_code='test',
                                      values=self.values[1])
        test_submission1._doc.test = True

        test_submission2 = Submission(self.dbm,
                                      transport_info=TransportInfo(
                                          'web', TEST_REPORTER_MOBILE_NUMBER,
                                          'destination'),
                                      form_code='test',
                                      values=self.values[2])
        test_submission2._doc.test = False

        submission_logs = [
            Submission(self.dbm,
                       transport_info=TransportInfo('web',
                                                    '*****@*****.**',
                                                    'destination'),
                       form_code='test',
                       values=self.values[0]), test_submission1,
            test_submission2
        ]

        filtered_submissions = DataSenderFilter('TEST').filter(submission_logs)
        self.assertEqual(1, len(filtered_submissions))
        self.assertEqual(test_submission2.id, filtered_submissions[0].id)
Пример #2
0
    def setUp(self):
        super(SubmissionAnalyzerTest, self).setUp()
        self.org_id = 'SLX364903'
        self._prepare_subjects()

        self.transport = TransportInfo(transport="web",
                                       source="1234",
                                       destination="5678")
        self.form_model_generator = FormModelGenerator(self.manager)
        self.form_model = self.form_model_generator.form_model()
Пример #3
0
    def test_should_return_submissions_filter_by_datasender(self):
        submission_logs = [
            Submission(self.dbm,
                       transport_info=TransportInfo('web',
                                                    '*****@*****.**',
                                                    'destination'),
                       form_code='test',
                       values=self.values[0]),
            Submission(self.dbm,
                       transport_info=TransportInfo('web', '127359085',
                                                    'destination'),
                       form_code='test',
                       values=self.values[1]),
            Submission(self.dbm,
                       transport_info=TransportInfo('web', '0000000000',
                                                    'destination'),
                       form_code='test',
                       values=self.values[2])
        ]

        filtered_submissions = DataSenderFilter(
            '*****@*****.**').filter(submission_logs)
        self.assertEqual(1, len(filtered_submissions))
Пример #4
0
    def _prepare_analyzer_with_one_submission(self,
                                              form_model,
                                              values,
                                              is_for_submission_page=False):
        submission = Submission(self.manager,
                                transport_info=TransportInfo(
                                    'web', '*****@*****.**',
                                    'destination'),
                                form_code=form_model.form_code,
                                values=values)
        self.submission_id = submission.id

        return SubmissionAnalyzer(
            form_model,
            self.manager,
            self.org_id, [submission],
            is_for_submission_page=is_for_submission_page)
Пример #5
0
    def _prepare_analyzer(self,
                          form_model,
                          values_list,
                          keywords=None,
                          is_for_submission_page=False):
        submissions = []
        for values in values_list:
            submission = Submission(self.manager,
                                    transport_info=TransportInfo(
                                        'web', '*****@*****.**',
                                        'destination'),
                                    form_code=form_model.form_code,
                                    values=values)
            submissions.append(submission)

        return SubmissionAnalyzer(
            form_model,
            self.manager,
            self.org_id,
            submissions,
            keywords,
            is_for_submission_page=is_for_submission_page)
Пример #6
0
def submission(request):
    if request.method != 'POST':
        response = HttpResponse(status=204)
        response['Location'] = request.build_absolute_uri()
        return response

    request_user = request.user
    submission_file = request.FILES.get("xml_submission_file").read()

    if not __authorized_to_make_submission_on_requested_form(
            request_user, submission_file):
        response = HttpResponse(status=403)
        return response

    manager = get_database_manager(request_user)
    player = XFormPlayer(manager)
    try:
        mangrove_request = Request(message=submission_file,
                                   transportInfo=TransportInfo(
                                       transport=SMART_PHONE,
                                       source=request_user.email,
                                       destination=''))

        response = player.accept(mangrove_request, logger=sp_submission_logger)

        if response.errors:
            logger.error("Error in submission : \n%s" %
                         get_errors(response.errors))
            return HttpResponseBadRequest()

    except Exception as e:
        logger.exception("Exception in submission : \n%s" % e)
        return HttpResponseBadRequest()

    response = HttpResponse(status=201)
    response['Location'] = request.build_absolute_uri(request.path)
    return response
Пример #7
0
 def setUp(self):
     self.dbm = Mock(spec=DatabaseManager)
     self.mock_form_model = Mock(spec=FormModel)
     self.mock_form_model.entity_question.code = '123'
     self.transport_info = TransportInfo('web', 'source', 'destination')
     self.values = [
         {
             'q1': 'q1',
             'q2': '30.07.2012',
             'entity_question_code': '001'
         },
         {
             'q1': 'q1',
             'q2': '30.08.2012',
             'entity_question_code': '005'
         },
         {
             'q1': 'q1',
             'q2': '30.08.2012',
             'entity_question_code': '002'
         },
     ]
     self.submissions = [
         Submission(self.dbm,
                    self.transport_info,
                    form_code='test',
                    values=self.values[0]),
         Submission(self.dbm,
                    transport_info=self.transport_info,
                    form_code='test',
                    values=self.values[1]),
         Submission(self.dbm,
                    transport_info=self.transport_info,
                    form_code='test',
                    values=self.values[2])
     ]