Пример #1
0
 def setUp(self):
     self.category = ExperimentCategory("Dummy experiments")
     self.experiment = Experiment("ud-dummy", self.category,
                                  datetime.datetime.now(),
                                  datetime.datetime.now(), 5L)
     self.use = ExperimentUse(datetime.datetime.now(),
                              datetime.datetime.now(), self.experiment,
                              'student1', '127.0.0.1', 5L)
     self.allowed = ExperimentAllowed(self.experiment, 150, 5, True)
Пример #2
0
 def _parse_experiment_list_holders(self, experiment_list_holders):
     experiments = []
     for experiment in [
             holder['experiment'] for holder in experiment_list_holders
     ]:
         category = ExperimentCategory(experiment['category']['name'])
         exp = Experiment(experiment['name'], category,
                          experiment['start_date'], experiment['end_date'])
         experiments.append(exp)
     return experiments
Пример #3
0
 def _parse_experiment_list_holders(self, experiment_list_holders):
     experiments = []
     for experiment in [
             holder.experiment for holder in experiment_list_holders
     ]:
         category = ExperimentCategory(experiment.category.name)
         exp = Experiment(experiment.name, category,
                          experiment.start_date, experiment.end_date)
         experiments.append(exp)
     return experiments
    def test_get_experiments(self):
        PORT = 11224
        self.configurationManager._set_value(
            AdminFacadeServer.ADMIN_FACADE_JSON_PORT, PORT)
        self.client = SmartGwtClient(PORT)
        self.rfs.start()
        try:
            self.rfm_json.get_experiments({'id': REAL_ID})
            dt = datetime.datetime.now()
            experiments = [
                Experiment("ud-pld",
                           ExperimentCategory("PLD experiments"),
                           dt,
                           dt,
                           id=1),
                Experiment("ud-fpga",
                           ExperimentCategory("FPGA experiments"),
                           dt,
                           dt,
                           id=2)
            ]
            self.mocker.result(experiments)
            self.mocker.replay()

            experiments = self.client.get_experiments(REAL_ID)

            self.assertEquals(2, len(experiments))

            self.assertEquals("ud-pld", experiments[0]['name'])
            self.assertEquals("PLD experiments", experiments[0]['category'])
            self.assertEquals(1, experiments[0]['id'])

            self.assertEquals("ud-fpga", experiments[1]['name'])
            self.assertEquals("FPGA experiments", experiments[1]['category'])
            self.assertEquals(2, experiments[1]['id'])

            self.mocker.verify()
        finally:
            self.rfs.stop()
