Skip to content

Commit

Permalink
Project structure 3 (#4287)
Browse files Browse the repository at this point in the history
* chenged tests dir

* fixed all linter problems

* fix  precomit

* fix compose

* fixed  tests root dir
  • Loading branch information
johniak authored Oct 3, 2024
1 parent 7ec51ba commit 78ef72a
Show file tree
Hide file tree
Showing 107 changed files with 437 additions and 571 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exclude =
migrations,
snapshots,
__pypackages__,
frontend,

ignore =
# black formatting related
Expand Down
2 changes: 1 addition & 1 deletion .github/helpers/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else
--cov-report xml:test-coverage/coverage.xml \
--randomly-seed=42 \
--create-db \
/tests/unit/
./tests/unit/
;;
"lint")
mkdir -p ./lint-results
Expand Down
2 changes: 1 addition & 1 deletion .github/helpers/docker-compose.selenium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
backend:
volumes:
- ../../tests/test-coverage:/code/test-coverage
- ../../tests/report/:/tests/selenium/output_data/report/
- ../../tests/report/:/code/tests/selenium/output_data/report/
- type: volume
source: backend-web-app
target: /code/src/hct_mis_api/apps/web
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ jobs:
-f ./.github/helpers/docker-compose.selenium.yml \
run backend bash -c "
waitforit -host=db -port=5432 -timeout=30
pytest -svvv $extra_options /tests/selenium --cov-report xml:test-coverage/coverage.xml --html-report=/tests/selenium/output_data/report/report.html --randomly-seed=42
pytest -svvv $extra_options ./tests/selenium --cov-report xml:test-coverage/coverage.xml --html-report=./tests/selenium/output_data/report/report.html --randomly-seed=42
"
- name: Upload Artifact
uses: actions/upload-artifact@v4
Expand Down
49 changes: 8 additions & 41 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
stages: [commit]
- repo: https://github.com/ambv/black
rev: 23.12.1
hooks:
- id: black
args: [--config=backend/pyproject.toml]
exclude: "migrations|snapshots"
stages: [commit]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [--config=backend/.flake8]
additional_dependencies: [flake8-bugbear==22.12.6]
stages: [ commit ]
exclude: /deployment/|/migrations/
# mypy precommit hook
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
hooks:
- id: mypy
verbose: true
args: [--config-file=backend/pyproject.toml, --follow-imports=skip]
pass_filenames: true
stages: [commit]
additional_dependencies: [
types-requests==2.28.11.15,
types-redis==4.5.1.4,
types-python-dateutil==2.8.19.10,
types-pytz==2022.7.1.2,
djangorestframework-stubs==1.9.1,
graphene-stubs==0.15,
django-stubs==1.15.0,
django-stubs-ext==0.7.0,
openpyxl-stubs==0.1.25
]
exclude: /deployment/|/migrations/
- repo: local
hooks:
- id: Linters checks
name: Linters checks
entry: docker compose -f development_tools/compose.yml run --no-TTY -i --rm backend sh -c 'black . --check && isort . --check-only && flake8 . && mypy .'
language: system
pass_filenames: false
verbose: true
6 changes: 1 addition & 5 deletions development_tools/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ services:
ports:
- "8080:8000"
volumes:
- ../src:/code/src/
- ../manage.py:/code/manage.py
- ../pyproject.toml:/code/pyproject.toml
- ../pdm.lock:/code/pdm.lock
- ../tests:/tests/
# - ../.:/code/
- backend-data:/data
- ../pyproject.toml:/packages/pyproject.toml
- ../pdm.lock:/packages/pdm.lock
Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ENV PYTHONPYCACHEPREFIX=/tmp/pycache \
PYTHONPATH=$PYPACKAGES/lib:$PYTHONPATH \
PATH=$PYPACKAGES/bin:$PATH \
XDG_RUNTIME_DIR=/run/user/"${UID}"

ENV DJANGO_SETTINGS_MODULE=hct_mis_api.config.settings
WORKDIR $CODE

