Beispiel #1
0
    def setUp(self):
        v = Version()
        v.save()
        self.v = v
        TestItemA.objects.create(label='a1',version_first=v)
        TestItemA.objects.create(label='a2',version_first=v)
        TestItemB.objects.create(label='b1',version_first=v)
        TestItemB.objects.create(label='b2',version_first=v)
        TestItemC.objects.create(label='c1',version_first=v)
        TestItemC.objects.create(label='c2',version_first=v)
        a1 = TestItemA.objects.get(pk=1)
        a2 = TestItemA.objects.get(pk=2)
        b1 = TestItemB.objects.get(pk=1)
        b2 = TestItemB.objects.get(pk=2)
        c1 = TestItemC.objects.get(pk=1)
        c2 = TestItemC.objects.get(pk=2)

        TestData.objects.create(testitema=a1,testitemb=b1,testitemc=c1,value=1,version_first=v)
        TestData.objects.create(testitema=a1,testitemb=b1,testitemc=c2,value=2,version_first=v)
        TestData.objects.create(testitema=a1,testitemb=b2,testitemc=c1,value=3,version_first=v)
        TestData.objects.create(testitema=a1,testitemb=b2,testitemc=c2,value=4,version_first=v)
        TestData.objects.create(testitema=a2,testitemb=b1,testitemc=c1,value=5,version_first=v)
        TestData.objects.create(testitema=a2,testitemb=b1,testitemc=c2,value=6,version_first=v)
        TestData.objects.create(testitema=a2,testitemb=b2,testitemc=c1,value=7,version_first=v)
        TestData.objects.create(testitema=a2,testitemb=b2,testitemc=c2,value=8,version_first=v)


        TestMappings.objects.create(testitema=a1,testitemb=b1,testitemc=c1,version_first=v)
        TestMappings.objects.create(testitema=a1,testitemb=b1,testitemc=c2,version_first=v)
        TestMappings.objects.create(testitema=a1,testitemb=b2,testitemc=c1,version_first=v)
        TestMappings.objects.create(testitema=a1,testitemb=b2,testitemc=c2,version_first=v)
        TestMappings.objects.create(testitema=a2,testitemb=b1,testitemc=c1,version_first=v)
        TestMappings.objects.create(testitema=a2,testitemb=b1,testitemc=c2,version_first=v)
        TestMappings.objects.create(testitema=a2,testitemb=b2,testitemc=c1,version_first=v)
        TestMappings.objects.create(testitema=a2,testitemb=b2,testitemc=c2,version_first=v)
 def setUp(self):
     v = Version()
     v.save()
     TestItemA.objects.create(label='a1', version_first=v)
     TestItemA.objects.create(label='a2', version_first=v)
     TestItemB.objects.create(label='b1', version_first=v)
     TestItemB.objects.create(label='b2', version_first=v, version_last=v)
     TestItemC.objects.create(label='c1', version_first=v)
     TestItemC.objects.create(label='c2', version_first=v)
Beispiel #3
0
    def get_top_crashes(self, version=None, time=None, limit=None):
        res = self.get_queryset()

        if version is not None:
            version_filter_params = Version.get_filter_params(version, prefix='version__')
            res = res.filter(**version_filter_params)

        if time is not None:
            target = timezone.now() - timedelta(days=time)
            res = res.filter(upload_time__gte=target)

        res = res.values('os_name', 'signature').annotate(Count('os_name'))

        data = {}
        for entry in res:
            signature = entry['signature']
            if not signature in data:
                data[signature] = CrashByVersionData(signature)
            count = entry['os_name__count']
            data[signature].all += count
            if entry['os_name'] == 'linux':
                data[signature].lin = count
            elif entry['os_name'] == 'windows':
                data[signature].win = count
        values = data.values()
        sorted_values = sorted(values, key=CrashByVersionData.getKey)

        num_entries = len(values)
        if limit is not None and num_entries > limit:
            values = sorted_values[num_entries-limit:]

        return values
Beispiel #4
0
    def get_top_crashes(self, version=None, time=None, limit=None):
        res = self.get_queryset()

        if version is not None:
            version_filter_params = Version.get_filter_params(version, prefix="version__")
            res = res.filter(**version_filter_params)

        if time is not None:
            target = timezone.now() - timedelta(days=time)
            res = res.filter(upload_time__gte=target)

        res = res.values("os_name", "signature").annotate(Count("os_name"))

        data = {}
        for entry in res:
            signature = entry["signature"]
            if not signature in data:
                data[signature] = CrashByVersionData(signature)
            count = entry["os_name__count"]
            data[signature].all += count
            if entry["os_name"] == "linux":
                data[signature].lin = count
            elif entry["os_name"] == "windows":
                data[signature].win = count
        values = data.values()
        sorted(values, key=CrashByVersionData.getKey)
        if limit is not None and len(values) > limit:
            values = values[0:limit]
        return values
