Beispiel #1
0
    def setUp(self):

        #the memcache will contain values that will break the tests
        #dont run this on production!
        memcache.flush_all()

        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Create a consistency policy that will simulate the High Replication consistency model.
        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=0)
        # Initialize the datastore stub with this policy.
        self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)

        millis = int(round(time.time() * 1000))

        tree_name = 'test_tree' + str(millis)

        username = '******' + str(millis)

        self.parent_branch = Branch(id=tree_name)

        self.parent_branch.author_name = username
        self.parent_branch.link = ''
        self.parent_branch.content = ''
        self.parent_branch.put()

        self.child_branchs = []
 def create(self, request, **kwargs):
     serializer = BranchSerializer(data=request.data)
     if serializer.is_valid():
         user = save_user(request.data, UserPermissions.IS_BRANCH)
         company = Company(**request.data["company"])
         city = City(**request.data["city"])
         branch = Branch(
             nickName=request.data["nickName"],
             type=UserType.BRANCH,
             address=request.data["address"],
             phone=request.data["phone"],
             company=company,
             city=city,
             user=user,
         )
         branch.save()
         return Response(
             {
                 "status": "SUCCESS",
                 "msg_status": "Sucursal creada satisfactoriamente. Puede ingresar con su nueva contrasena.",
             }
         )
     else:
         messages = []
         make_error(serializer.errors.values(), messages)
         return Response({"status": "FAILURE", "msg_status": messages})
Beispiel #3
0
 def execute(id):
     if Branch.get_by_key_name(key):
         error[0] = 'Branch "%s" already exists' % key
         return
     branch = Branch(id=id, name=name, key_name=key)
     branch.put()
     return branch
Beispiel #4
0
class BranchTestCase(unittest.TestCase):
    
    def setUp(self):
                
        #the memcache will contain values that will break the tests
        #dont run this on production!
        memcache.flush_all()
        
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Create a consistency policy that will simulate the High Replication consistency model.
        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
        # Initialize the datastore stub with this policy.
        self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
        
        
        millis = int(round(time.time() * 1000))
        
        tree_name = 'test_tree' + str(millis)
        
        username = '******' + str(millis)
        
        self.parent_branch = Branch(id=tree_name)
        
        self.parent_branch.author_name = username
        self.parent_branch.link = ''
        self.parent_branch.content = ''
        self.parent_branch.put()
        
        self.child_branchs = []
        
    def tearDown(self):
        for branch in self.child_branchs:
            branch.key.delete()
        
        self.parent_branch.key.delete()
        
        self.testbed.deactivate()
        
    def testUpdateNoDuplicate(self):
        
        
        branch = Branch()
        branch.link = 'testIdenticalLink.some_link'
        branch.content = 'some_content'
        
        branch.revision = 0
        branch.parent_branch = self.parent_branch.key
        branch.parent_branch_authorname = self.parent_branch.authorname
        branch.put()
        
        self.parent_branch.append_child(branch)
        
        self.assertTrue(len(self.parent_branch.children()) == 1)
        
        self.child_branchs.append(branch)
Beispiel #5
0
class BranchTestCase(unittest.TestCase):
    def setUp(self):

        #the memcache will contain values that will break the tests
        #dont run this on production!
        memcache.flush_all()

        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Create a consistency policy that will simulate the High Replication consistency model.
        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=0)
        # Initialize the datastore stub with this policy.
        self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)

        millis = int(round(time.time() * 1000))

        tree_name = 'test_tree' + str(millis)

        username = '******' + str(millis)

        self.parent_branch = Branch(id=tree_name)

        self.parent_branch.author_name = username
        self.parent_branch.link = ''
        self.parent_branch.content = ''
        self.parent_branch.put()

        self.child_branchs = []

    def tearDown(self):
        for branch in self.child_branchs:
            branch.key.delete()

        self.parent_branch.key.delete()

        self.testbed.deactivate()

    def testUpdateNoDuplicate(self):

        branch = Branch()
        branch.link = 'testIdenticalLink.some_link'
        branch.content = 'some_content'

        branch.revision = 0
        branch.parent_branch = self.parent_branch.key
        branch.parent_branch_authorname = self.parent_branch.authorname
        branch.put()

        self.parent_branch.append_child(branch)

        self.assertTrue(len(self.parent_branch.children()) == 1)

        self.child_branchs.append(branch)
Beispiel #6
0
    def __init__(self):
        # FIXME: This function is massive. Break it up
        self._test_map = {}
        platform_id_map = {}
        branch_id_map = {}
        for test in Test.all():
            if test.hidden:
                continue

            branch_ids = [Branch.get(branch_key).id for branch_key in test.branches]
            platform_ids = [Platform.get(platform_key).id for platform_key in test.platforms]
            self._test_map[test.id] = {
                'name': test.name,
                'branchIds': branch_ids,
                'platformIds': platform_ids,
            }

            for platform_id in platform_ids:
                platform_id_map.setdefault(platform_id, {'tests': [], 'branches': []})
                platform_id_map[platform_id]['tests'].append(test.id)
                platform_id_map[platform_id]['branches'] += branch_ids

            for branch_id in branch_ids:
                branch_id_map.setdefault(branch_id, {'tests': [], 'platforms': []})
                branch_id_map[branch_id]['tests'].append(test.id)
                branch_id_map[branch_id]['platforms'] += platform_ids

        self._platform_map = {}
        for platform in Platform.all():
            if platform.id not in platform_id_map:
                continue

            if platform.hidden:
                for test_id in platform_id_map[platform.id]['tests']:
                    self._test_map[test_id]['platformIds'].remove(platform.id)
                for branch_id in platform_id_map[platform.id]['branches']:
                    branch_id_map[branch_id]['platforms'].remove(platform.id)
                continue

            self._platform_map[platform.id] = {
                'name': platform.name,
                'testIds': list(set(platform_id_map[platform.id]['tests'])),
                'branchIds': list(set(platform_id_map[platform.id]['branches'])),
            }

        self._branch_map = {}
        for branch in Branch.all():
            if branch.id not in branch_id_map:
                continue
            self._branch_map[branch.id] = {
                'name': branch.name,
                'testIds': list(set(branch_id_map[branch.id]['tests'])),
                'platformIds': list(set(branch_id_map[branch.id]['platforms'])),
            }