COPY --from=waitforit /data/waitforit /usr/local/bin/waitforit
Expand Down Expand Up @@ -82,12 +82,12 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ENV PYTHONPATH=$CODE/src:/test/:$PYTHONPATH
ENV PYTHONPATH=$CODE/src:$CODE/test/:$PYTHONPATH
RUN pdm sync --no-editable --no-self --no-isolation

WORKDIR $CODE
COPY ./src/ ./src/
COPY ./tests /tests
COPY ./tests ./tests
COPY ./manage.py ./manage.py
COPY .flake8 pyproject.toml pdm.lock ./
COPY ./docker/entrypoint.sh /bin/
Expand Down
31 changes: 16 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exclude = '''
| migrations
| snapshots
| __pypackages__
| frontend
)/
'''
# TODO: remove migrations exclude rule once it won't create much conflicts between feature branches and develop
Expand Down Expand Up @@ -45,18 +46,18 @@ known_first_party = [
"accountability",
]
known_django = "django"
sections = ["FUTURE","STDLIB","DJANGO","THIRDPARTY","FIRSTPARTY","LOCALFOLDER"]
sections = ["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
include_trailing_comma = true
skip = ["migrations", "snapshots", "venv", "__pypackages__"]
skip = ["migrations", "snapshots", "venv", ".venv", "__pypackages__", "frontend"]

[tool.mypy]
python_version = 3.11
show_error_codes = true
exclude = [
"migrations",
"venv",
"snapshots",
"__pypackages__",
"migrations",
"venv",
"snapshots",
"__pypackages__",
]

strict = true
Expand All @@ -66,12 +67,12 @@ follow_imports = "skip"

# TODO: remove one, fix errors, repeat
disable_error_code = [
"var-annotated", # this enforces Django Model fields to have type annotations
"attr-defined",
"misc", # cannot subclass DjangoObjectType
"union-attr",
"type-arg", # this misses type parameters for graphene.ObjectType
"no-any-return", # this enforces adding return None for function that returns None
"var-annotated", # this enforces Django Model fields to have type annotations
"attr-defined",
"misc", # cannot subclass DjangoObjectType
"union-attr",
"type-arg", # this misses type parameters for graphene.ObjectType
"no-any-return", # this enforces adding return None for function that returns None
]

[tool.django-stubs]
Expand Down Expand Up @@ -133,7 +134,7 @@ requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.pdm.build]
includes = ['src/hct_mis_api','src/data']
includes = ['src/hct_mis_api', 'src/data']

[tool.pdm]
distribution = true
Expand All @@ -143,7 +144,7 @@ name = "hope"
version = "3.0.0"
description = "HCT MIS is UNICEF's humanitarian cash transfer platform."
authors = [
{name = "Tivix"},
{ name = "Tivix" },
]
dependencies = [
"setuptools==71.1.0",
Expand Down Expand Up @@ -242,7 +243,7 @@ dependencies = [
]
requires-python = "==3.11.*"
readme = "README.md"
license = {text = "None"}
license = { text = "None" }

[tool.setuptools]
py-modules = ["hct_mis_api"]
12 changes: 7 additions & 5 deletions tests/selenium/accountability/test_communication.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import pytest
from tests.selenium.helpers.fixtures import get_program_with_dct_type_and_name
from tests.selenium.page_object.accountability.communication import AccountabilityCommunication
from tests.selenium.page_object.accountability.comunication_details import (
AccountabilityCommunicationDetails,
)

from hct_mis_api.apps.account.models import User
from hct_mis_api.apps.accountability.fixtures import CommunicationMessageFactory
Expand All @@ -15,6 +10,13 @@
TargetPopulationFactory,
)
from hct_mis_api.apps.targeting.models import TargetPopulation
from tests.selenium.helpers.fixtures import get_program_with_dct_type_and_name
from tests.selenium.page_object.accountability.communication import (
AccountabilityCommunication,
)
from tests.selenium.page_object.accountability.comunication_details import (
AccountabilityCommunicationDetails,
)