Beispiel #5
0
    def get_top_crashes(self, version=None, time=None, limit=None):
        res = self.get_queryset()

        if version is not None:
            version_filter_params = Version.get_filter_params(version, prefix='version__')
            res = res.filter(**version_filter_params)

        if time is not None:
            target = timezone.now() - timedelta(days=time)
            res = res.filter(upload_time__gte=target)

        res = res.values('os_name', 'signature').annotate(Count('os_name'))

        data = {}
        for entry in res:
            signature = entry['signature']
            if not signature in data:
                data[signature] = CrashByVersionData(signature)
            count = entry['os_name__count']
            data[signature].all += count
            if entry['os_name'] == 'linux':
                data[signature].lin = count
            elif entry['os_name'] == 'windows':
                data[signature].win = count
        values = data.values()
        sorted_values = sorted(values, key=CrashByVersionData.getKey)

        num_entries = len(values)
        if limit is not None and num_entries > limit:
            values = sorted_values[num_entries-limit:]

        return values
Beispiel #6
0
    def setUp(self):
        self.context = []
        self.v1 = Version()
        self.v1.set_version_id("")
        self.v1.save()
        self.v2 = Version()
        self.v2.set_version_id("")
        self.v2.save()

        TestItemA.objects.create(label='a1', version_first=self.v1)
        TestItemA.objects.create(label='a2', version_first=self.v1)
        TestItemB.objects.create(label='b1', version_first=self.v1)
        TestItemB.objects.create(label='b2', version_first=self.v1)
        TestItemC.objects.create(label='c1', version_first=self.v1)
        TestItemC.objects.create(label='c2', version_first=self.v1)

        self.a1 = TestItemA.objects.get(label='a1')
        self.a2 = TestItemA.objects.get(label='a2')
        self.b1 = TestItemB.objects.get(label='b1')
        self.b2 = TestItemB.objects.get(label='b2')
        self.c1 = TestItemC.objects.get(label='c1')
        self.c2 = TestItemC.objects.get(label='c2')

        TestData.objects.create(testitema=self.a1,
                                testitemb=self.b1,
                                testitemc=self.c1,
                                value=1,
                                version_first=self.v1)
        TestData.objects.create(testitema=self.a1,
                                testitemb=self.b1,
                                testitemc=self.c2,
                                value=2,
                                version_first=self.v1)
        TestData.objects.create(testitema=self.a1,
                                testitemb=self.b2,
                                testitemc=self.c1,
                                value=3,
                                version_first=self.v1)
        TestData.objects.create(testitema=self.a1,
                                testitemb=self.b2,
                                testitemc=self.c1,
                                value=4)

        self.r1 = TestData.objects.get(value=1)
        self.r2 = TestData.objects.get(value=2)
        self.r3a = TestData.objects.get(value=3)
        self.r3b = TestData.objects.get(value=4)
Beispiel #7
0
 def get_queryset(self):
     self.signature_obj = get_object_or_404(
         Signature, signature=self.kwargs['signature'])
     version = self.request.GET.get('version', None)
     crashes = self.signature_obj.processedcrash_set.all()
     if version is not None:
         version_filter_params = Version.get_filter_params(
             version, prefix='version__')
         crashes = crashes.filter(**version_filter_params)
     return crashes
Beispiel #8
0
def add_version(request, version):
    if request.method != 'POST':
        return HttpResponseNotAllowed('Only POST allowed')

    parsed = Version.get_filter_params(version)
    if len(parsed) != 4:
        return HttpResponseBadRequest('Bad version string')

    Version.objects.create_from_string(version)
    return HttpResponse('Version added')