Beispiel #7
0
    def test_create_if_possible(self):
        self.assertThereIsNoInstanceOf(Branch)

        branch = Branch.create_if_possible('some-branch', 'some branch')
        self.assertTrue(branch)
        self.assertTrue(branch.key().name(), 'some-branch')
        self.assertTrue(branch.name, 'some branch')
        self.assertOnlyInstance(branch)

        self.assertFalse(Branch.create_if_possible('some-branch', 'some other branch'))
        self.assertTrue(branch.name, 'some branch')
        self.assertOnlyInstance(branch)
Beispiel #8
0
    def test_create_if_possible(self):
        self.assertThereIsNoInstanceOf(Branch)

        branch = Branch.create_if_possible('some-branch', 'some branch')
        self.assertTrue(branch)
        self.assertTrue(branch.key().name(), 'some-branch')
        self.assertTrue(branch.name, 'some branch')
        self.assertOnlyInstance(branch)

        self.assertFalse(Branch.create_if_possible('some-branch', 'some other branch'))
        self.assertTrue(branch.name, 'some branch')
        self.assertOnlyInstance(branch)
Beispiel #9
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain; charset=utf-8';
        cache = memcache.get('manifest')
        if cache:
            self.response.out.write(cache)
            return

        testMap = {}
        platformIdMap = {}
        branchIdMap = {}
        for test in Test.all():
            branchIds = [Branch.get(branchKey).id for branchKey in test.branches]
            platformIds = [Platform.get(platformKey).id for platformKey in test.platforms]
            testMap[test.id] = {
                'name': test.name,
                'branchIds': branchIds,
                'platformIds': platformIds,
            }

            for platformId in platformIds:
                platformIdMap.setdefault(platformId, {'tests': [], 'branches': []})
                platformIdMap[platformId]['tests'].append(test.id)
                platformIdMap[platformId]['branches'] += branchIds

            for branchId in branchIds:
                branchIdMap.setdefault(branchId, {'tests': [], 'platforms': []})
                branchIdMap[branchId]['tests'].append(test.id)
                branchIdMap[branchId]['platforms'] += platformIds

        platformMap = {}
        for platform in Platform.all():
            if platform.id not in platformIdMap:
                continue
            platformMap[platform.id] = {
                'name': platform.name,
                'testIds': list(set(platformIdMap[platform.id]['tests'])),
                'branchIds': list(set(platformIdMap[platform.id]['branches'])),
            }

        branchMap = {}
        for branch in Branch.all():
            if branch.id not in branchIdMap:
                continue
            branchMap[branch.id] = {
                'name': branch.name,
                'testIds': list(set(branchIdMap[branch.id]['tests'])),
                'platformIds': list(set(branchIdMap[branch.id]['platforms'])),
            }

        result = json.dumps({'testMap': testMap, 'platformMap': platformMap, 'branchMap': branchMap})
        self.response.out.write(result)
        memcache.add('manifest', result)
Beispiel #10
0
    def test_update_or_insert_to_update(self):
        branch = Branch.create_if_possible('some-branch', 'Some Branch')
        platform = Platform.create_if_possible('some-platform', 'Some Platform')
        test = Test.update_or_insert('some-test', branch, platform)
        self.assertOnlyInstance(test)

        other_branch = Branch.create_if_possible('other-branch', 'Other Branch')
        other_platform = Platform.create_if_possible('other-platform', 'Other Platform')
        test = Test.update_or_insert('some-test', other_branch, other_platform, 'ms')
        self.assertOnlyInstance(test)
        self.assertEqualUnorderedList(test.branches, [branch.key(), other_branch.key()])
        self.assertEqualUnorderedList(test.platforms, [platform.key(), other_platform.key()])
        self.assertEqualUnorderedList(test.unit, 'ms')
Beispiel #11
0
    def test_update_or_insert_to_update(self):
        branch = Branch.create_if_possible('some-branch', 'Some Branch')
        platform = Platform.create_if_possible('some-platform', 'Some Platform')
        test = Test.update_or_insert('some-test', branch, platform)
        self.assertOnlyInstance(test)

        other_branch = Branch.create_if_possible('other-branch', 'Other Branch')
        other_platform = Platform.create_if_possible('other-platform', 'Other Platform')
        test = Test.update_or_insert('some-test', other_branch, other_platform, 'ms')
        self.assertOnlyInstance(test)
        self.assertEqualUnorderedList(test.branches, [branch.key(), other_branch.key()])
        self.assertEqualUnorderedList(test.platforms, [platform.key(), other_platform.key()])
        self.assertEqualUnorderedList(test.unit, 'ms')
Beispiel #12
0
    def get(self):
        self.response.headers["Content-Type"] = "text/plain; charset=utf-8"
        self.response.out.write('{"testMap":')

        testMap = {}
        platformIdMap = {}
        branchIdMap = {}
        for test in Test.all():
            branchIds = [Branch.get(branchKey).id for branchKey in test.branches]
            platformIds = [Platform.get(platformKey).id for platformKey in test.platforms]
            testMap[test.id] = {"name": test.name, "branchIds": branchIds, "platformIds": platformIds}

            for platformId in platformIds:
                platformIdMap.setdefault(platformId, {"tests": [], "branches": []})
                platformIdMap[platformId]["tests"].append(test.id)
                platformIdMap[platformId]["branches"] += branchIds

            for branchId in branchIds:
                branchIdMap.setdefault(branchId, {"tests": [], "platforms": []})
                branchIdMap[branchId]["tests"].append(test.id)
                branchIdMap[branchId]["platforms"] += platformIds

        self.response.out.write(json.dumps(testMap))
        self.response.out.write(',"platformMap":')

        platformMap = {}
        for platform in Platform.all():
            if platform.id not in platformIdMap:
                continue
            platformMap[platform.id] = {
                "name": platform.name,
                "testIds": list(set(platformIdMap[platform.id]["tests"])),
                "branchIds": list(set(platformIdMap[platform.id]["branches"])),
            }

        self.response.out.write(json.dumps(platformMap))
        self.response.out.write(',"branchMap":')

        branchMap = {}
        for branch in Branch.all():
            if branch.id not in branchIdMap:
                continue
            branchMap[branch.id] = {
                "name": branch.name,
                "testIds": list(set(branchIdMap[branch.id]["tests"])),
                "platformIds": list(set(branchIdMap[branch.id]["platforms"])),
            }

        self.response.out.write(json.dumps(branchMap))
        self.response.out.write("}")
