def test_validate_project_name_config(self): config_dict = { 'name': 'test sdf', 'description': '', 'is_public': True } with self.assertRaises(ValidationError): ProjectConfig.from_dict(config_dict)
def test_create_project(self): object = ProjectConfig(faker.word()) httpretty.register_uri(httpretty.POST, ProjectClient._build_url( self.client.base_url, ProjectClient.ENDPOINT), body=json.dumps(object.to_dict()), content_type='application/json', status=200) result = self.client.create_project(object) assert result.to_dict() == object.to_dict()
def test_update_project(self): object = ProjectConfig(faker.word()) project_uuid = uuid.uuid4().hex httpretty.register_uri(httpretty.PATCH, ProjectClient._build_url( self.client.base_url, ProjectClient.ENDPOINT, project_uuid), body=json.dumps(object.to_dict()), content_type='application/json', status=200) result = self.client.update_project(project_uuid, {'name': 'new'}) assert result.to_dict() == object.to_dict()
def create(name, description): """Create a new project. Example: ``` polyaxon project create --name=cats-vs-dogs --description=Image Classification with Deep Learning ``` """ try: project_config = ProjectConfig.from_dict( dict(name=name, description=description)) except ValidationError: Printer.print_error( 'Project name should contain only alpha numerical, "-", and "_".') sys.exit(1) try: project = PolyaxonClients().project.create_project(project_config) except (PolyaxonHTTPError, PolyaxonShouldExitError) as e: Printer.print_error('Could not create project `{}`.'.format(name)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) Printer.print_success( "Project `{}` was created successfully with uuid `{}`.".format( project.name, project.uuid.hex))
def validate(data): """Validates the data and creates the config objects""" if 'project' not in data: raise PolyaxonfileError( "The Polyaxonfile must contain a project section.") if 'model' not in data: raise PolyaxonfileError( "The Polyaxonfile must contain a model section.") validated_data = { 'version': data['version'], 'project': ProjectConfig.from_dict(data['project']), 'model': ModelConfig.from_dict(data['model']) } if data.get('settings'): validated_data['settings'] = SettingsConfig.from_dict(data['settings']) if data.get('train'): validated_data['train'] = TrainConfig.from_dict(data['train']) if data.get('eval'): validated_data['eval'] = EvalConfig.from_dict(data['eval']) return validated_data
def test_project_experiments_and_groups_config(self): uuid_value = uuid.uuid4().hex config_dict = { 'name': 'test', 'description': '', 'is_public': True, 'experiment_groups': [ ExperimentGroupConfig(content='content', uuid=uuid_value, project=uuid_value).to_dict() ], 'experiments': [ ExperimentConfig(config={}, uuid=uuid_value, project=uuid_value).to_dict() ] } config = ProjectConfig.from_dict(config_dict) assert_equal_dict(config_dict, config.to_dict()) config_dict.pop('description') config_dict.pop('experiment_groups') config_dict.pop('experiments') assert_equal_dict(config_dict, config.to_light_dict())
def create_project(self, project_config): try: response = self.post(self._get_http_url('/projects'), json=project_config.to_dict()) return ProjectConfig.from_dict(response.json()) except PolyaxonException as e: self.handle_exception(e=e, log_message='Error while creating project') return None
def get_project(self, project_uuid): request_url = self._build_url(self._get_http_url(), project_uuid) try: response = self.get(request_url) return ProjectConfig.from_dict(response.json()) except NotFoundError: return None
def update_project(self, username, project_name, patch_dict): request_url = self._build_url(self._get_http_url(), username, project_name) try: response = self.patch(request_url, json=patch_dict) return ProjectConfig.from_dict(response.json()) except PolyaxonException as e: self.handle_exception(e=e, log_message='Error while updating project') return None
def get_project(self, username, project_name): request_url = self._build_url(self._get_http_url(), username, project_name) try: response = self.get(request_url) return ProjectConfig.from_dict(response.json()) except PolyaxonException as e: self.handle_exception(e=e, log_message='Error while retrieving project') return None
def get_by_name(self, name): request_url = self._build_url(self.auth_config.username, name) request_url = self._get_url(request_url) try: response = self.get(request_url) return ProjectConfig.from_dict(response.json()) except NotFoundError: return None
def validate_headers(spec, data): """Validates headers data and creates the config objects""" validated_data = { spec.VERSION: data[spec.VERSION], spec.PROJECT: ProjectConfig.from_dict(data[spec.PROJECT]), } if data.get(spec.SETTINGS): validated_data[spec.SETTINGS] = SettingsConfig.from_dict( data[spec.SETTINGS]) return validated_data
def test_get_project(self): object = ProjectConfig(faker.word()).to_dict() httpretty.register_uri(httpretty.GET, ProjectClient._build_url( self.client.base_url, ProjectClient.ENDPOINT, 'uuid'), body=json.dumps(object), content_type='application/json', status=200) result = self.client.get_project('uuid') assert object == result.to_dict()
def test_project_config(self): config_dict = { 'name': 'test', 'description': '', 'is_public': True, 'has_code': True, 'num_experiments': 0, 'num_experiment_groups': 0, } config = ProjectConfig.from_dict(config_dict) assert config.to_dict() == config_dict
def list_projects(self, page=1): try: response = self.get(self._get_http_url(), params=self.get_page(page=page)) projects_dict = response.json() return [ ProjectConfig.from_dict(project) for project in projects_dict.get("results", []) ] except PolyaxonException as e: self.handle_exception( e=e, log_message='Error while retrieving projects') return []
def get_projects(self): try: response = self.get(self._get_url()) projects_dict = response.json() return [ ProjectConfig.from_dict(project) for project in projects_dict.get("projects", []) ] except PolyaxonException as e: logger.info("Error while retrieving projects: {}".format( e.message)) if isinstance(e, AuthenticationError): # exit now since there is nothing we can do without login sys.exit(1) return []
def test_list_projects(self): projects = [ProjectConfig(faker.word).to_dict() for _ in range(10)] httpretty.register_uri(httpretty.GET, ProjectClient._build_url( self.client.base_url, ProjectClient.ENDPOINT), body=json.dumps({ 'results': projects, 'count': 10, 'next': None }), content_type='application/json', status=200) projects = self.client.list_projects() assert len(projects) == 10
def test_project_config(self): config_dict = { 'name': 'test', 'description': '', 'is_public': True, 'has_code': True, 'has_tensorboard': True, 'num_experiments': 0, 'num_independent_experiments': 0, 'num_experiment_groups': 0, 'created_at': local_now().isoformat(), 'updated_at': local_now().isoformat() } config = ProjectConfig.from_dict(config_dict) config_to_dict = config.to_dict() config_to_dict.pop('experiment_groups', None) config_to_dict.pop('experiments', None) config_to_dict.pop('has_notebook', None) config_to_dict.pop('unique_name', None) config_to_dict.pop('user', None) config_to_dict.pop('uuid', None) assert config_to_dict == config_dict config_dict.pop('description') config_dict.pop('updated_at') config_dict.pop('has_code') config_to_dict = config.to_light_dict() config_to_dict.pop('has_notebook', None) config_to_dict.pop('unique_name', None) assert config_to_dict == config_dict config_to_dict = config.to_dict(humanize_values=True) assert config_to_dict.pop('created_at') == 'a few seconds ago' assert config_to_dict.pop('updated_at') == 'a few seconds ago' config_to_dict = config.to_light_dict(humanize_values=True) assert config_to_dict.pop('created_at') == 'a few seconds ago'
def test_project_config(self): config_dict = {'name': 'test', 'description': '', 'is_public': True} config = ProjectConfig.from_dict(config_dict) assert config.to_dict() == config_dict