예제 #1
0
파일: test_models.py 프로젝트: sau29/scale
    def test_save_job_error_models(self):
        """Tests successfully calling save_job_error_models()"""

        job_type_name = 'job_type_1_for_error_test'
        error_model_1 = Error()
        error_model_1.name = 'error_1'
        error_model_1.job_type_name = job_type_name
        error_model_1.title = 'Error 1'
        error_model_1.description = 'This is a description'
        error_model_1.category = 'ALGORITHM'
        error_model_2 = Error()
        error_model_2.name = 'error_2'
        error_model_2.job_type_name = job_type_name

        # Test saving models for the first time
        Error.objects.save_job_error_models(job_type_name,
                                            [error_model_1, error_model_2])
        self.assertEqual(
            Error.objects.filter(job_type_name=job_type_name).count(), 2)

        # Make some changes
        error_model_1.description = 'New description'
        error_model_2.category = 'DATA'

        # Test updating models
        Error.objects.save_job_error_models(job_type_name,
                                            [error_model_1, error_model_2])
        self.assertEqual(
            Error.objects.get(name='error_1').description, 'New description')
        self.assertEqual(Error.objects.get(name='error_2').category, 'DATA')
예제 #2
0
 def testCount(self):
     for x in range(0, 1110):
         Error().save(dont_send_signals=True)
     assert count() == 1110
     for x in range(0, 5):
         err = Error(dont_send_signals=True)
         err.priority = 4
         err.save()
     assert count(["priority = ", 4]) == 5
     assert count(["priority = ", None]) == 1110
     assert count() == 1115
예제 #3
0
def post(request):
    """ Add in a post """
    log("Processing email message")
    mailobj = mail.InboundEmailMessage(request.raw_post_data)
    to = mailobj.to

    if to in settings.ALLOWED_RECEIVING_ADDRESSES:
        key = settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER
    else:
        key = to.split("-", 1)[1].split("@")[0]
        if key != settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER:
            log("To address (%s, to %s) does not match account number (%s)" %
                (key, to, settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER))
            return

    for content_type, body in mailobj.bodies("text/plain"):
        if mailobj.subject.find(" Broken ") > -1:
            log("Trying to parse body using 404 parser")
            result = parse_404(body, mailobj.subject)
        else:
            log("Trying to parse body using 500 parser")
            result = parse_500(body, mailobj.subject)
        err = Error()
        result["account"] = key
        populate(err, result)

    return render_plain("message parsed")
예제 #4
0
def post(request):
    """ Add in a post """
    err = Error()
    err.ip = request.META.get("REMOTE_ADDR", "")
    err.user_agent = request.META.get("HTTP_USER_AGENT", "")

    populate(err, request.POST)
    return render_plain("Error recorded")
예제 #5
0
def parse(content_type, body):
    data = body.decode()
    if data.rfind("}") > 0:
        # strip out any crap on the end
        end = data.rfind("}")
        # not sure why i was doing this, i'm sure there
        # was a good reason at one point
        text = data[:end] + "}"
        err = Error()
        json = loads(text, strict=False)
        populate(err, json)
        return True
예제 #6
0
파일: error.py 프로젝트: sau29/scale
    def create_model(self):
        """Creates an error model representing this job error

        :returns: The error model
        :rtype: :class:`error.models.Error`
        """

        error_model = Error()
        error_model.name = self.name
        error_model.job_type_name = self.job_type_name
        error_model.title = self.title
        error_model.description = self.description
        error_model.category = self.category

        return error_model
예제 #7
0
파일: test_models.py 프로젝트: sau29/scale
    def test_get_job_error(self):
        """Tests successfully calling get_job_error()"""

        job_type_name = 'job_type_1'
        error_model = Error()
        error_model.name = 'error_1'
        error_model.job_type_name = job_type_name
        error_model.title = 'Error 1'
        error_model.description = 'This is a description'
        error_model.category = 'ALGORITHM'
        Error.objects.save_job_error_models(job_type_name, [error_model])

        # Test retrieving error model, which will load it into the cache
        error_model = get_job_error(job_type_name, 'error_1')
        self.assertEqual(error_model.name, 'error_1')
예제 #8
0
    def _setup(self):
        self.project = Project(name="testing")
        self.project.save()

        self.url = ProjectURL(url="http://test.areciboapp.com")
        self.url.project = self.project
        self.url.save()

        self.url = ProjectURL(url="http://www.areciboapp.com")
        self.url.project = self.project
        self.url.save()

        self.error = Error()
        for k, v in break_url("http://test.areciboapp.com/an/other").items():
            setattr(self.error, k, v)
        self.error.save()
예제 #9
0
def create_error():
    return Error(timestamp=datetime.now(), timestamp_date=datetime.today())
예제 #10
0
def populate(incoming):
    """ Populate the error table with the incoming error """
    # special lookup the account
    err = Error()
    uid = incoming.get("account", "")
    if not settings.ANONYMOUS_POSTING:
        if not uid:
            raise ValueError, "Missing the required account number."

        if str(uid) != settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER:
            raise ValueError, "Account number does not match"

    # special
    if incoming.has_key("url"):
        for k, v in break_url(incoming["url"]).items():
            setattr(err, k, v)

    # check the status codes
    if incoming.has_key("status"):
        status = str(incoming["status"])
        try:
            valid_status(status)
            err.status = status
        except StatusDoesNotExist:
            err.errors += "Status does not exist, ignored.\n"

    # not utf-8 encoded
    for src, dest in [
        ("ip", "ip"),
        ("user_agent", "user_agent"),
        ("uid", "uid"),
    ]:
        actual = incoming.get(src, None)
        if actual is not None:
            setattr(err, dest, str(actual))

    try:
        priority = int(incoming.get("priority", 0))
    except ValueError:
        priority = 0
    err.priority = min(priority, 10)

    # possibly utf-8 encoding
    for src, dest in [("type", "type"), ("msg", "msg"), ("server", "server"),
                      ("traceback", "traceback"), ("request", "request"),
                      ("username", "username")]:
        actual = incoming.get(src, None)
        if actual is not None:
            try:
                setattr(err, dest, actual.encode("utf-8"))
            except UnicodeDecodeError:
                err.errors += "Encoding error on the %s field, ignored.\n" % src

    # timestamp handling
    if "timestamp" in incoming:
        tmstmp = incoming["timestamp"].strip()
        if tmstmp.endswith("GMT"):
            tmstmp = tmstmp[:-3] + "-0000"
        tme = parsedate(tmstmp)
        if tme:
            try:
                final = datetime(*tme[:7])
                err.error_timestamp = final
                err.error_timestamp_date = final.date()
            except ValueError, msg:
                err.errors += 'Date error on the field "%s", ignored.\n' % msg