Beispiel #9
0
    def setUp(self):
        self.context = []
        v1 = Version()
        v1.set_version_id("")
        v1.save()
        v2 = Version()
        v2.set_version_id("")
        v2.save()

        TestItemA.objects.create(label='a1', version_first=v1)
        TestItemA.objects.create(label='a2', version_first=v1)
        TestItemB.objects.create(label='b1', version_first=v1, version_last=v2)
        TestItemB.objects.create(label='b2', version_first=v1)
        TestItemC.objects.create(label='c1', version_first=v1)
        TestItemC.objects.create(label='c2', version_first=v1)

        self.a1 = TestItemA.objects.get(label='a1')
        self.a2 = TestItemA.objects.get(label='a2')
        self.b1 = TestItemB.objects.get(label='b1')
        self.b2 = TestItemB.objects.get(label='b2')
        self.c1 = TestItemC.objects.get(label='c1')
        self.c2 = TestItemC.objects.get(label='c2')
    def setUp(self):
        self.context = []
        v1 = Version()
        v1.set_version_id("1")
        v1.save()
        v2 = Version()
        v2.set_version_id("2")
        v2.save()

        self.v1 = v1
        self.v2 = v2

        TestItemA.objects.create(label='a1', version_first=v1)
        TestItemA.objects.create(label='a2', version_first=v1)
        TestItemB.objects.create(label='b1', version_first=v1)
        TestItemB.objects.create(label='b2', version_first=v1)
        TestItemC.objects.create(label='c1', version_first=v1)
        TestItemC.objects.create(label='c2', version_first=v1)

        a1 = TestItemA.objects.get(label='a1')
        a2 = TestItemA.objects.get(label='a2')
        b1 = TestItemB.objects.get(label='b1')
        b2 = TestItemB.objects.get(label='b2')
        c1 = TestItemC.objects.get(label='c1')
        c2 = TestItemC.objects.get(label='c2')

        self.a1 = a1
        self.a2 = a2
        self.b1 = b1
        self.b2 = b2
        self.c1 = c1
        self.c2 = c2

        TestData.objects.create(testitema=a1,
                                testitemb=b1,
                                testitemc=c1,
                                value=1,
                                version_first=v1)
        TestData.objects.create(testitema=a1,
                                testitemb=b1,
                                testitemc=c2,
                                value=2,
                                version_first=v1)
        TestData.objects.create(testitema=a1,
                                testitemb=b2,
                                testitemc=c1,
                                value=13,
                                version_first=v1,
                                version_last=v2)
        TestData.objects.create(testitema=a1,
                                testitemb=b2,
                                testitemc=c2,
                                value=14,
                                version_first=v1,
                                version_last=v2)
        TestData.objects.create(testitema=a1,
                                testitemb=b2,
                                testitemc=c1,
                                value=3,
                                version_first=v2)
        TestData.objects.create(testitema=a1,
                                testitemb=b2,
                                testitemc=c2,
                                value=4,
                                version_first=v2)
        TestData.objects.create(testitema=a2,
                                testitemb=b1,
                                testitemc=c1,
                                value=5,
                                version_first=v1)
        TestData.objects.create(testitema=a2,
                                testitemb=b1,
                                testitemc=c2,
                                value=6,
                                version_first=v1)
        TestData.objects.create(testitema=a2,
                                testitemb=b2,
                                testitemc=c1,
                                value=17,
                                version_first=v1,
                                version_last=v2)
        TestData.objects.create(testitema=a2,
                                testitemb=b2,
                                testitemc=c2,
                                value=18,
                                version_first=v1,
                                version_last=v2)
        TestData.objects.create(testitema=a2,
                                testitemb=b2,
                                testitemc=c1,
                                value=7,
                                version_first=v2)
        TestData.objects.create(testitema=a2,
                                testitemb=b2,
                                testitemc=c2,
                                value=8,
                                version_first=v2)
Beispiel #11
0
 def get_crashes_for_version(self, version):
     res = self.get_queryset()
     version_filter_params = Version.get_filter_params(version, prefix='version__')
     res = res.filter(**version_filter_params)
     return res
    def setUp(self):
        self.context = []
        v1 = Version()
        v1.set_version_id("")
        v1.save()
        v2 = Version()
        v2.set_version_id("")
        v2.save()

        TestItemA.objects.create(label='a1',version_first=v1)
        TestItemA.objects.create(label='a2',version_first=v1)
        TestItemB.objects.create(label='b1',version_first=v1)
        TestItemB.objects.create(label='b2',version_first=v1)
        TestItemC.objects.create(label='c1',version_first=v1)
        TestItemC.objects.create(label='c2',version_first=v1)
        TestItemC.objects.create(label='c3',version_first=v1)
        TestItemC.objects.create(label='c4',version_first=v1)

        a1 = TestItemA.objects.get(label='a1')
        a2 = TestItemA.objects.get(label='a2')
        b1 = TestItemB.objects.get(label='b1')
        b2 = TestItemB.objects.get(label='b2')
        c1 = TestItemC.objects.get(label='c1')
        c2 = TestItemC.objects.get(label='c2')
        c3 = TestItemC.objects.get(label='c3')
        c4 = TestItemC.objects.get(label='c4')

        self.a1 = a1
        self.a2 = a2
        self.b1 = b1
        self.b2 = b2
        self.c1 = c1
        self.c2 = c1
        self.c3 = c1
        self.c4 = c1