Beispiel #13
0
def login():
    form = LogIn()
    Branch.branch_types()
    Types.stall_types()
    print current_user
    if current_user.is_active():
        if current_user.roleID == 1:
            return redirect(url_for('index2'))
        else:
            return redirect(url_for('index'))
    else:
        if request.method == "POST" and form.validate_on_submit():
            user = Users.query.filter_by(username=form.username.data).first()
            if user:
                if user.roleID == 2:
                    if user is not None and check_password_hash(
                            user.passwrd, form.passwrd.data):
                        msg = user.username + " logs in"
                        lgdate = str(now)
                        print lgdate
                        logmessage = Logs(details=msg, log_date=lgdate)
                        dbase.session.add(logmessage)
                        login_user(user)
                        return redirect(url_for('index'))
                    #return '<h1>Invalid username or password!</h1>'
                    flash('Invalid username or password')
                elif user.roleID == 1:
                    if user is not None and check_password_hash(
                            user.passwrd, form.passwrd.data):
                        msg = user.username + " logs in"
                        lgdate = str(now)
                        print lgdate
                        logmessage = Logs(details=msg, log_date=lgdate)
                        dbase.session.add(logmessage)
                        login_user(user)
                        login_user(user)
                        flash('You were logged in')
                        return redirect(url_for('index2'))
                    #return '<h1>Invalid username or password!</h1>'
                    flash('Invalid username or password')

                else:
                    #return '<h1>Invalid username or password!</h1>'
                    flash('Invalid username or password')
            else:
                #return '<h1>Invalid username or password!</h1>'
                flash('Invalid username or password')
    return render_template('login.html', form=form)
Beispiel #14
0
 def test_value_no_plaforms(self):
     some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
     self.assertEqual(ManifestJSONGenerator().value(), {
         'branchMap': {},
         'platformMap': {},
         'testMap': {}
     })
Beispiel #15
0
 def get(self):
     upload_url = blobstore.create_upload_url('/upload')
     contention_ID = self.request.get('con_id')
     con = Contention.get_by_id(int(contention_ID))
     con_date = con.date.strftime("%a, %d. %b %y, %I:%M%p")
     # for x in xrange(1, 11):
     # image_num = "image" + str(x)
     # if con(image_num):
     # con_image_urls[x]= get_serving_url(con(image_num))
     #return images.get_serving_url(self.image1)
     count = 0
     ari_query = Ari_types.all().order('ari')
     aris = ari_query.fetch(50)
     if con:
         elems = con.elements.fetch(50)
         count = int(elems.count(20)) + 1
     tlvl = []
     slvl = []
     for f in elems:
         if f.top_level == 1:
             tlvl.append(f)
         else:
             slvl.append(f)
     gols = rec_con(tlvl, slvl)
     objections = []
     reasons = []
     rcount = 0
     ocount = 0
     ccount = 0
     #contention_query =  Contention.all().order('date')
     if con:
         if elems:
             for r in elems:
                 if r.element_type == 'reason':
                     reasons.append(r)
                     rcount = rcount + 1
             for o in elems:
                 if o.element_type == 'objection':
                     objections.append(o)
                     ocount = ocount + 1
         ccount = int(len(elems))
     branch_query = Branch.all().order('branch')
     branches = branch_query.fetch(10)
     params = {
         'upload_url': upload_url,
         'c_id': contention_ID,
         'con': con,
         'con_date': con_date,
         'reasons': reasons,
         'objections': objections,
         'ccount': ccount,
         'rcount': rcount,
         'ocount': ocount,
         'elems': elems,
         'gols': gols,
         'count': count,
         "branches": branches,
         'aris': aris
     }
     return self.render('contention_panel_view.html', params)
Beispiel #16
0
    def test_chart_params_with_value(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform)

        start_time = datetime(2011, 2, 21, 12, 0, 0)
        end_time = datetime(2011, 2, 28, 12, 0, 0)
        results = self._create_results(some_branch, some_platform, some_builder, 'some-test',
            [50.0, 51.0, 52.0, 49.0, 48.0, 51.9, 50.7, 51.1],
            [start_time + timedelta(day) for day in range(0, 8)])

        # Use int despite of its impreciseness since tests may fail due to rounding errors otherwise.
        def split_as_int(string):
            return [int(float(value)) for value in string.split(',')]

        params = Runs.update_or_insert(some_branch, some_platform, some_test).chart_params(7)
        self.assertEqual(params['chxl'], '0:|Feb 21|Feb 22|Feb 23|Feb 24|Feb 25|Feb 26|Feb 27|Feb 28')
        self.assertEqual(split_as_int(params['chxr']), [1, 0, 57, int(52 * 1.1 / 5 + 0.5)])
        x_min, x_max, y_min, y_max = split_as_int(params['chds'])
        self.assertEqual(datetime.fromtimestamp(x_min), start_time)
        self.assertEqual(datetime.fromtimestamp(x_max), end_time)
        self.assertEqual(y_min, 0)
        self.assertEqual(y_max, int(52 * 1.1))
        self.assertEqual(split_as_int(params['chg']), [int(100 / 7), 20, 0, 0])

        params = Runs.update_or_insert(some_branch, some_platform, some_test).chart_params(14)
        self.assertEqual(params['chxl'], '0:|Feb 14|Feb 16|Feb 18|Feb 20|Feb 22|Feb 24|Feb 26|Feb 28')
        self.assertEqual(split_as_int(params['chxr']), [1, 0, 57, int(52 * 1.1 / 5 + 0.5)])
        x_min, x_max, y_min, y_max = split_as_int(params['chds'])
        self.assertEqual(datetime.fromtimestamp(x_min), datetime(2011, 2, 14, 12, 0, 0))
        self.assertEqual(datetime.fromtimestamp(x_max), end_time)
        self.assertEqual(y_min, 0)
        self.assertEqual(y_max, int(52 * 1.1))
        self.assertEqual(split_as_int(params['chg']), [int(100 / 7), 20, 0, 0])
Beispiel #17
0
    def test_to_json_with_results(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform)
        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 51.0, 52.0, 49.0, 48.0])

        value = json.loads(Runs.update_or_insert(some_branch, some_platform, some_test).to_json())
        self.assertEqualUnorderedList(value.keys(), ['test_runs', 'averages', 'min', 'max', 'unit', 'date_range', 'stat'])
        self.assertEqual(value['stat'], 'ok')
        self.assertEqual(value['min'], 48.0)
        self.assertEqual(value['max'], 52.0)
        self.assertEqual(value['unit'], None)
        self.assertEqual(value['date_range'], None)  # date_range is never given

        self.assertEqual(len(value['test_runs']), len(results))
        for i, run in enumerate(value['test_runs']):
            result = results[i]
            self.assertEqual(run[0], result.key().id())
            self.assertEqual(run[1][1], i)  # Build number
            self.assertEqual(run[1][2], 100 + i)  # Revision
            self.assertEqual(run[1][3], None)  # Supplementary revision
            self.assertEqual(run[3], result.value)
            self.assertEqual(run[6], some_builder.key().id())
            self.assertEqual(run[7], None)  # Statistics
