Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

494 selenium+docker #503

Merged
merged 66 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b8ee64e
add folder tests
MarinaProsche Dec 11, 2023
2218ad6
add test folder and first test
MarinaProsche Dec 11, 2023
e095e91
first version of auyh tests
MarinaProsche Dec 12, 2023
10950d7
added param in commandline and class
MarinaProsche Dec 29, 2023
3dc0bb7
from basic test
MarinaProsche Jan 22, 2024
05c504f
first version of test_statistic
MarinaProsche Jan 22, 2024
76d7644
copied from 485
MarinaProsche Feb 6, 2024
0c83e22
added test_debug.py
MarinaProsche Feb 6, 2024
3333658
version_test done
MarinaProsche Feb 7, 2024
a45c1a1
tests/requirements.txt added
MarinaProsche Feb 7, 2024
c216d92
requrements.txt and def authorization() added
MarinaProsche Feb 7, 2024
64af71e
base for new test
MarinaProsche Feb 7, 2024
203f437
test is ready
MarinaProsche Feb 7, 2024
2da1273
base for new selenium test
MarinaProsche Feb 8, 2024
30ed760
change structure
MarinaProsche Feb 8, 2024
edd31ac
added pres example for testing
MarinaProsche Feb 8, 2024
0a1847c
info in README.md
MarinaProsche Feb 8, 2024
1d6d1e0
full test
MarinaProsche Feb 8, 2024
fbfd2bd
delete changes of restart.sh
MarinaProsche Feb 8, 2024
ed59b0f
Merge branch '481_first_selenium_test' into 485_selenium_test_statistic
MarinaProsche Feb 21, 2024
0145493
test_statistic improved
MarinaProsche Feb 21, 2024
83e8fa4
first try of Dockerfile_selenium
MarinaProsche Feb 23, 2024
11febfa
Tests added in Docker (ready)
MarinaProsche Feb 27, 2024
b35315a
setting changed (Firefox to Chrome)
MarinaProsche Feb 27, 2024
b370b02
Merge branch '484_selenium_pres_load' into 494_selenium+docker
MarinaProsche Feb 28, 2024
15712e0
default pres added
MarinaProsche Feb 28, 2024
be76b5e
486 merged
MarinaProsche Feb 28, 2024
9f7f374
487 merged
MarinaProsche Feb 28, 2024
81db6fa
load_report_test added
MarinaProsche Feb 28, 2024
a1b9f3c
full set of tests up to 28.02
MarinaProsche Feb 28, 2024
139636e
added new docker-compose-tests
MarinaProsche Feb 29, 2024
379ac42
docer-compose for tests ready
MarinaProsche Feb 29, 2024
4714576
base of gh-actions for selenium
MarinaProsche Feb 29, 2024
3ab790c
add check
MarinaProsche Mar 1, 2024
2495daa
mistake fixed
MarinaProsche Mar 1, 2024
0835838
set output
MarinaProsche Mar 1, 2024
3d73311
loop added
MarinaProsche Mar 1, 2024
ed6b745
structure changed
MarinaProsche Mar 1, 2024
8297fc7
try to fix test using time limit
MarinaProsche Mar 1, 2024
2abbbc4
try another par
MarinaProsche Mar 4, 2024
6631156
fixed condition
MarinaProsche Mar 7, 2024
0d681ed
try to fix
MarinaProsche Mar 7, 2024
d462a12
structure is improved
MarinaProsche Mar 11, 2024
a53c77a
structure and test check changed
MarinaProsche Mar 11, 2024
17ecf43
new folder
MarinaProsche Mar 11, 2024
9320a19
fix mistake
MarinaProsche Mar 11, 2024
86b2868
step results added
MarinaProsche Mar 11, 2024
2730fe0
Some docker_check_tests.sh fixes for 494 (#508)
HadronCollider Mar 12, 2024
3f40471
first part of improvment
MarinaProsche Mar 15, 2024
9c4020f
2 part of improvement
MarinaProsche Mar 16, 2024
271e198
version.json added
MarinaProsche Mar 16, 2024
f1ed726
added version.json
MarinaProsche Mar 16, 2024
e0a4378
remove VERSION.json
MarinaProsche Mar 16, 2024
bd918f9
merge master (fix requirements.txt conflict)
HadronCollider Mar 16, 2024
a438b33
change using crypto-js to md5 (for password hash)
HadronCollider Mar 16, 2024
8f3cd06
update url to repo
HadronCollider Mar 16, 2024
d528cb3
download nltk and language_tool_python on worker ready
HadronCollider Mar 16, 2024
977207e
Merge pull request #512 from moevm/project_updates
HadronCollider Mar 16, 2024
7cf119f
Add CELERY_QUERIES to tests
HadronCollider Mar 17, 2024
5523968
add default get_main_headers logic for base class
HadronCollider Mar 17, 2024
37debe2
remove step 'Build system images (non-pulling)' for selenium workflow
HadronCollider Mar 17, 2024
65376ab
fix mistake with main_header
MarinaProsche Mar 18, 2024
fb0b409
Merge branch '494_selenium+docker' into 466_fix_main_header_for_docx
HadronCollider Mar 18, 2024
38b79c4
Merge pull request #514 from moevm/466_fix_main_header_for_docx
HadronCollider Mar 18, 2024
fcddd46
docker_check_tests.sh: logs are added, while-true is removed
MarinaProsche Mar 18, 2024
92e8968
remove old docker-compose-tests, improved README, changed Dockerfile_…
MarinaProsche Mar 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ CONSUMER_SECRET=secret
WEB_PORT=8080

REDIS_URL=redis://redis:6379/0
CELERY_QUERIES=query
CELERY_QUERIES=check-solution

FLOWER_SECRET_KEY=123
FLOWER_PORT=5555
FLOWER_AUTH=user:user
FLOWER_PREFIX=/

MONGODB_CACHE_SIZE=1
MONGODB_CACHE_SIZE=1
45 changes: 45 additions & 0 deletions .github/workflows/selenium_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Selenium_tests

on: [push]

jobs:
check_tests:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- name: Build docker-compose with docker-compose-selenium (tests)
run: |
cp .env_example .env
cp app/VERSION_example.json app/VERSION.json
docker-compose -f docker-compose.yml -f docker-compose-selenium.yml build

- name: Run docker-compose with docker-compose-selenium (tests)
run: |
docker-compose -f docker-compose.yml -f docker-compose-selenium.yml up -d
chmod +x tests/scripts/docker_check_tests.sh
./tests/scripts/docker_check_tests.sh


# jobs:
# check_tests:
# runs-on: ubuntu-20.04

# steps:
# - uses: actions/checkout@v2

# - name: Simplify docker-compose file name
# run: mv docker-compose-tests.yml docker-compose.yml

# - name: Build system images (non-pulling)
# run: |
# # build base image
# docker build -f Dockerfile_base -t osll/slides-base:20230202 .

# - name: Run docker-compose tests
# run: |
# cp .env_example .env
# docker-compose up -d
# chmod +x tests/scripts/docker_check_tests.sh
# ./tests/scripts/docker_check_tests.sh
17 changes: 17 additions & 0 deletions Dockerfile_selenium
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM selenium/standalone-chrome:121.0-chromedriver-121.0-grid-4.18.0-20240220

ENV LOGIN=""
ENV PASSWORD=""

WORKDIR /usr/src/project

USER root
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По умолчанию всё запускается от root, поэтому, возможно, лишняя команда

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Комментарий ещё актуален

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Без команды возникает ошибка с правами.

RUN apt-get update && \
apt-get install -y python3 python3-pip && \
rm -rf /var/lib/apt/lists/*

COPY tests/requirements.txt tests/requirements.txt
RUN pip install -r tests/requirements.txt
COPY tests ./tests

ENTRYPOINT python3 tests/main.py --login ${LOGIN} --password ${PASSWORD}
6 changes: 6 additions & 0 deletions app/VERSION_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"commit": "",
"message": "",
"date": "",
"version": ""
}
2 changes: 1 addition & 1 deletion app/main/checks/report_checks/needed_headers_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def late_init(self):
self.headers = self.file.make_chapters(self.file_type['report_type'])
self.headers_page = self.file.find_header_page(self.file_type['report_type'])
self.chapters_str = self.file.show_chapters(self.file_type['report_type'])
self.headers_main = self.file.get_main_headers()
# TODO: change
self.headers_main = self.file.get_main_headers(self.file_type['report_type'])
if self.headers_main == "Задание 1":
self.patterns = StyleCheckSettings.CONFIGS.get(self.config)[0]["headers"]
elif self.headers_main == "Задание 2":
Expand Down
3 changes: 3 additions & 0 deletions app/main/reports/document_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ def find_literature_page(self, work_type):
@abstractmethod
def show_chapters(self, work_type):
pass

def get_main_headers(self):
pass
7 changes: 7 additions & 0 deletions app/main/reports/docx_uploader/docx_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self):
self.inline_shapes = []
self.core_properties = None
self.headers = []
self.headers_main = ''
self.file = None
self.special_paragraph_indices = {}
self.headers_page = 0
Expand Down Expand Up @@ -90,6 +91,12 @@ def make_headers(self, work_type):
break
self.headers = headers
return self.headers

def get_main_headers(self, work_type): #this method helps to avoid mistake in "needed_headers_check" (because of structure checks for md)
if not self.headers_main:
if work_type == 'VKR':
self.headers_main = self.make_headers(work_type)[1]['name']
return self.headers_main

def __make_table(self, tables):
for i in range(len(tables)):
Expand Down
2 changes: 1 addition & 1 deletion app/main/reports/md_uploader/md_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def page_counter(self): # we need this just to find a last page and make link to
self.page_count = 5
return self.page_count

def get_main_headers(self):
def get_main_headers(self, work_type):
if not self.headers_main:
header_main_regex = "<h1>(.*?)<\/h1>"
self.headers_main = re.findall(header_main_regex, self.html_text)[0]
Expand Down
4 changes: 0 additions & 4 deletions app/nlp/stemming.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import itertools

import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize, sent_tokenize
from pymorphy2 import MorphAnalyzer

nltk.download('stopwords')
nltk.download('punkt')

MORPH_ANALYZER = MorphAnalyzer()
TASKS = 'задачи:'
Expand Down
28 changes: 19 additions & 9 deletions app/tasks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import configparser
from configparser import ConfigParser
import os
from os.path import join, exists

from celery import Celery
from celery.signals import worker_ready

import passback_grades
from passback_grades import run_passback
from db import db_methods
from db.db_types import Check
from main.checker import check
from main.parser import parse
from main.check_packs import BASE_PACKS
from root_logger import get_root_logger

config = configparser.ConfigParser()
config = ConfigParser()
config.read('app/config.ini')

TASK_RETRY_COUNTDOWN = 60 # default = 3 * 60
Expand All @@ -33,6 +34,16 @@
celery.conf.timezone = 'Europe/Moscow' # todo: get from env


@worker_ready.connect
def at_start(sender, **k):
from nltk import download
download('stopwords')
download('punkt')

from language_tool_python.download_lt import download_lt
download_lt()


@celery.task(name="create_task", queue='check-solution', bind=True)
def create_task(self, check_info):
check_obj = Check(check_info)
Expand Down Expand Up @@ -67,12 +78,11 @@ def create_task(self, check_info):
self.retry(countdown=TASK_RETRY_COUNTDOWN) # Retry the task, adding it to the back of the queue.


@celery.task(name="passback-task", queue='passback-grade')
def passback_task():
return run_passback()


def remove_files(filepaths):
for filepath in filepaths:
if exists(filepath): os.remove(filepath)


@celery.task(name="passback-task", queue='passback-grade')
def passback_task():
print('Run passback')
return passback_grades.run_passback()
2 changes: 1 addition & 1 deletion app/templates/criteria_pack.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</label><br>
<label>
Список критериев набора (однажды тут будет подробнейшая <a
href="https://github.com/moevm/mse_auto_checking_slides_vaganov/issues/351">инструкция</a>)<br>
href="https://github.com/moevm/document_insight_system/issues/351">инструкция</a>)<br>
# укажите здесь конфигурацию набора в формате JSON<br>
<textarea id="raw_criterions" rows=10 cols=80
required>{{ pack['raw_criterions'] }}</textarea>
Expand Down
4 changes: 2 additions & 2 deletions app/templates/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</script>
<div class="col-11 col-sm-8 col-md-5 col-lg-4 my-auto">
<h3 class="text-center ins" id="upload_title">{{ upload_title }}</h3>
<p class="text-center" id="criteria_pack_name">Для проверки используется набор
критериев<br><b>{{ current_user.criteria }}</b></p>
<p class="text-center" id="criteria_pack_name_text">Для проверки используется набор
критериев<br><b id="criteria_pack_name">{{ current_user.criteria }}</b></p>
<div class="row justify-content-center" id="uploading_body">
<div class="col my-auto">
<form>
Expand Down
4 changes: 2 additions & 2 deletions assets/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'bootstrap-icons/font/bootstrap-icons.css'
import 'bootstrap-datepicker';
import 'bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css'

import * as CryptoJS from "crypto-js";
import * as md5 from "md5";

import '../styles/main.css';

Expand All @@ -33,7 +33,7 @@ import '../styles/404.css';


export function hash(password) {
return CryptoJS.MD5(password).toString()
return md5(password)
}

export function collect_values_if_possible(...ids) {
Expand Down
13 changes: 13 additions & 0 deletions docker-compose-selenium.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:
selenium-tests:
build:
context: .
dockerfile: Dockerfile_selenium
environment:
- LOGIN=${ADMIN_PASSWORD}
- PASSWORD=${ADMIN_PASSWORD}
depends_on:
- web
network_mode: service:web
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "mse_auto_checking_slides_vaganov",
"name": "document_insight_system",
"version": "1.0.0",
"license": "ISC",
"repository": "https://github.com/moevm/mse_auto_checking_slides_vaganov",
"repository": "https://github.com/moevm/document_insight_system",
"description": "Presentation parsing app",
"scripts": {
"watch": "webpack --watch",
Expand All @@ -21,10 +21,10 @@
"bootstrap-icons": "1.5.0",
"bootstrap-table": "1.18.3",
"clean-webpack-plugin": "^3.0.0",
"crypto-js": "^3.1.2",
"css-loader": "6.2.0",
"file-loader": "6.2.0",
"jquery": "^3.5.1",
"md5": "2.3.0",
"pdfjs-dist": "2.5.207",
"popper.js": "1.16.1",
"style-loader": "3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ echo "{
\"message\": \"$COMMIT_MSG\",
\"date\": \"$DATE\",
\"version\": \"$VERSION\"
}"
}"
73 changes: 73 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

## For local tests:

```bash
$ pip install -r tests/requirements.txt
```

### Run tests:

use login and password from .env
You can run tests with your own data:

```bash

$ python3 tests/main.py --host host --login login --password password --pres your press --report your report --report_doc your report doc
```

or use default setting:

```bash
$ python3 tests/main.py --login login --password password
```

## Docker:

### Dockerfile
You can run tests with dockerfile_selenium independently, using special flag:

```bash
$ docker build -t your_image_name -f Dockerfile_selenium .
$ docker run -e LOGIN=your_login -e PASSWORD=your password --network="host" your_image_name

```

### Docker-compose
You can run docker-compose-selenium with docker-compose:

```bash
$ docker-compose -f docker-compose.yml -f docker-compose-selenium.yml build
$ docker-compose -f docker-compose.yml -f docker-compose-selenium.yml up

```

## List of tests:

### Test for autorization:

class AuthTestSelenium(BasicSeleniumTest) with 3 tests
Tests check: if page "/login" opens, if it doesn't take wrong login/password and takes correct.

### Test for open page /check_list:

class StatisticTestSelenium(BasicSeleniumTest) with 1 test
Test check: if page "/check_list" opens


### Test for open single check card:

class SingleCheckTestSelenium(BasicSeleniumTest) with 1 test
Test check: if page with random single check opens (from "/check_list")

### Test for open page /version:

class VersionTestSelenium(BasicSeleniumTest) with 1 test
Test check: if page "/version" opens and contains info from "VERSION.json"

### Test for loading report and pres:

class FileLoadTestSelenium(BasicSeleniumTest) with 3 tests
Test check: if reports wit different extensions loads correctly
use default documents from "/tests" or your own example


Loading
Loading