# Current version                       Archived version
#  a column         b column            a column        b column
#       a1  a2          b1  b2               a1  a2          b1  b2
#  b1   c1  c3      a1  c1  c2          b1   c2  c4      a1  c2  c2
#  b2   c2  c4      a2  c3  c4          b2   c2  c4      a2  c4  c4
 
        TestMappings.objects.create(testitema=a1,testitemb=b1,testitemc=c2,version_first=v1,version_last=v2)
        TestMappings.objects.create(testitema=a2,testitemb=b1,testitemc=c4,version_first=v1,version_last=v2)
        TestMappings.objects.create(testitema=a1,testitemb=b1,testitemc=c1,version_first=v1)
        TestMappings.objects.create(testitema=a1,testitemb=b2,testitemc=c2,version_first=v1)
        TestMappings.objects.create(testitema=a2,testitemb=b1,testitemc=c3,version_first=v2)
        TestMappings.objects.create(testitema=a2,testitemb=b2,testitemc=c4,version_first=v1)
    def setUp(self):
        self.context = []

        v1 = Version()
        v1.set_version_id("")
        v1.save()
        v2 = Version()
        v2.set_version_id("")
        v2.save()

        TestItemA.objects.create(label='a1', version_first=v1)
        TestItemB.objects.create(label='b1', version_first=v1)
        TestItemC.objects.create(label='c1', version_first=v1)

        a1 = TestItemA.objects.get(label='a1')
        b1 = TestItemB.objects.get(label='b1')
        c1 = TestItemC.objects.get(label='c1')

        TestMappings.objects.create(testitema=a1,
                                    testitemb=b1,
                                    testitemc=c1,
                                    version_first=v1)