Beispiel #18
0
 def test_update_or_insert_with_unit(self):
     branch = Branch.create_if_possible('some-branch', 'Some Branch')
     platform = Platform.create_if_possible('some-platform',
                                            'Some Platform')
     test = Test.update_or_insert('some-test', branch, platform, 'runs/s')
     self.assertOnlyInstance(test)
     self.assertEqualUnorderedList(test.unit, 'runs/s')
Beispiel #19
0
    def get(self):
        self.response.headers['Content-Type'] = 'application/json; charset=utf-8';
        cache = memcache.get('dashboard')
        if cache:
            self.response.out.write(cache)
            return

        webkit_trunk = Branch.get_by_key_name('webkit-trunk')

        # FIXME: Determine popular branches, platforms, and tests
        dashboard = {
            'defaultBranch': 'WebKit trunk',
            'branchToId': {webkit_trunk.name: webkit_trunk.id},
            'platformToId': {},
            'testToId': {},
        }

        for platform in Platform.all():
            dashboard['platformToId'][platform.name] = platform.id

        for test in Test.all():
            dashboard['testToId'][test.name] = test.id

        result = json.dumps(dashboard)
        self.response.out.write(result)
        memcache.add('dashboard', result)
Beispiel #20
0
 def test_value_with_hidden_platform_and_tesst(self):
     webkit_trunk = Branch.create_if_possible('webkit-trunk',
                                              'WebKit trunk')
     some_platform = Platform.create_if_possible('some-platform',
                                                 'Some Platform')
     hidden_platform = Platform.create_if_possible('hidden-platform',
                                                   'Hidden Platform')
     hidden_platform.hidden = True
     hidden_platform.put()
     Test.update_or_insert('some-test', webkit_trunk, some_platform)
     Test.update_or_insert('some-test', webkit_trunk, hidden_platform)
     Test.update_or_insert('other-test', webkit_trunk, some_platform)
     Test.update_or_insert('other-test', webkit_trunk, hidden_platform)
     Test.update_or_insert('hidden-test', webkit_trunk, some_platform)
     Test.update_or_insert('hidden-test', webkit_trunk, hidden_platform)
     hidden_test = Test.get_by_key_name('hidden-test')
     hidden_test.hidden = True
     hidden_test.put()
     self.assertEqual(DashboardJSONGenerator().value()['platformToId'],
                      {'Some Platform': some_platform.id})
     self.assertEqual(
         DashboardJSONGenerator().value()['testToId'], {
             'some-test': Test.get_by_key_name('some-test').id,
             'other-test': Test.get_by_key_name('other-test').id
         })
Beispiel #21
0
    def test_json_by_ids(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform',
                                                    'Some Platform')
        some_builder = Builder.get(
            Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch,
                                          some_platform)

        self._create_results(some_branch, some_platform, some_builder,
                             'some-test', [50.0])
        runs = Runs.update_or_insert(some_branch, some_platform, some_test)
        runs_json = runs.to_json()

        key_name = Runs._key_name(some_branch.id, some_platform.id,
                                  some_test.id)
        self.assertEqual(
            Runs.json_by_ids(some_branch.id, some_platform.id, some_test.id),
            runs_json)
        self.assertEqual(memcache.get(key_name), runs_json)

        memcache.set(key_name, 'blah')
        self.assertEqual(
            Runs.json_by_ids(some_branch.id, some_platform.id, some_test.id),
            'blah')

        memcache.delete(key_name)
        self.assertEqual(
            Runs.json_by_ids(some_branch.id, some_platform.id, some_test.id),
            runs_json)
        self.assertEqual(memcache.get(key_name), runs_json)
Beispiel #22
0
    def test_to_json_with_results(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform)
        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 51.0, 52.0, 49.0, 48.0])

        value = json.loads(Runs.update_or_insert(some_branch, some_platform, some_test).to_json())
        self.assertEqualUnorderedList(value.keys(), ['test_runs', 'averages', 'min', 'max', 'unit', 'date_range', 'stat'])
        self.assertEqual(value['stat'], 'ok')
        self.assertEqual(value['min'], 48.0)
        self.assertEqual(value['max'], 52.0)
        self.assertEqual(value['unit'], None)
        self.assertEqual(value['date_range'], None)  # date_range is never given

        self.assertEqual(len(value['test_runs']), len(results))
        for i, run in enumerate(value['test_runs']):
            result = results[i]
            self.assertEqual(run[0], result.key().id())
            self.assertEqual(run[1][1], i)  # Build number
            self.assertEqual(run[1][2], 100 + i)  # Revision
            self.assertEqual(run[1][3], None)  # Supplementary revision
            self.assertEqual(run[3], result.value)
            self.assertEqual(run[6], some_builder.key().id())
            self.assertEqual(run[7], None)  # Statistics
Beispiel #23
0
    def test_value_single_platform(self):
        webkit_trunk = Branch.create_if_possible('webkit-trunk',
                                                 'WebKit trunk')
        some_platform = Platform.create_if_possible('some-platform',
                                                    'Some Platform')
        self.assertEqual(
            DashboardJSONGenerator().value(), {
                'defaultBranch': 'WebKit trunk',
                'branchToId': {
                    'WebKit trunk': webkit_trunk.id
                },
                'platformToId': {
                    'Some Platform': some_platform.id
                },
                'testToId': {},
            })

        Test.update_or_insert('some-test', webkit_trunk, some_platform)
        self.assertEqual(
            DashboardJSONGenerator().value(), {
                'defaultBranch': 'WebKit trunk',
                'branchToId': {
                    'WebKit trunk': webkit_trunk.id
                },
                'platformToId': {
                    'Some Platform': some_platform.id
                },
                'testToId': {
                    'some-test': Test.get_by_key_name('some-test').id
                },
            })
