Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
test: TT-417 add test with customer id
  • Loading branch information
Jobzi committed Nov 25, 2021
commit 6376755a1e57a1ae7b0506ac33d27073b7347863
26 changes: 16 additions & 10 deletions V2/tests/api/azure/project_azure_endpoints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def _new_project(project: domain.Project, database: DB):


def test__project_azure_endpoint__returns_all_projects(
test_db, project_factory, insert_project
test_db, project_factory, insert_project, insert_customer, customer_factory
):
project_to_insert = [project_factory(), project_factory()]
inserted_customer = insert_customer(customer_factory(), test_db)
project_to_insert = [project_factory(customer_id=inserted_customer.id),
project_factory(customer_id=inserted_customer.id)]
inserted_projects = [
insert_project(project_to_insert[0], test_db).__dict__,
insert_project(project_to_insert[1], test_db).__dict__
Expand All @@ -39,9 +41,10 @@ def test__project_azure_endpoint__returns_all_projects(


def test__project_azure_endpoint__returns_an_project__when_project_matches_its_id(
test_db, project_factory, insert_project
test_db, project_factory, insert_project, insert_customer, customer_factory
):
project_to_insert = project_factory()
inserted_customer = insert_customer(customer_factory(), test_db)
project_to_insert = project_factory(customer_id=inserted_customer.id)
inserted_project = insert_project(project_to_insert, test_db).__dict__

req = func.HttpRequest(
Expand Down Expand Up @@ -74,9 +77,10 @@ def test__projects_azure_endpoint__returns_a_status_code_400__when_project_reciv


def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_an_project_matching_its_id_is_found(
test_db, project_factory, insert_project
test_db, project_factory, insert_project, insert_customer, customer_factory
):
project_to_insert = project_factory()
inserted_customer = insert_customer(customer_factory(), test_db)
project_to_insert = project_factory(customer_id=inserted_customer.id)
inserted_project = insert_project(project_to_insert, test_db).__dict__

req = func.HttpRequest(
Expand Down Expand Up @@ -110,9 +114,10 @@ def test__delete_projects_azure_endpoint__returns_a_status_code_400__when_projec


def test__update_project_azure_endpoint__returns_an_project__when_found_an_project_to_update(
test_db, project_factory, insert_project
test_db, project_factory, insert_project, insert_customer, customer_factory
):
project_to_insert = project_factory()
inserted_customer = insert_customer(customer_factory(), test_db)
project_to_insert = project_factory(customer_id=inserted_customer.id)
inserted_project = insert_project(project_to_insert, test_db).__dict__

project_body = {"description": Faker().sentence()}
Expand Down Expand Up @@ -147,9 +152,10 @@ def test__update_projects_azure_endpoint__returns_a_status_code_400__when_projec


def test__project_azure_endpoint__creates_an_project__when_project_has_all_attributes(
project_factory
test_db, project_factory, insert_customer, customer_factory
):
project_body = project_factory().__dict__
inserted_customer = insert_customer(customer_factory(), test_db)
project_body = project_factory(customer_id=inserted_customer.id).__dict__
body = json.dumps(project_body).encode("utf-8")
req = func.HttpRequest(
method='POST',
Expand Down
2 changes: 1 addition & 1 deletion V2/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# flake8: noqa
from fixtures import _activity_factory, _test_db, _insert_activity
from fixtures import _time_entry_factory
from fixtures import _customer_factory
from fixtures import _customer_factory, _insert_customer
from fixtures import _project_factory
12 changes: 12 additions & 0 deletions V2/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time_tracker.activities._infrastructure as activities_infrastructure
import time_tracker.time_entries._domain as time_entries_domain
import time_tracker.customers._domain as customers_domain
import time_tracker.customers._infrastructure as customers_infrastructure
import time_tracker.projects._domain as projects_domain
from time_tracker._infrastructure import DB

Expand Down Expand Up @@ -95,6 +96,8 @@ def _make_customer(
return customer

return _make_customer


@pytest.fixture(name='project_factory')
def _project_factory() -> projects_domain.Project:
def _make_project(
Expand All @@ -119,3 +122,12 @@ def _make_project(
)
return project
return _make_project


@pytest.fixture(name='insert_customer')
def _insert_customer() -> dict:
def _new_customer(activity: customers_domain.Customer, database: DB):
dao = customers_infrastructure.CustomersSQLDao(database)
new_activity = dao.create(activity)
return new_activity
return _new_customer
29 changes: 19 additions & 10 deletions V2/tests/integration/daos/projects_dao_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ def _clean_database():


def test__create_project__returns_a_project_dto__when_saves_correctly_with_sql_database(
create_fake_dao, project_factory
create_fake_dao, project_factory, insert_customer, customer_factory
):
dao = create_fake_dao
project_to_insert = project_factory()
inserted_customer = insert_customer(customer_factory(), dao.db)
project_to_insert = project_factory(customer_id=inserted_customer.id)

inserted_project = dao.create(project_to_insert)

Expand All @@ -36,10 +37,12 @@ def test__create_project__returns_a_project_dto__when_saves_correctly_with_sql_d


def test_update__returns_an_update_project__when_an_project_matching_its_id_is_found_with_sql_database(
create_fake_dao, project_factory
create_fake_dao, project_factory, insert_customer, customer_factory
):
dao = create_fake_dao
project_to_insert = project_factory()
inserted_customer = insert_customer(customer_factory(), dao.db)
project_to_insert = project_factory(customer_id=inserted_customer.id)

inserted_project = dao.create(project_to_insert)

expected_description = Faker().sentence()
Expand All @@ -62,10 +65,13 @@ def test_update__returns_none__when_no_project_matching_its_id_is_found_with_sql


def test__get_all__returns_a_list_of_project_dto_objects__when_one_or_more_projects_are_found_with_sql_database(
create_fake_dao, project_factory
create_fake_dao, project_factory, insert_customer, customer_factory
):
dao = create_fake_dao
project_to_inserts = [project_factory(), project_factory()]
inserted_customer = insert_customer(customer_factory(), dao.db)
project_to_inserts = [project_factory(customer_id=inserted_customer.id),
project_factory(customer_id=inserted_customer.id)]

inserted_projects = [
dao.create(project_to_inserts[0]),
dao.create(project_to_inserts[1])
Expand All @@ -77,10 +83,12 @@ def test__get_all__returns_a_list_of_project_dto_objects__when_one_or_more_proje


def test_get_by_id__returns_an_project_dto__when_found_one_project_that_matches_its_id_with_sql_database(
create_fake_dao, project_factory
create_fake_dao, project_factory, insert_customer, customer_factory
):
dao = create_fake_dao
project_to_insert = project_factory()
inserted_customer = insert_customer(customer_factory(), dao.db)
project_to_insert = project_factory(customer_id=inserted_customer.id)

inserted_project = dao.create(project_to_insert)

project = dao.get_by_id(inserted_project.id)
Expand Down Expand Up @@ -111,10 +119,11 @@ def test_get_all__returns_an_empty_list__when_doesnt_found_any_projects_with_sql


def test_delete__returns_an_project_with_inactive_status__when_an_project_matching_its_id_is_found_with_sql_database(
create_fake_dao, project_factory
create_fake_dao, project_factory, insert_customer, customer_factory
):
dao = create_fake_dao
project_to_insert = project_factory()
inserted_customer = insert_customer(customer_factory(), dao.db)
project_to_insert = project_factory(customer_id=inserted_customer.id)
inserted_project = dao.create(project_to_insert)

project = dao.delete(inserted_project.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, database: _db.DB):
sq.Column('name', sq.String),
sq.Column('description', sq.String),
sq.Column('project_type_id', sq.Integer),
sq.Column('customer_id', sq.Integer),
sq.Column('customer_id', sq.Integer, sq.ForeignKey('customer.id')),
sq.Column('status', sq.SmallInteger),
sq.Column('deleted', sq.BOOLEAN),
sq.Column(
Expand All @@ -39,7 +39,7 @@ def create(self, project_data: domain.Project) -> domain.Project:
new_project.update({"id": project.inserted_primary_key[0]})
return self.__create_project_dto(new_project)

except sq.exc.sqError:
except sq.exc.SQLAlchemyError:
return None

def get_by_id(self, id: int) -> domain.Project:
Expand Down