Пример #1
0
    def test_celery_sketch(self):
        from sketchy.models.capture import Capture
        capture_record = Capture()
        capture_record.url = 'http://xkcd.com'
        db.session.add(capture_record)
        db.session.commit()
        db.session.refresh(capture_record)

        app.config.update(USE_S3=False)
        files_to_write = tasks.do_capture(200, capture_record,
                                          "http://127.0.0.1:7001")
        self.assertEquals(files_to_write['html'], 'xkcd.com_1.html')
        self.assertEquals(files_to_write['sketch'], 'xkcd.com_1.png')
        self.assertEquals(files_to_write['scrape'], 'xkcd.com_1.txt')

        try:
            os.remove(
                os.path.join(app.config['LOCAL_STORAGE_FOLDER'],
                             'xkcd.com_1.html'))
            os.remove(
                os.path.join(app.config['LOCAL_STORAGE_FOLDER'],
                             'xkcd.com_1.png'))
            os.remove(
                os.path.join(app.config['LOCAL_STORAGE_FOLDER'],
                             'xkcd.com_1.txt'))
        except:
            pass
Пример #2
0
    def test_check_url_valid(self):
       from sketchy.models.capture import Capture
       capture_record = Capture()
       capture_record.url = 'http://xkcd.com'
       db.session.add(capture_record)
       db.session.commit()
       db.session.refresh(capture_record)

       rst = tasks.check_url.delay(capture_id=capture_record.id).get()
       self.assertEquals(rst, '200')
Пример #3
0
    def test_check_url_valid(self):
        from sketchy.models.capture import Capture
        capture_record = Capture()
        capture_record.url = 'http://xkcd.com'
        db.session.add(capture_record)
        db.session.commit()
        db.session.refresh(capture_record)

        rst = tasks.check_url.delay(capture_id=capture_record.id).get()
        self.assertEquals(rst, '200')
Пример #4
0
 def test_check_url_invalid(self):
     from sketchy.models.capture import Capture
     capture_record = Capture()
     capture_record.url = 'http://redditsss.com'
     db.session.add(capture_record)
     db.session.commit()
     db.session.refresh(capture_record)
     print capture_record.id
     try:
         rst = tasks.check_url.delay(capture_id=capture_record.id).get()
     except Exception as err:
         self.assertEquals(str(err.message), 'None: Max retries exceeded with url: / (Caused by redirect)')
Пример #5
0
 def test_check_url_invalid(self):
     from sketchy.models.capture import Capture
     capture_record = Capture()
     capture_record.url = 'http://redditsss.com'
     db.session.add(capture_record)
     db.session.commit()
     db.session.refresh(capture_record)
     print capture_record.id
     try:
         rst = tasks.check_url.delay(capture_id=capture_record.id).get()
     except Exception as err:
         self.assertEquals(
             str(err.message),
             'None: Max retries exceeded with url: / (Caused by redirect)')
Пример #6
0
    def post(self):
        """
        Create a new sketch record and call celery tasks for populating record data
        """
        # Determine the hostname/port as well as scheme of webserver
        base_url = app.config['BASE_URL']

        # Parse out all arguments that may be provided by requestor
        args = JSONPARSER.parse_args()
        capture_record = Capture()
        capture_record.url = args["url"]
        capture_record.status_only = args["status_only"]
        capture_record.callback = args["callback"]

        # Add the capture_record and commit to the DB
        try:
            db.session.add(capture_record)
            db.session.commit()
        except IntegrityError, exc:
            return {"error": exc.message}, 500
Пример #7
0
    def test_celery_sketch(self):
        from sketchy.models.capture import Capture
        capture_record = Capture()
        capture_record.url = 'http://xkcd.com'
        db.session.add(capture_record)
        db.session.commit()
        db.session.refresh(capture_record)

        app.config.update(USE_S3=False)
        files_to_write = tasks.do_capture(200, capture_record, "http://127.0.0.1", False)
        self.assertEquals(files_to_write['html'], 'xkcd.com_1.html')
        self.assertEquals(files_to_write['sketch'], 'xkcd.com_1.png')
        self.assertEquals(files_to_write['scrape'], 'xkcd.com_1.txt')

        try:
            os.remove(os.path.join(app.config['LOCAL_STORAGE_FOLDER'], 'xkcd.com_1.html'))
            os.remove(os.path.join(app.config['LOCAL_STORAGE_FOLDER'], 'xkcd.com_1.png'))
            os.remove(os.path.join(app.config['LOCAL_STORAGE_FOLDER'], 'xkcd.com_1.txt'))
        except:
            pass
Пример #8
0
    def post(self):
        """
        Create a new sketch record and call celery tasks for populating record data
        """
        # Determine the hostname/port as well as scheme of webserver
        base_url = app.config['BASE_URL']

        # Parse out all arguments that may be provided by requestor
        args = JSONPARSER.parse_args()
        capture_record = Capture()
        capture_record.url = args["url"]
        capture_record.status_only = args["status_only"]
        capture_record.callback = args["callback"]

        # Add the capture_record and commit to the DB
        try:
            db.session.add(capture_record)
            db.session.commit()
        except IntegrityError, exc:
            return {"error": exc.message}, 500
Пример #9
0
    def get(self):
        """
        Retrieve Capture based on id
        """
        args = EAGERPARSER.parse_args()
        base_url = app.config['BASE_URL']

        app.config.update(USE_S3='')
        # Parse out url and capture type
        capture_record = Capture()
        capture_record.url = args["url"]
        capture_type = args["type"]

        if capture_type not in ['html', 'sketch', 'scrape']:
                return 'Incorrect capture type specified: html, sketch, or scrape', 406

        # Write to DB
        try:
            db.session.add(capture_record)
            db.session.commit()
        except IntegrityError, exc:
            return {"error": exc.message}, 500
Пример #10
0
    def get(self):
        """
        Retrieve Capture based on id
        """
        args = EAGERPARSER.parse_args()
        base_url = app.config['BASE_URL']

        app.config.update(USE_S3='')
        # Parse out url and capture type
        capture_record = Capture()
        capture_record.url = args["url"]
        capture_type = args["type"]

        if capture_type not in ['html', 'sketch', 'scrape']:
            return 'Incorrect capture type specified: html, sketch, or scrape', 406

        # Write to DB
        try:
            db.session.add(capture_record)
            db.session.commit()
        except IntegrityError, exc:
            return {"error": exc.message}, 500