Пример #5
0
    def list_experiments(self, session_id):
        serialized_session_id = {'id': session_id.id}
        experiment_list = self._core_call('list_experiments',
                                          session_id=serialized_session_id)
        experiments = []
        for external_experiment in experiment_list:
            category = ExperimentCategory(
                external_experiment['experiment']['category']['name'])
            # 2012-04-10T15:22:38
            start_date = datetime.datetime.strptime(
                external_experiment['experiment']['start_date'],
                "%Y-%m-%dT%H:%M:%S")
            end_date = datetime.datetime.strptime(
                external_experiment['experiment']['end_date'],
                "%Y-%m-%dT%H:%M:%S")
            if 'client' in external_experiment['experiment']:
                client = ExperimentClient(
                    external_experiment['experiment']['client'], {})
            else:
                client = None
            if 'permission_id' in external_experiment:
                permission_id = external_experiment['permission_id']
                permission_scope = external_experiment['permission_scope']
            else:
                permission_id = None
                permission_scope = None

            exp = Experiment(name=external_experiment['experiment']['name'],
                             category=category,
                             start_date=start_date,
                             end_date=end_date,
                             client=client)
            exp_allowed = ExperimentAllowed(
                exp,
                time_allowed=external_experiment['time_allowed'],
                priority=external_experiment['priority'],
                initialization_in_accounting=external_experiment[
                    'initialization_in_accounting'],
                permanent_id=external_experiment['permanent_id'],
                permission_id=permission_id,
                permission_scope=permission_scope)
            experiments.append(exp_allowed)
        return experiments
    def test_get_experiment_uses_without_criterias(self):
        PORT = 11227
        self.configurationManager._set_value(
            AdminFacadeServer.ADMIN_FACADE_JSON_PORT, PORT)
        self.client = SmartGwtClient(PORT)
        self.rfs.start()
        try:
            dt1 = datetime.datetime(2010, 10, 4, 11, 00, 00)
            dt2 = datetime.datetime(2010, 10, 5, 12, 00, 00)

            user1 = User("jaime.irurzun", "Jaime Irurzun",
                         "*****@*****.**", Role("student"))
            user2 = User("pablo.orduna", "Pablo Orduna",
                         "*****@*****.**", Role("student"))

            exp = Experiment("ud-pld",
                             ExperimentCategory("PLD experiments"),
                             dt1,
                             dt2,
                             id=1)

            experiment_use1 = ExperimentUse(dt1,
                                            dt2,
                                            exp,
                                            user1,
                                            "unknown",
                                            id=4)
            experiment_use2 = ExperimentUse(dt1,
                                            dt2,
                                            exp,
                                            user2,
                                            "unknown",
                                            id=5)

            self.rfm_json.get_experiment_uses({'id': REAL_ID}, None, None,
                                              None, None, 0, 50, [])

            self.mocker.result(([experiment_use1, experiment_use2], 2))
            self.mocker.replay()

            experiment_uses_response = self.client.get_experiment_uses(
                REAL_ID, [], None, 0, 50, [], 'exact')

            self.assertEquals(0, experiment_uses_response['status'])
            self.assertEquals(0, experiment_uses_response['startRows'])
            self.assertEquals(2, experiment_uses_response['endRow'])
            self.assertEquals(2, experiment_uses_response['totalRows'])

            experiment_uses = experiment_uses_response['data']

            self.assertEquals(2, len(experiment_uses))

            self.assertEquals(4, experiment_uses[0]['id'])
            self.assertEquals('2010-10-04T11:00:00',
                              experiment_uses[0]['start_date'])
            self.assertEquals('2010-10-05T12:00:00',
                              experiment_uses[0]['end_date'])
            self.assertEquals(user1.login, experiment_uses[0]['agent_login'])
            self.assertEquals(user1.full_name,
                              experiment_uses[0]['agent_name'])
            self.assertEquals(user1.email, experiment_uses[0]['agent_email'])
            self.assertEquals('ud-pld', experiment_uses[0]['experiment_name'])
            self.assertEquals('PLD experiments',
                              experiment_uses[0]['experiment_category'])
            self.assertEquals('unknown', experiment_uses[0]['origin'])

            self.assertEquals(5, experiment_uses[1]['id'])
            self.assertEquals('2010-10-04T11:00:00',
                              experiment_uses[1]['start_date'])
            self.assertEquals('2010-10-05T12:00:00',
                              experiment_uses[1]['end_date'])
            self.assertEquals(user2.login, experiment_uses[1]['agent_login'])
            self.assertEquals(user2.full_name,
                              experiment_uses[1]['agent_name'])
            self.assertEquals(user2.email, experiment_uses[1]['agent_email'])
            self.assertEquals('ud-pld', experiment_uses[1]['experiment_name'])
            self.assertEquals('PLD experiments',
                              experiment_uses[1]['experiment_category'])
            self.assertEquals('unknown', experiment_uses[1]['origin'])

            self.mocker.verify()
        finally:
            self.rfs.stop()
    def test_get_experiment_uses(self):
        PORT = 11226
        self.configurationManager._set_value(
            AdminFacadeServer.ADMIN_FACADE_JSON_PORT, PORT)
        self.client = SmartGwtClient(PORT)
        self.rfs.start()
        try:

            criterias = []
            criterias.append({
                'operator': 'greaterOrEqual',
                'fieldName': 'start_date',
                'value': '2010-10-03T22:00:00'
            })
            criterias.append({
                'operator': 'lessOrEqual',
                'fieldName': 'end_date',
                'value': '2010-10-08T21:59:59'
            })
            criterias.append({
                'operator': 'equals',
                'fieldName': 'group',
                'value': 2
            })
            criterias.append({
                'operator': 'equals',
                'fieldName': 'experiment_id',
                'value': 9
            })

            from_date = datetime.datetime(2010, 10, 3, 22, 00, 00)
            to_date = datetime.datetime(2010, 10, 8, 21, 59, 59)

            dt1 = datetime.datetime(2010, 10, 4, 11, 00, 00)
            dt2 = datetime.datetime(2010, 10, 5, 12, 00, 00)

            user1 = User("jaime.irurzun", "Jaime Irurzun",
                         "*****@*****.**", Role("student"))
            user2 = User("pablo.orduna", "Pablo Orduna",
                         "*****@*****.**", Role("student"))

            exp = Experiment("ud-pld",
                             ExperimentCategory("PLD experiments"),
                             dt1,
                             dt2,
                             id=1)

            experiment_use1 = ExperimentUse(dt1,
                                            dt2,
                                            exp,
                                            user1,
                                            "unknown",
                                            id=4)
            experiment_use2 = ExperimentUse(dt1,
                                            dt2,
                                            exp,
                                            user2,
                                            "unknown",
                                            id=5)

            self.rfm_json.get_experiment_uses({'id': REAL_ID}, from_date,
                                              to_date, 2, 9, 0, 50,
                                              ['start_date'])

            self.mocker.result(([experiment_use1, experiment_use2], 2))
            self.mocker.replay()

            experiment_uses_response = self.client.get_experiment_uses(
                REAL_ID, criterias, 'and', 0, 50, ['start_date'], 'exact')

            self.assertEquals(0, experiment_uses_response['status'])
            self.assertEquals(0, experiment_uses_response['startRows'])
            self.assertEquals(2, experiment_uses_response['endRow'])
            self.assertEquals(2, experiment_uses_response['totalRows'])

            experiment_uses = experiment_uses_response['data']

            self.assertEquals(2, len(experiment_uses))

            self.assertEquals(4, experiment_uses[0]['id'])
            self.assertEquals('2010-10-04T11:00:00',
                              experiment_uses[0]['start_date'])
            self.assertEquals('2010-10-05T12:00:00',
                              experiment_uses[0]['end_date'])
            self.assertEquals(user1.login, experiment_uses[0]['agent_login'])
            self.assertEquals(user1.full_name,
                              experiment_uses[0]['agent_name'])
            self.assertEquals(user1.email, experiment_uses[0]['agent_email'])
            self.assertEquals('ud-pld', experiment_uses[0]['experiment_name'])
            self.assertEquals('PLD experiments',
                              experiment_uses[0]['experiment_category'])
            self.assertEquals('unknown', experiment_uses[0]['origin'])

            self.assertEquals(5, experiment_uses[1]['id'])
            self.assertEquals('2010-10-04T11:00:00',
                              experiment_uses[1]['start_date'])
            self.assertEquals('2010-10-05T12:00:00',
                              experiment_uses[1]['end_date'])
            self.assertEquals(user2.login, experiment_uses[1]['agent_login'])
            self.assertEquals(user2.full_name,
                              experiment_uses[1]['agent_name'])
            self.assertEquals(user2.email, experiment_uses[1]['agent_email'])
            self.assertEquals('ud-pld', experiment_uses[1]['experiment_name'])
            self.assertEquals('PLD experiments',
                              experiment_uses[1]['experiment_category'])
            self.assertEquals('unknown', experiment_uses[1]['origin'])

            self.mocker.verify()
        finally:
            self.rfs.stop()