pytestmark = pytest.mark.django_db(transaction=True)

Expand Down
8 changes: 5 additions & 3 deletions tests/selenium/accountability/test_surveys.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.db import transaction

import pytest
from tests.selenium.helpers.fixtures import get_program_with_dct_type_and_name
from tests.selenium.page_object.accountability.surveys import AccountabilitySurveys
from tests.selenium.page_object.accountability.surveys_details import AccountabilitySurveysDetails

from hct_mis_api.apps.account.models import User
from hct_mis_api.apps.accountability.fixtures import SurveyFactory
Expand All @@ -16,6 +13,11 @@
TargetingCriteriaFactory,
TargetPopulationFactory,
)
from tests.selenium.helpers.fixtures import get_program_with_dct_type_and_name
from tests.selenium.page_object.accountability.surveys import AccountabilitySurveys
from tests.selenium.page_object.accountability.surveys_details import (
AccountabilitySurveysDetails,
)

pytestmark = pytest.mark.django_db(transaction=True)

Expand Down
92 changes: 59 additions & 33 deletions tests/selenium/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,90 @@
from django.core.management import call_command

import pytest
from environ import Env
from _pytest.fixtures import FixtureRequest
from _pytest.nodes import Item
from _pytest.runner import CallInfo
from environ import Env
from flags.models import FlagState
from tests.selenium.page_object.accountability.communication import AccountabilityCommunication
from pytest_django.live_server_helper import LiveServer
from pytest_html_reporter import attach
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options