Beispiel #24
0
 def setUp(self):
             
     #the memcache will contain values that will break the tests
     #dont run this on production!
     memcache.flush_all()
     
     # First, create an instance of the Testbed class.
     self.testbed = testbed.Testbed()
     # Then activate the testbed, which prepares the service stubs for use.
     self.testbed.activate()
     # Create a consistency policy that will simulate the High Replication consistency model.
     self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
     # Initialize the datastore stub with this policy.
     self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
     
     
     millis = int(round(time.time() * 1000))
     
     tree_name = 'test_tree' + str(millis)
     
     username = '******' + str(millis)
     
     self.parent_branch = Branch(id=tree_name)
     
     self.parent_branch.author_name = username
     self.parent_branch.link = ''
     self.parent_branch.content = ''
     self.parent_branch.put()
     
     self.child_branchs = []
Beispiel #25
0
    def test_update_or_insert(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform)
        self.assertThereIsNoInstanceOf(Runs)

        runs = Runs.update_or_insert(some_branch, some_platform, some_test)
        self.assertOnlyInstance(runs)
        self.assertEqual(runs.json_runs, '')
        self.assertEqual(runs.json_averages, '')
        self.assertEqual(runs.json_min, None)
        self.assertEqual(runs.json_max, None)
        old_memcache_value = memcache.get(Runs._key_name(some_branch.id, some_platform.id, some_test.id))
        self.assertTrue(old_memcache_value)

        runs.delete()
        self.assertThereIsNoInstanceOf(Runs)

        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0])
        runs = Runs.update_or_insert(some_branch, some_platform, some_test)
        self.assertOnlyInstance(runs)
        self.assertTrue(runs.json_runs.startswith('[5,[4,0,100,null],'))
        self.assertEqual(json.loads('{' + runs.json_averages + '}'), {"100": 50.0})
        self.assertEqual(runs.json_min, 50.0)
        self.assertEqual(runs.json_max, 50.0)
        self.assertNotEqual(memcache.get(Runs._key_name(some_branch.id, some_platform.id, some_test.id)), old_memcache_value)
Beispiel #26
0
    def test_update_incrementally(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform)
        self.assertThereIsNoInstanceOf(Runs)

        timestamps = [datetime.now(), datetime.now()]
        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 52.0], timestamps)
        runs = Runs.update_or_insert(some_branch, some_platform, some_test)
        self.assertOnlyInstance(runs)
        self.assertEqual(json.loads('[' + runs.json_runs + ']'),
            [[5, [4, 0, 100, None], mktime(timestamps[0].timetuple()), 50.0, 0, [], None, None],
            [7, [6, 1, 101, None], mktime(timestamps[1].timetuple()), 52.0, 0, [], None, None]])
        self.assertEqual(json.loads('{' + runs.json_averages + '}'), {"100": 50.0, "101": 52.0})
        self.assertEqual(runs.json_min, 50.0)
        self.assertEqual(runs.json_max, 52.0)

        timestamps.append(datetime.now())
        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [48.0],
            timestamps[2:], starting_revision=102)
        runs.update_incrementally(builds[0], results[0])

        self.assertOnlyInstance(runs)
        self.assertEqual(json.loads('[' + runs.json_runs + ']'),
            [[5, [4, 0, 100, None], mktime(timestamps[0].timetuple()), 50.0, 0, [], None, None],
            [7, [6, 1, 101, None], mktime(timestamps[1].timetuple()), 52.0, 0, [], None, None],
            [9, [8, 0, 102, None], mktime(timestamps[2].timetuple()), 48.0, 0, [], None, None]])
        self.assertEqual(json.loads('{' + runs.json_averages + '}'), {"100": 50.0, "101": 52.0, "102": 48.0})
        self.assertEqual(runs.json_min, 48.0)
        self.assertEqual(runs.json_max, 52.0)
Beispiel #27
0
    def test_value_single_platform(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        self.assertEqual(ManifestJSONGenerator().value(), {'branchMap': {}, 'platformMap': {}, 'testMap': {}})

        some_test = Test.update_or_insert('some-test', some_branch, some_platform)
        self._assert_single_test(ManifestJSONGenerator().value(), some_branch, some_platform, some_test)
Beispiel #28
0
    def get(self):
        self.response.headers["Content-Type"] = "application/json; charset=utf-8"

        cache = memcache.get("dashboard")
        if cache:
            self.response.out.write(cache)
            return

        webkitTrunk = Branch.get_by_key_name("webkit-trunk")

        # FIXME: Determine popular branches, platforms, and tests
        dashboard = {
            "defaultBranch": "WebKit trunk",
            "branchToId": {webkitTrunk.name: webkitTrunk.id},
            "platformToId": {},
            "testToId": {},
        }

        for platform in Platform.all():
            dashboard["platformToId"][platform.name] = platform.id

        for test in Test.all():
            dashboard["testToId"][test.name] = test.id

        result = json.dumps(dashboard)
        self.response.out.write(result)
        memcache.add("dashboard", result)
Beispiel #29
0
    def test_update_incrementally(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform)
        self.assertThereIsNoInstanceOf(Runs)

        timestamps = [datetime.now(), datetime.now()]
        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 52.0], timestamps)
        runs = Runs.update_or_insert(some_branch, some_platform, some_test)
        self.assertOnlyInstance(runs)
        self.assertEqual(json.loads('[' + runs.json_runs + ']'),
            [[5, [4, 0, 100, None], mktime(timestamps[0].timetuple()), 50.0, 0, [], None, None],
            [7, [6, 1, 101, None], mktime(timestamps[1].timetuple()), 52.0, 0, [], None, None]])
        self.assertEqual(json.loads('{' + runs.json_averages + '}'), {"100": 50.0, "101": 52.0})
        self.assertEqual(runs.json_min, 50.0)
        self.assertEqual(runs.json_max, 52.0)

        timestamps.append(datetime.now())
        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [48.0],
            timestamps[2:], starting_revision=102)
        runs.update_incrementally(builds[0], results[0])

        self.assertOnlyInstance(runs)
        self.assertEqual(json.loads('[' + runs.json_runs + ']'),
            [[5, [4, 0, 100, None], mktime(timestamps[0].timetuple()), 50.0, 0, [], None, None],
            [7, [6, 1, 101, None], mktime(timestamps[1].timetuple()), 52.0, 0, [], None, None],
            [9, [8, 0, 102, None], mktime(timestamps[2].timetuple()), 48.0, 0, [], None, None]])
        self.assertEqual(json.loads('{' + runs.json_averages + '}'), {"100": 50.0, "101": 52.0, "102": 48.0})
        self.assertEqual(runs.json_min, 48.0)
        self.assertEqual(runs.json_max, 52.0)
