Beispiel #1
0
    def transfer_file(self, compress_with=None):
        """Initiate transfer via HTTPS

        :param compress_with: if document isn't already compressed and
          this is set, compress the file before transfering.

        """
        filename = self.document['filename']

        config = Config()
        upload_url = config.get('distribute', 'upload_url')
        user = config.get('distribute', 'username')
        pw = config.get('distribute', 'password')
        payload = {'siteShortName': self.document['reportable_region']}

        content = self.extract_content(compress_with)
        files = {'userfile': content}

        if inProduction():
            logging.info("POST %s to %s" % (filename, upload_url))
            r = requests.post(upload_url, auth=(user, pw), files=files,
                              data=payload)
            # We only get redirected if successful!
            if r.status_code != 302:
                logging.error("failed distrbute POST")
                #Can't rely on status_code, as distribute returns 200
                #with problems in the body.
                logging.error("".join(list(r.iter_content())))
                r.raise_for_status()
            else:
                self.record_transfer()
        else:
            logging.warn("inProduction() check failed, not POSTing "
                         "file '%s' to '%s'", filename, upload_url)
Beispiel #2
0
    def transfer_file(self, compress_with=None):
        """Initiate transfer via PHIN-MS

        Copy the file into the directory PHIN-MS is configured to
        poll.  NB - this method is doing nothing to confirm it is
        sent, that is left to the watchdog.

        :param compress_with: if document isn't already compressed and
          this is set, compress the file before transfering.

        """
        self._set_report_type(self.document.get('report_type', None),
                              self.document.get('patient_class', None))
        filename = self.document['filename']
        dest = os.path.join(self.outbound_dir, filename)
        content = self.extract_content(compress_with)

        if inProduction():
            logging.info("write %s to %s" % (filename, dest))
            with open(dest, 'wb') as destination:
                destination.write(content.read())
            self.record_transfer()
        else:
            logging.warn("inProduction() check failed, not sending "
                         "file '%s' to '%s'", filename, dest)
Beispiel #3
0
    def testDistributeTransfer(self):
        # need a document in the db
        self.create_test_file(compression='gzip',
                              reportable_region='wae')

        # fake a transfer of this object
        context = DistributeTransfer(testing.DummyRequest())
        context.request.fs = self.fs
        context.request.document_store = self.document_store
        context = context[str(self.oid)]
        self.assertFalse(inProduction())  # avoid accidental transfers!
        context.transfer_file()
Beispiel #4
0
    def testPhinmsTransfer(self):
        # need a document in the db
        self.create_test_file(compression='gzip',
                              report_type='longitudinal')

        # fake a transfer of this object
        context = PHINMS_Transfer(testing.DummyRequest())
        context.request.fs = self.fs
        context.request.document_store = self.document_store
        context = context[str(self.oid)]
        self.assertFalse(inProduction())  # avoid accidental transfers!
        context.transfer_file()

        self.assertEqual(self.report_type, 'longitudinal')
        config = Config()
        path = config.get('phinms', self.report_type)
        self.assertEqual(context.outbound_dir, path)
Beispiel #5
0
def test_inProcution():
    """testing - shouldn't be inProduction!"""
    assert(inProduction() == False)
Beispiel #6
0
def test_inProcution():
    """testing - shouldn't be inProduction!"""
    assert (inProduction() == False)