Skip to content

Commit

Permalink
OPIK-360 Andrei/projects crud tests (#565)
Browse files Browse the repository at this point in the history
* sanity fixes

* projects crud automated tests

* actions workflows

* fixed typo

* fixed sanity

* removed on push activation

---------

Co-authored-by: Andrei Căutișanu <[email protected]>
Co-authored-by: Andrei Căutișanu <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2024
1 parent faed49e commit 57e0056
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
name: Install Local Version of Opik
name: Run Selected Suite

on:
workflow_dispatch:
inputs:
suite:
type: choice
description: 'Choose which test suite to run'
required: true
default: 'projects-CRUD'
options:
- projects-CRUD

jobs:
test_installation:
run_suite:
runs-on: ubuntu-20.04

steps:
Expand All @@ -31,23 +39,33 @@ jobs:
OPIK_USAGE_REPORT_ENABLED: false
run: |
cd ${{ github.workspace }}/deployment/docker-compose
docker compose up --detach
docker compose up -d --build
- name: Check Docker pods are up
run: |
chmod +x ./tests_end_to_end/installer/check_docker_compose_pods.sh
./tests_end_to_end/installer/check_docker_compose_pods.sh
chmod +x ./tests_end_to_end/installer_utils/check_docker_compose_pods.sh
./tests_end_to_end/installer_utils/check_docker_compose_pods.sh
shell: bash

- name: Check backend health
run: |
chmod +x ./tests_end_to_end/installer/check_backend.sh
./tests_end_to_end/installer/check_backend.sh
chmod +x ./tests_end_to_end/installer_utils/check_backend.sh
./tests_end_to_end/installer_utils/check_backend.sh
shell: bash

- name: Check app is up via the UI
run: |
pytest -v -s ${{ github.workspace }}/tests_end_to_end/installer/test_app_status.py
pytest -v -s ${{ github.workspace }}/tests_end_to_end/installer_utils/test_app_status.py
- name: Run suite
run: |
SUITE="${{ github.event.inputs.suite || 'projects-CRUD' }}"
cd ${{ github.workspace }}/tests_end_to_end
export PYTHONPATH='.'
if [ "$SUITE" == "projects-CRUD" ]; then
pytest -s tests/Projects/test_projects_crud_operations.py --browser chromium --base-url http://localhost:5173 --setup-show
fi
- name: Stop Opik server
if: always()
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ jobs:
- name: Check Docker pods are up
run: |
chmod +x ./tests_end_to_end/installer/check_docker_compose_pods.sh
./tests_end_to_end/installer/check_docker_compose_pods.sh
chmod +x ./tests_end_to_end/installer_utils/check_docker_compose_pods.sh
./tests_end_to_end/installer_utils/check_docker_compose_pods.sh
shell: bash

- name: Check backend health
run: |
chmod +x ./tests_end_to_end/installer/check_backend.sh
./tests_end_to_end/installer/check_backend.sh
chmod +x ./tests_end_to_end/installer_utils/check_backend.sh
./tests_end_to_end/installer_utils/check_backend.sh
shell: bash

- name: Check app is up via the UI
run: |
pytest -v -s ${{ github.workspace }}/tests_end_to_end/installer/test_app_status.py
pytest -v -s ${{ github.workspace }}/tests_end_to_end/installer_utils/test_app_status.py
- name: Run sanity suite
run: |
cd ${{ github.workspace }}/tests_end_to_end
export PYTHONPATH='.'
pytest -s application_sanity/test_sanity.py --browser chromium --base-url http://localhost:5173 --setup-show
pytest -s tests/application_sanity/test_sanity.py --browser chromium --base-url http://localhost:5173 --setup-show
- name: Stop Opik server
if: always()
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/sdk-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ jobs:
- name: Check Opik server availability
shell: bash
run: |
chmod +x ${{ github.workspace }}/tests_end_to_end/installer/*.sh
chmod +x ${{ github.workspace }}/tests_end_to_end/installer_utils/*.sh
cd ${{ github.workspace }}/deployment/docker-compose
echo "Check Docker pods are up"
${{ github.workspace }}/tests_end_to_end/installer/check_docker_compose_pods.sh
${{ github.workspace }}/tests_end_to_end/installer_utils/check_docker_compose_pods.sh
echo "Check backend health"
${{ github.workspace }}/tests_end_to_end/installer/check_backend.sh
${{ github.workspace }}/tests_end_to_end/installer_utils/check_backend.sh
- name: Install opik SDK
run: |
Expand Down
File renamed without changes.
39 changes: 37 additions & 2 deletions tests_end_to_end/page_objects/ProjectsPage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from playwright.sync_api import Page, expect
import time

class ProjectsPage:
def __init__(self, page: Page):
Expand All @@ -12,5 +13,39 @@ def go_to_page(self):
def click_project(self, project_name):
self.page.get_by_role('cell', name=project_name).click()

def check_project_exists(self, project_name):
expect(self.projects_table.get_by_role('cell', name=project_name)).to_be_visible()
def search_project(self, project_name):
self.page.get_by_test_id("search-input").click()
self.page.get_by_test_id("search-input").fill(project_name)

def check_project_exists_on_current_page(self, project_name):
expect(self.page.get_by_role('cell', name=project_name, exact=True)).to_be_visible()

def check_project_not_exists_on_current_page(self, project_name):
expect(self.page.get_by_role('cell', name=project_name, exact=True)).not_to_be_visible()

def check_project_exists_on_current_page_with_retry(self, project_name, timeout):
start_time = time.time()
while time.time() - start_time < timeout:
try:
self.check_project_exists_on_current_page(project_name=project_name)
break
except AssertionError:
self.page.wait_for_timeout(500)
else:
raise AssertionError(f'project {project_name} not found in projects list within {timeout} seconds')

def create_new_project(self, project_name):
self.page.get_by_role("button", name="Create new project").click()

project_name_fill_box = self.page.get_by_placeholder("Project name")
project_name_fill_box.click()
project_name_fill_box.fill(project_name)

self.page.get_by_role("button", name="Create project").click()

def delete_project_by_name(self, project_name):
self.search_project(project_name)
row = self.page.get_by_role('row').filter(has_text=project_name).filter(has=self.page.get_by_role('cell', name=project_name, exact=True))
row.get_by_role("button").click()
self.page.get_by_role("menuitem", name="Delete").click()
self.page.get_by_role("button", name="Delete project").click()
48 changes: 48 additions & 0 deletions tests_end_to_end/tests/Projects/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest
import os
from typing import Optional

import opik
from playwright.sync_api import Page
from opik.rest_api.client import OpikApi

from sdk_helpers import create_project_sdk, delete_project_by_name_sdk
from page_objects.ProjectsPage import ProjectsPage


@pytest.fixture(scope='function')
def create_project_sdk_no_cleanup():
proj_name = 'projects_crud_tests_sdk'

create_project_sdk(name=proj_name)
yield proj_name


@pytest.fixture(scope='function')
def create_project_ui_no_cleanup(page: Page):
proj_name = 'projects_crud_tests_ui'
projects_page = ProjectsPage(page)
projects_page.go_to_page()
projects_page.create_new_project(project_name=proj_name)

yield proj_name


@pytest.fixture(scope='function')
def create_delete_project_sdk():
proj_name = 'projects_crud_tests_sdk'

create_project_sdk(name=proj_name)
yield proj_name
delete_project_by_name_sdk(name=proj_name)


@pytest.fixture
def create_delete_project_ui(page: Page):
proj_name = 'projects_crud_tests_ui'
projects_page = ProjectsPage(page)
projects_page.go_to_page()
projects_page.create_new_project(project_name=proj_name)

yield proj_name
delete_project_by_name_sdk(name=proj_name)
49 changes: 49 additions & 0 deletions tests_end_to_end/tests/Projects/sdk_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest
import os
import time

import opik
from playwright.sync_api import Page
from opik.rest_api.client import OpikApi


def create_project_sdk(name: str):
client = OpikApi()
client.projects.create_project(name=name)


def find_project_by_name_sdk(name: str):
client = OpikApi()
proj_page = client.projects.find_projects(name=name, page=1, size=1)
return proj_page.dict()['content']


def delete_project_by_name_sdk(name: str):
client = OpikApi()
project = find_project_by_name_sdk(name=name)
client.projects.delete_project_by_id(project[0]['id'])


def wait_for_project_to_be_visible(project_name, timeout=10, initial_delay=1):
start_time = time.time()
delay = initial_delay

while time.time() - start_time < timeout:
if find_project_by_name_sdk(project_name):
return True

time.sleep(delay)
delay = min(delay*2, timeout-(time.time() - start_time))

raise TimeoutError(f'could not get created project {project_name} via API within {timeout} seconds')


def update_project_by_name_sdk(name: str, new_name: str):
client = OpikApi()
wait_for_project_to_be_visible(name, timeout=10)
projects_match = find_project_by_name_sdk(name)
project_id = projects_match[0]['id']

client.projects.update_project(id=project_id, name=new_name)

return project_id
Loading

0 comments on commit 57e0056

Please sign in to comment.