Beispiel #30
0
    def test_update_or_insert(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform)
        self.assertThereIsNoInstanceOf(Runs)

        runs = Runs.update_or_insert(some_branch, some_platform, some_test)
        self.assertOnlyInstance(runs)
        self.assertEqual(runs.json_runs, '')
        self.assertEqual(runs.json_averages, '')
        self.assertEqual(runs.json_min, None)
        self.assertEqual(runs.json_max, None)
        old_memcache_value = memcache.get(Runs._key_name(some_branch.id, some_platform.id, some_test.id))
        self.assertTrue(old_memcache_value)

        runs.delete()
        self.assertThereIsNoInstanceOf(Runs)

        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0])
        runs = Runs.update_or_insert(some_branch, some_platform, some_test)
        self.assertOnlyInstance(runs)
        self.assertTrue(runs.json_runs.startswith('[5, [4, 0, 100, null],'))
        self.assertEqual(json.loads('{' + runs.json_averages + '}'), {"100": 50.0})
        self.assertEqual(runs.json_min, 50.0)
        self.assertEqual(runs.json_max, 50.0)
        self.assertNotEqual(memcache.get(Runs._key_name(some_branch.id, some_platform.id, some_test.id)), old_memcache_value)
Beispiel #31
0
    def test_chart_params_with_value(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform)

        start_time = datetime(2011, 2, 21, 12, 0, 0)
        end_time = datetime(2011, 2, 28, 12, 0, 0)
        results = self._create_results(some_branch, some_platform, some_builder, 'some-test',
            [50.0, 51.0, 52.0, 49.0, 48.0, 51.9, 50.7, 51.1],
            [start_time + timedelta(day) for day in range(0, 8)])

        # Use int despite of its impreciseness since tests may fail due to rounding errors otherwise.
        def split_as_int(string):
            return [int(float(value)) for value in string.split(',')]

        params = Runs.update_or_insert(some_branch, some_platform, some_test).chart_params(7)
        self.assertEqual(params['chxl'], '0:|Feb 21|Feb 22|Feb 23|Feb 24|Feb 25|Feb 26|Feb 27|Feb 28')
        self.assertEqual(split_as_int(params['chxr']), [1, 0, 57, int(52 * 1.1 / 5 + 0.5)])
        x_min, x_max, y_min, y_max = split_as_int(params['chds'])
        self.assertEqual(datetime.fromtimestamp(x_min), start_time)
        self.assertEqual(datetime.fromtimestamp(x_max), end_time)
        self.assertEqual(y_min, 0)
        self.assertEqual(y_max, int(52 * 1.1))
        self.assertEqual(split_as_int(params['chg']), [int(100 / 7), 20, 0, 0])

        params = Runs.update_or_insert(some_branch, some_platform, some_test).chart_params(14)
        self.assertEqual(params['chxl'], '0:|Feb 14|Feb 16|Feb 18|Feb 20|Feb 22|Feb 24|Feb 26|Feb 28')
        self.assertEqual(split_as_int(params['chxr']), [1, 0, 57, int(52 * 1.1 / 5 + 0.5)])
        x_min, x_max, y_min, y_max = split_as_int(params['chds'])
        self.assertEqual(datetime.fromtimestamp(x_min), datetime(2011, 2, 14, 12, 0, 0))
        self.assertEqual(datetime.fromtimestamp(x_max), end_time)
        self.assertEqual(y_min, 0)
        self.assertEqual(y_max, int(52 * 1.1))
        self.assertEqual(split_as_int(params['chg']), [int(100 / 7), 20, 0, 0])
Beispiel #32
0
 def test_value_no_plaforms(self):
     webkit_trunk = Branch.create_if_possible('webkit-trunk', 'WebKit trunk')
     self.assertEqual(DashboardJSONGenerator().value(), {
         'defaultBranch': 'WebKit trunk',
         'branchToId': {'WebKit trunk': webkit_trunk.id},
         'platformToId': {},
         'testToId': {},
     })
Beispiel #33
0
 def create_branches(self):
     """
     Cadastra os Ramos
     """
     #print("CADASTRAR RAMOS:")
     for branch in BRANCHS:
         branch_new = Branch()
         branch_new.id = branch['id']
         branch_new.name = branch['name']
         branch_new.description = branch['description']
         branch_new.active = branch['active']
         if branch.get('group'):
             branch_new.group = Group.objects.get(pk=branch['group']['id'])
         branch_new.save()
Beispiel #34
0
    def test_to_json_with_unit(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform, 'runs/s')
        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 51.0, 52.0, 49.0, 48.0])

        value = json.loads(Runs.update_or_insert(some_branch, some_platform, some_test).to_json())
        self.assertEqual(value['unit'], 'runs/s')
Beispiel #35
0
    def test_to_json_with_unit(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
        some_test = Test.update_or_insert('some-test', some_branch, some_platform, 'runs/s')
        builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 51.0, 52.0, 49.0, 48.0])

        value = json.loads(Runs.update_or_insert(some_branch, some_platform, some_test).to_json())
        self.assertEqual(value['unit'], 'runs/s')
Beispiel #36
0
    def test_branch(self):
        log = self._create_log_with_payload('{"key": "value"}')
        self.assertEqual(log.branch(), None)

        log = self._create_log_with_payload('{"branch": "some-branch"}')
        self.assertEqual(log.branch(), None)

        branch = Branch.create_if_possible("some-branch", "Some Branch")
        log = self._create_log_with_payload('{"branch": "some-branch"}')
        self.assertEqual(log.branch().key(), branch.key())
Beispiel #37
0
def update_create(request, id=0):
    if request.method not in ['GET', 'POST']:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
    instance = None
    if id:
        instance = get_object_or_404(Lab, pk=id)
    if request.method == 'GET':
        form = MedicalLabForm(instance)
    elif request.method == 'POST':
        form = MedicalLabForm(request.POST, instance=instance)
        if form.is_valid():
            with transaction.commit_on_success():
                lab = form.save()
                # Only add lab, main branch in new lab creation
                if not instance:
                    request.user.lab = lab
                    request.user.save()
                    Branch.create_main_branch(lab)
    return render(request, 'add_update.html', {'form': form})
Beispiel #38
0
    def test_branch(self):
        log = self._create_log_with_payload('{"key": "value"}')
        self.assertEqual(log.branch(), None)

        log = self._create_log_with_payload('{"branch": "some-branch"}')
        self.assertEqual(log.branch(), None)

        branch = Branch.create_if_possible("some-branch", "Some Branch")
        log = self._create_log_with_payload('{"branch": "some-branch"}')
        self.assertEqual(log.branch().key(), branch.key())