Beispiel #14
0
class TableModelTestCase(TestCase):
    """Testing AssessModel()."""
    def setUp(self):
        self.context = []
        self.v1 = Version()
        self.v1.set_version_id("")
        self.v1.save()
        self.v2 = Version()
        self.v2.set_version_id("")
        self.v2.save()

        TestItemA.objects.create(label='a1', version_first=self.v1)
        TestItemA.objects.create(label='a2', version_first=self.v1)
        TestItemB.objects.create(label='b1', version_first=self.v1)
        TestItemB.objects.create(label='b2', version_first=self.v1)
        TestItemC.objects.create(label='c1', version_first=self.v1)
        TestItemC.objects.create(label='c2', version_first=self.v1)

        self.a1 = TestItemA.objects.get(label='a1')
        self.a2 = TestItemA.objects.get(label='a2')
        self.b1 = TestItemB.objects.get(label='b1')
        self.b2 = TestItemB.objects.get(label='b2')
        self.c1 = TestItemC.objects.get(label='c1')
        self.c2 = TestItemC.objects.get(label='c2')

        TestData.objects.create(testitema=self.a1,
                                testitemb=self.b1,
                                testitemc=self.c1,
                                value=1,
                                version_first=self.v1)
        TestData.objects.create(testitema=self.a1,
                                testitemb=self.b1,
                                testitemc=self.c2,
                                value=2,
                                version_first=self.v1)
        TestData.objects.create(testitema=self.a1,
                                testitemb=self.b2,
                                testitemc=self.c1,
                                value=3,
                                version_first=self.v1)
        TestData.objects.create(testitema=self.a1,
                                testitemb=self.b2,
                                testitemc=self.c1,
                                value=4)

        self.r1 = TestData.objects.get(value=1)
        self.r2 = TestData.objects.get(value=2)
        self.r3a = TestData.objects.get(value=3)
        self.r3b = TestData.objects.get(value=4)

    def test_commit(self):
        """Test that uncommitted rows are committed by setting version_last"""
        # Filters for current (fc) and proposed (fc)
        fc = {'version_first__isnull': False, 'version_last__isnull': True}
        fp = {'version_first__isnull': True, 'version_last__isnull': True}
        # Only the first two records are current
        current_records = list(TestData.objects.filter(**fc))
        self.assertEqual(current_records, [self.r1, self.r2, self.r3a])
        # Now commit the third record using AssessModel.commit()
        all_records = TestData.objects.filter(**fp)
        for record in all_records:
            record.commit(self.v2)
        current_records = list(TestData.objects.filter(**fc))
        self.assertEqual(current_records, [self.r1, self.r2, self.r3b])

    def test_set_from_cell_success(self):
        """Test that cell values can be set from single and multi-column"""
        t = TestData()
        t.set_fk_labels_objects()
        # Test the value table format
        key = {'testitema': 'a1', 'testitemb': 'b1', 'testitemc': 'c1'}
        header = 'value'
        value = '4'
        column_field = 'value'
        t.set_from_cell(key, header, value, column_field)
        self.assertEqual(t.value, Decimal('4'))
        # Test multicolumn with c as column
        key = {'testitema': 'a1', 'testitemb': 'b1'}
        header = 'c1'
        value = '5'
        column_field = 'testitemc'
        t.set_from_cell(key, header, value, column_field)
        self.assertEqual(t.value, Decimal('5'))
        # Test multicolumn with b as column
        key = {'testitema': 'a1', 'testitemc': 'c1'}
        header = 'b1'
        value = '6'
        column_field = 'testitemb'
        t.set_from_cell(key, header, value, column_field)
        self.assertEqual(t.value, Decimal('6'))

    def test_set_from_cell_failure(self):
        """Test that wrong headers and fields raises Exceptions"""
        t = TestData()
        t.set_fk_labels_objects()
        # Test the value table format
        key = {'testitema': 'a1', 'testitemb': 'b1', 'testitemc': 'c1'}
        value = '4'
        column_field = 'value'
        # bad header field should raise a NoFieldError for header
        header = 'bad_header_name'
        try:
            t.set_from_cell(key, header, value, column_field)
        except NoFieldError as e:
            e_msg = str(e)
        self.assertEqual(e_msg, str(NoFieldError('bad_header_name', TestData)))
        # bad value_field should raise a NoItemError for value_field
        column_field = 'bad_column_field'
        header = 'value'
        try:
            t.set_from_cell(key, header, value, column_field)
        except NoFieldError as e:
            e_msg = str(e)
        self.assertEqual(e_msg, str(NoFieldError('bad_column_field',
                                                 TestData)))
        # Bad header in multi-column should raise NoItemError for header
        key = {'testitema': 'a1', 'testitemb': 'b1'}
        value = '4'
        column_field = 'testitemc'
        header = 'bad_item_name'
        try:
            t.set_from_cell(key, header, value, column_field)
        except NoFieldError as e:
            e_msg = str(e)
        self.assertEqual(e_msg, str(NoItemError('bad_item_name', TestItemC)))

    def test_set_from_record_success(self):
        """Test that a record dict will update the model value."""
        t = TestData()
        t.set_fk_labels_objects()
        r = {
            'testitema': 'a1',
            'testitemb': 'b1',
            'testitemc': 'c1',
            'value': '4'
        }
        t.set_from_record_dict(r)
        self.assertEqual(t.value, Decimal('4'))

    def test_set_from_record_failure(self):
        """Test that a record dict will update the model value."""
        t = TestData()
        t.set_fk_labels_objects()
        # Bad index name should raise NoFieldError
        r = {
            'bad_index_name': 'a1',
            'testitemb': 'b1',
            'testitemc': 'c1',
            'value': '4'
        }
        try:
            t.set_from_record_dict(r)
        except NoFieldError as e:
            e_msg = str(e)
        self.assertEqual(e_msg, str(NoFieldError('bad_index_name', TestData)))
        # Missing index fields in record dict should raise NoFieldError
        r = {'testitema': 'a1', 'testitemb': 'b1', 'value': '4'}
        try:
            t.set_from_record_dict(r)
        except NoFieldError as e:
            e_msg = str(e)
        self.assertEqual(e_msg, str(NoFieldError('testitemc', TestData)))
        # Bad value name should raise NoITemError
        r = {
            'testitema': 'bad_item',
            'testitemb': 'b1',
            'testitemc': 'c1',
            'value': '4'
        }
        try:
            t.set_from_record_dict(r)
        except NoItemError as e:
            e_msg = str(e)
        self.assertEqual(e_msg, str(NoItemError('bad_item', TestItemA)))
        # Missing value_field should raise NoFieldError
        r = {'testitema': 'a1', 'testitemb': 'b1', 'testitemc': 'c1'}
        try:
            t.set_from_record_dict(r)
        except NoFieldError as e:
            e_msg = str(e)
        self.assertEqual(e_msg, str(NoFieldError('value', TestData)))