def test_should_send_ats_request_and_parse_response_codes(self):
        responses.add(responses.POST, settings.ATS_URL, content_type='text/xml',
                      body=self.ATS_SMS_REQUEST_RESPONSE_SENT.format(*self.ATS_TEST_UNIQ), status=200)
        sms1 = OutputSMSFactory(pk=self.ATS_TEST_UNIQ[0], **self.ATS_OUTPUT_SMS1)
        sms2 = OutputSMSFactory(pk=self.ATS_TEST_UNIQ[1], **self.ATS_OUTPUT_SMS2)

        response = send_ats_requests(sms1, sms2)

        assert_equal(response.request.url, 'http://fik.atspraha.cz/gwfcgi/XMLServerWrapper.fcgi')
        assert_equal(response.request.headers['content-type'], 'text/xml')

        response_codes = parse_response_codes(response.text)

        assert_equal(response_codes[self.ATS_TEST_UNIQ[0]], 0)
        assert_equal(response_codes[self.ATS_TEST_UNIQ[1]], 123456)
Exemple #2
0
    def test_should_send_ats_request_and_parse_response_codes(self, prefix):
        responses.add(responses.POST, settings.ATS_SMS_URL, content_type='text/xml', status=200,
                      body=self.ATS_SMS_REQUEST_RESPONSE_SENT.format(prefix=prefix, **self.ATS_TEST_UNIQ))
        sms1 = OutputSMSFactory(pk=self.ATS_TEST_UNIQ['uniq1'], **self.ATS_OUTPUT_SMS1)
        sms2 = OutputSMSFactory(pk=self.ATS_TEST_UNIQ['uniq2'], **self.ATS_OUTPUT_SMS2)

        response = send_ats_requests(sms1, sms2)

        assert_equal(response.request.url, 'http://fik.atspraha.cz/gwfcgi/XMLServerWrapper.fcgi')
        assert_equal(response.request.headers['content-type'], 'text/xml')

        response_codes = parse_response_codes(response.text)

        assert_equal(response_codes[self.ATS_TEST_UNIQ['uniq1']], 0)
        assert_equal(response_codes[self.ATS_TEST_UNIQ['uniq2']], 123456)
    def test_should_correctly_handle_unknown_ats_state(self):
        responses.add(responses.POST, settings.ATS_URL, content_type='text/xml',
                      body=self.ATS_UNKNOW_STATE_RESPONSE, status=200)
        sms1 = OutputSMSFactory(pk=self.ATS_TEST_UNIQ[0], **self.ATS_OUTPUT_SMS1)
        sms2 = OutputSMSFactory(pk=self.ATS_TEST_UNIQ[1], **self.ATS_OUTPUT_SMS2)

        response = send_ats_requests(sms1, sms2)
        with open('./var/log/ats_sms.log') as ats_log:
            log_lines_count = sum(1 for _ in ats_log)
            response_codes = parse_response_codes(response.text)
            ats_log.seek(0)
            log_lines = ats_log.readlines()

            assert_equal(log_lines_count + 1, len(log_lines))
            assert_true('999' in log_lines[-1])
            assert_false(response_codes)
Exemple #4
0
    def test_should_correctly_handle_unknown_ats_state(self):
        responses.add(responses.POST, settings.ATS_SMS_URL, content_type='text/xml',
                      body=self.ATS_UNKNOW_STATE_RESPONSE, status=200)
        sms1 = OutputSMSFactory(pk=self.ATS_TEST_UNIQ['uniq1'], **self.ATS_OUTPUT_SMS1)
        sms2 = OutputSMSFactory(pk=self.ATS_TEST_UNIQ['uniq2'], **self.ATS_OUTPUT_SMS2)

        response = send_ats_requests(sms1, sms2)
        with open('./var/log/ats_sms.log') as ats_log:
            log_lines_count = sum(1 for _ in ats_log)
            response_codes = parse_response_codes(response.text)
            ats_log.seek(0)
            log_lines = ats_log.readlines()

            assert_equal(log_lines_count + 1, len(log_lines))
            assert_true('999' in log_lines[-1])
            assert_false(response_codes)