Beispiel #39
0
def update_create(request, id=0):
    if request.method not in ['GET', 'POST']:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
    instance = None
    if id:
        instance = get_object_or_404(Lab, pk=id)
    if request.method == 'GET':
        form = MedicalLabForm(instance)
    elif request.method == 'POST':
        form = MedicalLabForm(request.POST, instance=instance)
        if form.is_valid():
            with transaction.commit_on_success():
                lab = form.save()
                # Only add lab, main branch in new lab creation
                if not instance:
                    request.user.lab = lab
                    request.user.save()
                    Branch.create_main_branch(lab)
    return render(request, 'add_update.html', {'form':form})
Beispiel #40
0
    def testUpdateNoDuplicate(self):

        branch = Branch()
        branch.link = 'testIdenticalLink.some_link'
        branch.content = 'some_content'

        branch.revision = 0
        branch.parent_branch = self.parent_branch.key
        branch.parent_branch_authorname = self.parent_branch.authorname
        branch.put()

        self.parent_branch.append_child(branch)

        self.assertTrue(len(self.parent_branch.children()) == 1)

        self.child_branchs.append(branch)
Beispiel #41
0
    def test_model_from_numeric_id(self):

        def execute(id):
            return Branch(id=id, name='some branch', key_name='some-branch').put()

        branch = Branch.get(create_in_transaction_with_numeric_id_holder(execute))

        self.assertEqual(model_from_numeric_id(branch.id, Branch).key(), branch.key())
        self.assertEqual(model_from_numeric_id(branch.id + 1, Branch), None)
        delete_model_with_numeric_id_holder(branch)
        self.assertEqual(model_from_numeric_id(branch.id, Branch), None)
Beispiel #42
0
    def test_model_from_numeric_id(self):

        def execute(id):
            return Branch(id=id, name='some branch', key_name='some-branch').put()

        branch = Branch.get(create_in_transaction_with_numeric_id_holder(execute))

        self.assertEqual(model_from_numeric_id(branch.id, Branch).key(), branch.key())
        self.assertEqual(model_from_numeric_id(branch.id + 1, Branch), None)
        delete_model_with_numeric_id_holder(branch)
        self.assertEqual(model_from_numeric_id(branch.id, Branch), None)
Beispiel #43
0
    def test_update_or_insert(self):
        branch = Branch.create_if_possible('some-branch', 'Some Branch')
        platform = Platform.create_if_possible('some-platform', 'Some Platform')

        self.assertThereIsNoInstanceOf(Test)

        test = Test.update_or_insert('some-test', branch, platform)
        self.assertTrue(test)
        self.assertEqual(test.branches, [branch.key()])
        self.assertEqual(test.platforms, [platform.key()])
        self.assertOnlyInstance(test)
Beispiel #44
0
 def testValidator(self):
 
     test_link_text = "a"*24
     test_content_text = "b"*24
     
     branch = Branch()
     branch.link = test_link_text
     branch.content = test_content_text
     branch.put()
     
     self.assertEqual(branch.link, test_link_text)
     self.assertEqual(branch.content, test_content_text)
     
     branch = Branch()
     branch.link = "<a>"+test_link_text+"</a>"
     branch.content = "<a>"+test_content_text+"</a>"
     branch.put()
     
     self.assertEqual(branch.link, test_link_text)
     self.assertEqual(branch.content, test_content_text)
Beispiel #45
0
 def get(self):
     
     trees = Tree.main_trees()
     branchdatas = Branch.get_first_branchs(trees)
     template_values = {
         'trees': trees,
         'branchdatas': branchdatas,
         'username': self.username()
     }
     
     self.render('main.html', template_values)
Beispiel #46
0
    def test_delete_model_with_numeric_id_holder(self):

        def execute(id):
            return Branch(id=id, name='some branch', key_name='some-branch').put()

        branch = Branch.get(create_in_transaction_with_numeric_id_holder(execute))
        self.assertOnlyInstance(branch)

        delete_model_with_numeric_id_holder(branch)

        self.assertThereIsNoInstanceOf(Branch)
        self.assertThereIsNoInstanceOf(NumericIdHolder)
Beispiel #47
0
    def test_delete_model_with_numeric_id_holder(self):

        def execute(id):
            return Branch(id=id, name='some branch', key_name='some-branch').put()

        branch = Branch.get(create_in_transaction_with_numeric_id_holder(execute))
        self.assertOnlyInstance(branch)

        delete_model_with_numeric_id_holder(branch)

        self.assertThereIsNoInstanceOf(Branch)
        self.assertThereIsNoInstanceOf(NumericIdHolder)
Beispiel #48
0
 def test_value_without_results(self):
     some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
     some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
     self.assertThereIsNoInstanceOf(Test)
     self.assertThereIsNoInstanceOf(TestResult)
     self.assertEqual(Runs(some_branch, some_platform, 'some-test').value(), {
         'test_runs': [],
         'averages': {},
         'min': None,
         'max': None,
         'date_range': None,
         'stat': 'ok'})
Beispiel #49
0
    def test_update_or_insert(self):
        branch = Branch.create_if_possible('some-branch', 'Some Branch')
        platform = Platform.create_if_possible('some-platform', 'Some Platform')

        self.assertThereIsNoInstanceOf(Test)

        test = Test.update_or_insert('some-test', branch, platform)
        self.assertTrue(test)
        self.assertEqual(test.branches, [branch.key()])
        self.assertEqual(test.platforms, [platform.key()])
        self.assertEqual(test.unit, None)
        self.assertOnlyInstance(test)
Beispiel #50
0
 def test_value_no_plaforms(self):
     webkit_trunk = Branch.create_if_possible('webkit-trunk',
                                              'WebKit trunk')
     self.assertEqual(
         DashboardJSONGenerator().value(), {
             'defaultBranch': 'WebKit trunk',
             'branchToId': {
                 'WebKit trunk': webkit_trunk.id
             },
             'platformToId': {},
             'testToId': {},
         })
