def test_configurations_POST_no_running_experiments(self): import uuid app = Application(name='Science', id=5, apikey=str(uuid.uuid4())) Application.save(app) expgroup = ExperimentGroup(name='Cake', id=59) ExperimentGroup.save(expgroup) conf = Configuration(key='v9', value=False, experimentgroup_id=expgroup.id) Configuration.save(conf) start = get_datetime(-2, 0, 0, 0, 0, 0) end = get_datetime(-1, 0, 0, 0, 0, 0) experiment = Experiment(name='Non-running Test Experiment', application_id=5, startDatetime=start, endDatetime=end, experimentgroups=[ExperimentGroup.get(59)]) Experiment.save(experiment) httpclients = Clients(self.req) self.req.headers['authorization'] = Application.get(5).apikey self.req.swagger_data = {'clientname': 'Chell'} response = httpclients.configurations_POST() assert response.status_code == 400
def test_configurations_POST_no_name(self): self.req.headers['authorization'] = Application.get(1).apikey self.req.swagger_data = {} httpclients = Clients(self.req) response = httpclients.configurations_POST() assert response.status_code == 400
def test_configurations_POST_client_not_created_if_exists_in_application( self): httpclients = Clients(self.req) self.req.headers['authorization'] = Application.get(1).apikey self.req.swagger_data = {'clientname': 'Chell'} httpclients.configurations_POST() count_clients_before = Client.query().count() self.req.headers['authorization'] = Application.get(1).apikey self.req.swagger_data = {'clientname': 'Chell'} httpclients.configurations_POST() count_clients_after = Client.query().count() assert count_clients_after == count_clients_before
def test_configurations_POST_creates_client_if_nonexistent(self): count_clients_before = Client.query().count() self.req.headers['authorization'] = Application.get(1).apikey self.req.swagger_data = {'clientname': 'another tester'} httpclients = Clients(self.req) response = httpclients.configurations_POST() assert Client.query().count() > count_clients_before
def test_configurations_POST_existing_client(self): httpclients = Clients(self.req) self.req.headers['authorization'] = Application.get(1).apikey self.req.swagger_data = {'clientname': 'First client'} response = httpclients.configurations_POST() expected1 = list(map(lambda _: _.as_dict(), \ Configuration.query()\ .join(ExperimentGroup)\ .filter(ExperimentGroup.id == 1).all())) expected2 = list(map(lambda _: _.as_dict(), \ Configuration.query()\ .join(ExperimentGroup)\ .filter(ExperimentGroup.id == 2).all())) assert response == expected1 or response == expected2
def test_configurations_POST_assigns_user_to_experimentgroup(self): count_experimentgroup_clients_before = Client.query()\ .join(Client.experimentgroups)\ .filter(ExperimentGroup.id == 42)\ .count() self.req.headers['authorization'] = Application.get(2).apikey self.req.swagger_data = {'clientname': 'Chell'} httpclients = Clients(self.req) response = httpclients.configurations_POST() count_experimentgroup_clients_after = Client.query()\ .join(Client.experimentgroups)\ .filter(ExperimentGroup.id == 42)\ .count() assert count_experimentgroup_clients_after > count_experimentgroup_clients_before
def test_configurations_POST_no_experimentgroups(self): import uuid app = Application(name='Science', id=5, apikey=str(uuid.uuid4())) Application.save(app) start = get_datetime(-1, 0, 0, 0, 0, 0) end = get_datetime(1, 0, 0, 0, 0, 0) experiment = Experiment( name='Test Experiment without Experimentgroups', application_id=5, startDatetime=start, endDatetime=end, experimentgroups=[]) Experiment.save(experiment) httpclients = Clients(self.req) self.req.headers['authorization'] = Application.get(5).apikey self.req.swagger_data = {'clientname': 'Chell'} response = httpclients.configurations_POST() assert response.status_code == 400
def test_configurations_POST_no_apikey(self): self.req.swagger_data = {'clientname': 'new Tester'} httpclients = Clients(self.req) response = httpclients.configurations_POST() assert response.status_code == 401