Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into selenium/targeting…
Browse files Browse the repository at this point in the history
…_tests

# Conflicts:
#	backend/selenium_tests/conftest.py
  • Loading branch information
szymon-kellton committed Jul 9, 2024
2 parents daa187a + 46d5ff1 commit 0127a19
Show file tree
Hide file tree
Showing 19 changed files with 955 additions and 30 deletions.
1 change: 1 addition & 0 deletions backend/hct_mis_api/apps/household/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class Meta:
django_get_or_create = ("key",)

key = factory.fuzzy.FuzzyChoice([value.lower() for value, _ in IDENTIFICATION_TYPE_CHOICE])
label = factory.LazyAttribute(lambda o: o.key.replace("_", " ").title())


class DocumentFactory(DjangoModelFactory):
Expand Down
134 changes: 134 additions & 0 deletions backend/selenium_tests/accountability/test_surveys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
from django.db import transaction

import pytest
from helpers.fixtures import get_program_with_dct_type_and_name
from page_object.accountability.surveys import AccountabilitySurveys
from 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
from hct_mis_api.apps.accountability.models import Survey
from hct_mis_api.apps.core.models import BusinessArea, DataCollectingType
from hct_mis_api.apps.household.fixtures import create_household_and_individuals
from hct_mis_api.apps.household.models import REFUGEE, Household
from hct_mis_api.apps.program.models import Program
from hct_mis_api.apps.targeting.fixtures import (
TargetingCriteriaFactory,
TargetPopulationFactory,
)

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


@pytest.fixture
def test_program() -> Program:
return get_program_with_dct_type_and_name("Test Program", "NORM", DataCollectingType.Type.STANDARD)


@pytest.fixture
def add_household() -> Household:
program = Program.objects.first()
with transaction.atomic():
household, individuals = create_household_and_individuals(
household_data={"business_area": program.business_area, "program": program, "residence_status": REFUGEE},
individuals_data=[
{"business_area": program.business_area, "observed_disability": []},
],
)
return household


@pytest.fixture
def add_accountability_surveys_message() -> Survey:
targeting_criteria = TargetingCriteriaFactory()

target_population = TargetPopulationFactory(
created_by=User.objects.first(),
targeting_criteria=targeting_criteria,
business_area=BusinessArea.objects.first(),
)
return SurveyFactory(
title="Test survey",
category="MANUAL",
unicef_id="SUR-24-0005",
target_population=target_population,
created_by=User.objects.first(),
)


@pytest.mark.usefixtures("login")
class TestSmokeAccountabilitySurveys:
def test_smoke_accountability_surveys(
self,
test_program: Program,
add_accountability_surveys_message: Survey,
pageAccountabilitySurveys: AccountabilitySurveys,
) -> None:
pageAccountabilitySurveys.selectGlobalProgramFilter("Test Program").click()
pageAccountabilitySurveys.getNavAccountability().click()
pageAccountabilitySurveys.getNavSurveys().click()

assert "Surveys" in pageAccountabilitySurveys.getPageHeaderTitle().text
assert "NEW SURVEY" in pageAccountabilitySurveys.getButtonNewSurvey().text
assert "Search" in pageAccountabilitySurveys.getFiltersSearch().text
assert "Target Population" in pageAccountabilitySurveys.getTargetPopulationInput().text
assert "Created by" in pageAccountabilitySurveys.getFiltersCreatedByAutocomplete().text
assert "Created by" in pageAccountabilitySurveys.getCreatedByInput().text
assert "From" in pageAccountabilitySurveys.getFiltersCreationDateFrom().text
assert "To" in pageAccountabilitySurveys.getFiltersCreationDateTo().text
assert "CLEAR" in pageAccountabilitySurveys.getButtonFiltersClear().text
assert "APPLY" in pageAccountabilitySurveys.getButtonFiltersApply().text
assert "Surveys List" in pageAccountabilitySurveys.getTableTitle().text
assert "Survey ID" in pageAccountabilitySurveys.getTableLabel()[0].text
assert "Survey Title" in pageAccountabilitySurveys.getTableLabel()[1].text
assert "Category" in pageAccountabilitySurveys.getTableLabel()[2].text
assert "Number of Recipients" in pageAccountabilitySurveys.getTableLabel()[3].text
assert "Created by" in pageAccountabilitySurveys.getTableLabel()[4].text
assert "Creation Date" in pageAccountabilitySurveys.getTableLabel()[5].text
assert "10 1–1 of 1" in pageAccountabilitySurveys.getTablePagination().text.replace("\n", " ")
assert 1 == len(pageAccountabilitySurveys.getRows())
assert "SUR-24-0005" in pageAccountabilitySurveys.getRows()[0].text
assert "Test survey" in pageAccountabilitySurveys.getRows()[0].text

