def test_set_navigation_projects(self): base_view = views.BaseView() projects = [models.Project(1, "Project1", 0, "token")] base_view.set_navigation_projects(projects) assert base_view.view_model["navigation_projects"][0]["id"] == 1 assert base_view.view_model["navigation_projects"][0][ "name"] == "Project1"
def test_render(self): project_sessions_view = views.ProjectSessionsView() project = models.Project(1, "Project1", 0, "token") project_sessions_view.set_project(project) sessions = [ models.Session(1, 1, None, None, True, False, "127.0.0.1", 1) ] project_sessions_view.set_project_sessions(sessions) sessions_epochs = [[ models.Epoch(1, 0, { "loss": 0, "acc": 1, "custom": 2 }, datetime.datetime.now(), 1) ]] project_sessions_view.set_project_sessions_epochs(sessions_epochs) project_sessions_view.render() assert project_sessions_view.view_model["list_sessions"][0]["id"] == 1 assert project_sessions_view.view_model["list_sessions"][0][ "index"] == 1 assert project_sessions_view.view_model["list_sessions"][0][ "is_active"] == True assert project_sessions_view.view_model["list_sessions"][0][ "loss"] == 0 assert project_sessions_view.view_model["list_sessions"][0]["acc"] == 1 assert project_sessions_view.view_model["breadcrumbs"][1][ "label"] == "Sessions" assert project_sessions_view.view_model["breadcrumbs"][1][ "url"] == "/projects/1/sessions"
def test_render_instructions(self): project_view = views.ProjectView() project = models.Project(1, "Project1", 0, "token") project_view.set_project(project) project_view.set_project_sessions([]) project_view.render() assert project_view.custom_template == "instructions"
def get_all_projects(self): query = "SELECT id_project, name, session_counter, token FROM projects" rows = self.query(query).fetchall() projects = [] for row in rows: id_project = row[0] name = row[1] session_counter = row[2] token = row[3] projects.append( models.Project(id_project, name, session_counter, token)) return projects
def get_project_by_token(self, token): query = "SELECT id_project, name, session_counter, token FROM projects WHERE token = ?" vars = [token] rows = self.query(query, vars).fetchall() project = None if len(rows) > 0: row = rows[0] id_project = row[0] name = row[1] session_counter = row[2] token = row[3] project = models.Project(id_project, name, session_counter, token) return project
def test_render(self): project_view = views.ProjectView() project = models.Project(1, "Project1", 0, "token") project_view.set_project(project) sessions = [ models.Session(1, 1, None, None, True, False, "127.0.0.1", 1) ] project_view.set_project_sessions(sessions) project_view.render() assert any(d["type"] == "display_token" for d in project_view.view_model["icons"]) assert any(d["type"] == "delete_project" for d in project_view.view_model["icons"]) assert project_view.view_model["breadcrumbs"][0]["label"] == "Project1" assert project_view.view_model["breadcrumbs"][0][ "url"] == "/projects/1"
def test_render(self): dashboard_view = views.DashboardView() dashboard_view.set_projects( [models.Project(1, "Project1", 0, "token")]) dashboard_view.set_sessions( [models.Session(1, 1, None, None, True, False, "127.0.0.1", 1)]) dashboard_view.render() assert dashboard_view.view_model["title"] == "Dashboard" assert dashboard_view.view_model["number_projects"] == 1 assert dashboard_view.view_model["number_running_sessions"] == 1 assert dashboard_view.view_model["icons"][0][ "type"] == "create_project" assert dashboard_view.view_model["breadcrumbs"][0][ "label"] == "Dashboard" assert dashboard_view.view_model["breadcrumbs"][0][ "url"] == "/dashboard"
def test_render(self): session_view = views.SessionView() project = models.Project(1, "Project1", 0, "token") session_view.set_project(project) session = models.Session(1, 1, None, None, True, False, "127.0.0.1", 1) session_view.set_session(session) epochs = [ models.Epoch(1, 0, { "loss": 0, "acc": 1, "custom": 2 }, datetime.datetime.now(), 1) ] session_view.set_session_epochs(epochs) session_view.render() assert session_view.view_model["breadcrumbs"][0]["label"] == "Project1" assert session_view.view_model["breadcrumbs"][0][ "url"] == "/projects/1" assert session_view.view_model["breadcrumbs"][1]["label"] == "Sessions" assert session_view.view_model["breadcrumbs"][1][ "url"] == "/projects/1/sessions" assert session_view.view_model["breadcrumbs"][2][ "url"] == "/projects/1/sessions/1" assert session_view.view_model["graphs"]["loss"]["data"][0][ "epoch"] == 0 assert session_view.view_model["graphs"]["loss"]["data"][0][ "loss"] == 0 assert session_view.view_model["graphs"]["acc"]["data"][0][ "epoch"] == 0 assert session_view.view_model["graphs"]["acc"]["data"][0]["acc"] == 1 assert session_view.view_model["graphs"]["custom"]["data"][0][ "epoch"] == 0 assert session_view.view_model["graphs"]["custom"]["data"][0][ "custom"] == 2 assert session_view.view_model["is_active"] == True assert session_view.view_model["number_epochs"] == 1 assert any(d["type"] == "delete_session" for d in session_view.view_model["icons"])
def test_set_project(self): project_view = views.ProjectView() project = models.Project(1, "Project1", 0, "token") project_view.set_project(project) assert project_view.project == project
def test_set_project(self): session_view = views.SessionView() project = models.Project(1, "Project1", 0, "token") session_view.set_project(project) assert session_view.project == project