from hct_mis_api.apps.account.fixtures import RoleFactory, UserFactory
from hct_mis_api.apps.account.models import Partner, Role, User, UserRole
from hct_mis_api.apps.account.permissions import Permissions
from hct_mis_api.apps.core.models import (
BusinessArea,
BusinessAreaPartnerThrough,
DataCollectingType,
)
from hct_mis_api.apps.geo.models import Country
from hct_mis_api.apps.household.fixtures import DocumentTypeFactory
from hct_mis_api.apps.household.models import DocumentType
from tests.selenium.page_object.accountability.communication import (
AccountabilityCommunication,
)
from tests.selenium.page_object.accountability.comunication_details import (
AccountabilityCommunicationDetails,
)
from tests.selenium.page_object.accountability.surveys import AccountabilitySurveys
from tests.selenium.page_object.accountability.surveys_details import AccountabilitySurveysDetails
from tests.selenium.page_object.accountability.surveys_details import (
AccountabilitySurveysDetails,
)
from tests.selenium.page_object.admin_panel.admin_panel import AdminPanel
from tests.selenium.page_object.country_dashboard.country_dashboard import CountryDashboard
from tests.selenium.page_object.country_dashboard.country_dashboard import (
CountryDashboard,
)
from tests.selenium.page_object.filters import Filters
from tests.selenium.page_object.grievance.details_feedback_page import FeedbackDetailsPage
from tests.selenium.page_object.grievance.details_grievance_page import GrievanceDetailsPage
from tests.selenium.page_object.grievance.details_feedback_page import (
FeedbackDetailsPage,
)
from tests.selenium.page_object.grievance.details_grievance_page import (
GrievanceDetailsPage,
)
from tests.selenium.page_object.grievance.feedback import Feedback
from tests.selenium.page_object.grievance.grievance_dashboard import GrievanceDashboard
from tests.selenium.page_object.grievance.grievance_tickets import GrievanceTickets
from tests.selenium.page_object.grievance.new_feedback import NewFeedback
from tests.selenium.page_object.grievance.new_ticket import NewTicket
from tests.selenium.page_object.managerial_console.managerial_console import ManagerialConsole
from tests.selenium.page_object.managerial_console.managerial_console import (
ManagerialConsole,
)
from tests.selenium.page_object.payment_module.new_payment_plan import NewPaymentPlan
from tests.selenium.page_object.payment_module.payment_module import PaymentModule
from tests.selenium.page_object.payment_module.payment_module_details import PaymentModuleDetails
from tests.selenium.page_object.payment_module.payment_module_details import (
PaymentModuleDetails,
)
from tests.selenium.page_object.payment_module.program_cycle import (
ProgramCycleDetailsPage,
ProgramCyclePage,
)
from tests.selenium.page_object.payment_verification.payment_record import PaymentRecord
from tests.selenium.page_object.payment_verification.payment_verification import PaymentVerification
from tests.selenium.page_object.payment_verification.payment_verification import (
PaymentVerification,
)
from tests.selenium.page_object.payment_verification.payment_verification_details import (
PaymentVerificationDetails,
)
from tests.selenium.page_object.people.people import People
from tests.selenium.page_object.people.people_details import PeopleDetails
from tests.selenium.page_object.program_log.payment_log import ProgramLog
from tests.selenium.page_object.programme_details.programme_details import ProgrammeDetails
from tests.selenium.page_object.programme_management.programme_management import ProgrammeManagement
from tests.selenium.page_object.programme_details.programme_details import (
ProgrammeDetails,
)
from tests.selenium.page_object.programme_management.programme_management import (
ProgrammeManagement,
)
from tests.selenium.page_object.programme_population.households import Households
from tests.selenium.page_object.programme_population.households_details import HouseholdsDetails
from tests.selenium.page_object.programme_population.households_details import (
HouseholdsDetails,
)
from tests.selenium.page_object.programme_population.individuals import Individuals
from tests.selenium.page_object.programme_population.individuals_details import IndividualsDetails
from tests.selenium.page_object.programme_population.individuals_details import (
IndividualsDetails,
)
from tests.selenium.page_object.programme_population.periodic_data_update_templates import (
PeriodicDatUpdateTemplates,
PeriodicDatUpdateTemplatesDetails,
Expand All @@ -57,30 +98,15 @@
PeriodicDataUpdateUploads,
)
from tests.selenium.page_object.programme_users.programme_users import ProgrammeUsers
from tests.selenium.page_object.registration_data_import.rdi_details_page import RDIDetailsPage
from tests.selenium.page_object.registration_data_import.rdi_details_page import (
RDIDetailsPage,
)
from tests.selenium.page_object.registration_data_import.registration_data_import import (
RegistrationDataImport,
)
from tests.selenium.page_object.targeting.targeting import Targeting
from tests.selenium.page_object.targeting.targeting_create import TargetingCreate
from tests.selenium.page_object.targeting.targeting_details import TargetingDetails
from pytest_django.live_server_helper import LiveServer
from pytest_html_reporter import attach
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options

from hct_mis_api.apps.account.fixtures import RoleFactory, UserFactory
from hct_mis_api.apps.account.models import Partner, Role, User, UserRole
from hct_mis_api.apps.account.permissions import Permissions
from hct_mis_api.apps.core.models import (
BusinessArea,
BusinessAreaPartnerThrough,
DataCollectingType,
)
from hct_mis_api.apps.geo.models import Country
from hct_mis_api.apps.household.fixtures import DocumentTypeFactory
from hct_mis_api.apps.household.models import DocumentType


def pytest_addoption(parser) -> None: # type: ignore
Expand All @@ -97,8 +123,8 @@ def pytest_configure(config) -> None: # type: ignore
settings.SCREENSHOT_DIRECTORY = f"{settings.REPORT_DIRECTORY}/screenshot"
if not os.path.exists(settings.SCREENSHOT_DIRECTORY):
os.makedirs(settings.SCREENSHOT_DIRECTORY)
print('settings.SCREENSHOT_DIRECTORY',settings.SCREENSHOT_DIRECTORY)
print('*'*70)
print("settings.SCREENSHOT_DIRECTORY", settings.SCREENSHOT_DIRECTORY)
print("*" * 70)

for file in os.listdir(settings.SCREENSHOT_DIRECTORY):
os.remove(os.path.join(settings.SCREENSHOT_DIRECTORY, file))
Expand Down
Loading

0 comments on commit 78ef72a

Please sign in to comment.