Beispiel #51
0
def create_branch_entry(request):
    if request.method == 'POST':
        try:
            received_json_data = json.loads(request.body)
            id = received_json_data.get('id', '')
            name = received_json_data.get('name', '')
            store_id = received_json_data.get('store_id', '')
            user_id = received_json_data.get('user_id', 'unknown')

            query = session.query(Store).filter(Store.id == store_id)
            _row = query.first()

            if _row is None:
                return JsonResponse(
                    {
                        "success":
                        "false",
                        "error":
                        "Store entry with store_id of " + str(store_id) +
                        " not found"
                    },
                    status=500)

            row = Branch(name=name, id=id, store_id=store_id)
            session.add(row)
            session.commit()
            create_new_log(user_id, "create branch", "branches", "all",
                           str(id))
            return JsonResponse({"Success": "true"}, status=200)
        except SQLAlchemyError as e:
            print(e)
            session.rollback()
            return JsonResponse({
                "success": "false",
                "error": e.message
            },
                                status=500)
        except ValueError as e:
            session.rollback()
            return JsonResponse({
                "success": "false",
                "error": e.message
            },
                                status=500)

    else:
        return JsonResponse({
            "success": "false",
            "error": "Method is POST"
        },
                            status=500)

    return JsonResponse({"Success": "true"}, status=200)
Beispiel #52
0
 def test_value_two_platforms(self):
     webkit_trunk = Branch.create_if_possible('webkit-trunk', 'WebKit trunk')
     some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
     other_platform = Platform.create_if_possible('other-platform', 'Other Platform')
     Test.update_or_insert('some-test', webkit_trunk, some_platform)
     Test.update_or_insert('some-test', webkit_trunk, other_platform)
     self.assertEqual(DashboardJSONGenerator().value(), {
         'defaultBranch': 'WebKit trunk',
         'branchToId': {'WebKit trunk': webkit_trunk.id},
         'platformToId': {'Some Platform': some_platform.id, 'Other Platform': other_platform.id},
         'testToId': {'some-test': Test.get_by_key_name('some-test').id},
     })
Beispiel #53
0
def branches(request, id=0):
    if request.method == 'GET':
        all_branches = Branch.objects.get(user=request.user)
        serializer = BranchSerializer(all_branches)
        return Response(serializer.data)
    elif request.method == 'POST':
        serializer = BranchSerializer(data=request.DATA)
        if serializer.is_valid():
            serializer.data.user = request.user
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
    elif request.method == 'PUT':
        branch = Branch(id=id)
        serializer = BranchSerializer(branch, data=request.DATA)
        if serializer.is_valid():
            serializer.data.user = request.user
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
    elif request.method == 'DELETE':
        branch = Branch(id=id)
        branch.delete()
        return Response("DELETED", status=status.HTTP_200_OK)
Beispiel #54
0
 def test_to_json_without_results(self):
     some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
     some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
     some_test = Test.update_or_insert('some-test', some_branch, some_platform)
     self.assertOnlyInstance(some_test)
     self.assertThereIsNoInstanceOf(TestResult)
     self.assertEqual(json.loads(Runs.update_or_insert(some_branch, some_platform, some_test).to_json()), {
         'test_runs': [],
         'averages': {},
         'min': None,
         'max': None,
         'date_range': None,
         'stat': 'ok'})
Beispiel #55
0
    def test_value_two_platforms(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform',
                                                    'Some Platform')
        other_platform = Platform.create_if_possible('other-platform',
                                                     'Other Platform')
        some_test = Test.update_or_insert('some-test', some_branch,
                                          some_platform)

        self._assert_single_test(ManifestJSONGenerator().value(), some_branch,
                                 some_platform, some_test)

        some_test = Test.update_or_insert('some-test', some_branch,
                                          other_platform)
        self.assertEqualUnorderedList(
            some_test.platforms,
            [some_platform.key(), other_platform.key()])

        value = ManifestJSONGenerator().value()
        expected_platform_ids = [some_platform.id, other_platform.id]
        self.assertEqualUnorderedList(value.keys(),
                                      ['branchMap', 'platformMap', 'testMap'])
        self.assertEqualUnorderedList(
            value['branchMap'], {
                some_branch.id: {
                    'name': some_branch.name,
                    'testIds': [some_test.id],
                    'platformIds': expected_platform_ids
                }
            })
        self.assertEqual(
            value['platformMap'], {
                some_platform.id: {
                    'name': some_platform.name,
                    'branchIds': [some_branch.id],
                    'testIds': [some_test.id]
                },
                other_platform.id: {
                    'name': other_platform.name,
                    'branchIds': [some_branch.id],
                    'testIds': [some_test.id]
                }
            })
        self.assertEqual(
            value['testMap'], {
                some_test.id: {
                    'name': some_test.name,
                    'branchIds': [some_branch.id],
                    'platformIds': expected_platform_ids
                }
            })
Beispiel #56
0
    def test_generate_runs(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
        some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))

        results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 51.0, 52.0, 49.0, 48.0])
        last_i = 0
        for i, (build, result) in enumerate(Runs._generate_runs(some_branch, some_platform, "some-test")):
            self.assertEqual(build.buildNumber, i)
            self.assertEqual(build.revision, 100 + i)
            self.assertEqual(result.name, 'some-test')
            self.assertEqual(result.value, results[i].value)
            last_i = i
        self.assertTrue(last_i + 1, len(results))
Beispiel #57
0
 def test_to_json_without_results(self):
     some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
     some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
     some_test = Test.update_or_insert('some-test', some_branch, some_platform)
     self.assertOnlyInstance(some_test)
     self.assertThereIsNoInstanceOf(TestResult)
     self.assertEqual(json.loads(Runs.update_or_insert(some_branch, some_platform, some_test).to_json()), {
         'test_runs': [],
         'averages': {},
         'min': None,
         'max': None,
         'unit': None,
         'date_range': None,
         'stat': 'ok'})
Beispiel #58
0
    def test_value_single_platform(self):
        some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
        some_platform = Platform.create_if_possible('some-platform',
                                                    'Some Platform')
        self.assertEqual(ManifestJSONGenerator().value(), {
            'branchMap': {},
            'platformMap': {},
            'testMap': {}
        })

        some_test = Test.update_or_insert('some-test', some_branch,
                                          some_platform)
        self._assert_single_test(ManifestJSONGenerator().value(), some_branch,
                                 some_platform, some_test)
Beispiel #59
0
 def testUpdateNoDuplicate(self):
     
     
     branch = Branch()
     branch.link = 'testIdenticalLink.some_link'
     branch.content = 'some_content'
     
     branch.revision = 0
     branch.parent_branch = self.parent_branch.key
     branch.parent_branch_authorname = self.parent_branch.authorname
     branch.put()
     
     self.parent_branch.append_child(branch)
     
     self.assertTrue(len(self.parent_branch.children()) == 1)
     
     self.child_branchs.append(branch)