def test_smoke_accountability_surveys_details(
self,
test_program: Program,
add_accountability_surveys_message: Survey,
add_household: Household,
pageAccountabilitySurveys: AccountabilitySurveys,
pageAccountabilitySurveysDetails: AccountabilitySurveysDetails,
) -> None:
add_accountability_surveys_message.recipients.set([Household.objects.first()])
pageAccountabilitySurveys.selectGlobalProgramFilter("Test Program").click()
pageAccountabilitySurveys.getNavAccountability().click()
pageAccountabilitySurveys.getNavSurveys().click()
pageAccountabilitySurveys.getRows()[0].click()

assert "SUR-24-0005" in pageAccountabilitySurveysDetails.getPageHeaderTitle().text
assert "Survey with manual process" in pageAccountabilitySurveysDetails.getLabelCategory().text
assert "Test survey" in pageAccountabilitySurveysDetails.getLabelSurveyTitle().text
created_by = add_accountability_surveys_message.created_by
assert (
f"{created_by.first_name} {created_by.last_name}"
in pageAccountabilitySurveysDetails.getLabelCreatedBy().text
)
assert (
add_accountability_surveys_message.created_at.strftime("%-d %b %Y")
in pageAccountabilitySurveysDetails.getLabelDateCreated().text
)
assert "Test Program" in pageAccountabilitySurveysDetails.getLabelProgramme().text
assert "Household Id" in pageAccountabilitySurveysDetails.getHouseholdId().text
assert "Status" in pageAccountabilitySurveysDetails.getStatus().text
assert "Head of Household" in pageAccountabilitySurveysDetails.getHouseholdHeadName().text
assert "Household Size" in pageAccountabilitySurveysDetails.getHouseholdSize().text
assert "Administrative Level 2" in pageAccountabilitySurveysDetails.getHouseholdLocation().text
assert "Residence Status" in pageAccountabilitySurveysDetails.getHouseholdResidenceStatus().text
assert "Registration Date" in pageAccountabilitySurveysDetails.getHouseholdRegistrationDate().text
assert "Rows per page: 10 1–1 of 1" in pageAccountabilitySurveysDetails.getTablePagination().text.replace(
"\n", " "
)
assert 1 == len(pageAccountabilitySurveys.getRows())
assert (
add_accountability_surveys_message.recipients.all()[0].unicef_id
in pageAccountabilitySurveys.getRows()[0].text
)
86 changes: 79 additions & 7 deletions backend/selenium_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from page_object.accountability.comunication_details import (
AccountabilityCommunicationDetails,
)
from page_object.accountability.surveys import AccountabilitySurveys
from page_object.accountability.surveys_details import AccountabilitySurveysDetails
from page_object.admin_panel.admin_panel import AdminPanel
from page_object.country_dashboard.country_dashboard import CountryDashboard
from page_object.filters import Filters
Expand All @@ -33,6 +35,8 @@
from page_object.payment_verification.payment_verification_details import (
PaymentVerificationDetails,
)
from page_object.people.people import People
from page_object.people.people_details import PeopleDetails
from page_object.program_log.payment_log import ProgramLog
from page_object.programme_details.programme_details import ProgrammeDetails
from page_object.programme_management.programme_management import ProgrammeManagement
Expand Down Expand Up @@ -64,6 +68,8 @@
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 Down Expand Up @@ -253,6 +259,16 @@ def pageHouseholds(request: FixtureRequest, browser: Chrome) -> Households:
yield Households(browser)


@pytest.fixture
def pagePeople(request: FixtureRequest, browser: Chrome) -> People:
yield People(browser)


@pytest.fixture
def pagePeopleDetails(request: FixtureRequest, browser: Chrome) -> PeopleDetails:
yield PeopleDetails(browser)


@pytest.fixture
def pageHouseholdsDetails(request: FixtureRequest, browser: Chrome) -> HouseholdsDetails:
yield HouseholdsDetails(browser)
Expand Down Expand Up @@ -333,6 +349,16 @@ def pageNewPaymentPlan(request: FixtureRequest, browser: Chrome) -> NewPaymentPl
yield NewPaymentPlan(browser)


@pytest.fixture
def pageAccountabilitySurveys(request: FixtureRequest, browser: Chrome) -> AccountabilitySurveys:
yield AccountabilitySurveys(browser)


@pytest.fixture
def pageAccountabilitySurveysDetails(request: FixtureRequest, browser: Chrome) -> AccountabilitySurveysDetails:
yield AccountabilitySurveysDetails(browser)


@pytest.fixture
def pageProgrammeUsers(request: FixtureRequest, browser: Chrome) -> ProgrammeUsers:
yield ProgrammeUsers(browser)
Expand Down Expand Up @@ -419,7 +445,7 @@ def create_super_user(business_area: BusinessArea) -> User:
UserRole.objects.create(
user=user,
role=Role.objects.get(name="Role"),
business_area=BusinessArea.objects.get(name="Afghanistan"),
business_area=business_area,
)

for partner in Partner.objects.exclude(name="UNICEF"):
Expand All @@ -429,29 +455,75 @@ def create_super_user(business_area: BusinessArea) -> User:
assert user.is_superuser

dct_list = [
{"label": "Full", "code": "full", "description": "Full individual collected", "active": True},
{"label": "Size only", "code": "size_only", "description": "Size only collected", "active": True},
{"label": "WASH", "code": "wash", "description": "WASH", "active": True},
{"label": "Partial", "code": "partial", "description": "Partial individuals collected", "active": True},
{
"label": "Full",
"code": "full",
"description": "Full individual collected",
"active": True,
"type": DataCollectingType.Type.STANDARD,
},
{
"label": "Size only",
"code": "size_only",
"description": "Size only collected",
"active": True,
"type": DataCollectingType.Type.STANDARD,
},
{
"label": "WASH",
"code": "wash",
"description": "WASH",
"active": True,
"type": DataCollectingType.Type.STANDARD,
},
{
"label": "Partial",
"code": "partial",
"description": "Partial individuals collected",
"active": True,
"type": DataCollectingType.Type.STANDARD,
},
{
"label": "size/age/gender disaggregated",
"code": "size_age_gender_disaggregated",
"description": "No individual data",
"active": True,
"type": DataCollectingType.Type.STANDARD,
},
]

for dct in dct_list:
data_collecting_type = DataCollectingType.objects.create(
label=dct["label"], code=dct["code"], description=dct["description"], active=dct["active"]
label=dct["label"],
code=dct["code"],
description=dct["description"],
active=dct["active"],
type=dct["type"],
)
data_collecting_type.limit_to.add(business_area)
data_collecting_type.save()
ba_partner_through, _ = BusinessAreaPartnerThrough.objects.get_or_create(
business_area=business_area, partner=partner
)
ba_partner_through.roles.set([role])
yield user

# add document types
doc_type_keys = (
"birth_certificate",
"drivers_license",
"electoral_card",
"tax_id",
"residence_permit_no",
"bank_statement",
"disability_certificate",
"other_id",
"foster_child",
)
for key in doc_type_keys:
DocumentTypeFactory(key=key)
DocumentType.objects.update_or_create(key="national_id", pk="227fcbc0-297a-4d85-8390-7de189278321")
DocumentType.objects.update_or_create(key="national_passport", pk="012a3ecb-0d6e-440f-9c68-83e5bf1ccddf")
return user


# set up a hook to be able to check if a test has failed
Expand Down
1 change: 0 additions & 1 deletion backend/selenium_tests/grievance/feedback/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def add_feedbacks(django_db_setup: Generator[None, None, None], django_db_blocke
def add_households(django_db_setup: Generator[None, None, None], django_db_blocker: DjangoDbBlocker) -> None:
with django_db_blocker.unblock():
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/registration_data/fixtures/data-cypress.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/household/fixtures/documenttype.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/household/fixtures/data-cypress.json")
yield

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def add_grievance(django_db_setup: Generator[None, None, None], django_db_blocke
def add_households(django_db_setup: Generator[None, None, None], django_db_blocker: DjangoDbBlocker) -> None:
with django_db_blocker.unblock():
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/registration_data/fixtures/data-cypress.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/household/fixtures/documenttype.json")
call_command("loaddata", f"{settings.PROJECT_ROOT}/apps/household/fixtures/data-cypress.json")
yield

Expand Down
Loading

0 comments on commit 0127a19

Please sign in to comment.