Skip to content

Commit 3d0cc52

Browse files
author
Alex Meadows
committed
process_tracker_python-90 Add contact information to data source
✨ Added Contact
1 parent abdc5d0 commit 3d0cc52

File tree

5 files changed

+126
-1
lines changed

5 files changed

+126
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,4 @@ pip-selfcheck.json
175175
.idea/process_tracker_python.iml
176176
/tests/s3:/
177177
/tests/s3:\/
178+
/.idea/inspectionProfiles/

dbscripts/mysql_process_tracker.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
USE process_tracker;
22

3+
create table contact_lkup
4+
(
5+
contact_id int auto_increment
6+
primary key,
7+
contact_name varchar(250) not null,
8+
contact_email varchar(750) null,
9+
constraint contact_lkup_contact_email_uindex
10+
unique (contact_email),
11+
constraint contact_lkup_contact_name_uindex
12+
unique (contact_name)
13+
);
14+
315
create table dataset_type_lkup
416
(
517
dataset_type_id int auto_increment,
@@ -132,6 +144,17 @@ create table source_lkup
132144
unique (source_name)
133145
);
134146

147+
create table process_tracker.source_contact
148+
(
149+
source_id int not null,
150+
contact_id int not null,
151+
primary key (source_id, contact_id),
152+
constraint source_contact_fk01
153+
foreign key (source_id) references process_tracker.source_lkup (source_id),
154+
constraint source_contact_fk02
155+
foreign key (contact_id) references process_tracker.contact_lkup (contact_id)
156+
);
157+
135158
create table system_lkup
136159
(
137160
system_id int auto_increment

dbscripts/postgresql_process_tracker.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ create schema process_tracker;
44

55
alter schema process_tracker owner to pt_admin;
66

7+
create table process_tracker.contact_lkup
8+
(
9+
contact_id serial not null
10+
constraint contact_lkup_pk
11+
primary key,
12+
contact_name varchar(250) not null,
13+
contact_email varchar(750)
14+
);
15+
16+
alter table process_tracker.contact_lkup owner to pt_admin;
17+
18+
create unique index contact_lkup_contact_email_uindex
19+
on process_tracker.contact_lkup (contact_email);
20+
21+
create unique index contact_lkup_contact_name_uindex
22+
on process_tracker.contact_lkup (contact_name);
23+
724
create table process_tracker.dataset_type_lkup
825
(
926
dataset_type_id serial not null
@@ -91,6 +108,20 @@ alter table source_lkup owner to pt_admin;
91108
create unique index source_lkup_udx01
92109
on source_lkup (source_name);
93110

111+
create table process_tracker.source_contact
112+
(
113+
source_id integer not null
114+
constraint source_contact_fk01
115+
references process_tracker.source_lkup,
116+
contact_id integer not null
117+
constraint source_contact_fk02
118+
references process_tracker.contact_lkup,
119+
constraint source_contact_pk
120+
primary key (source_id, contact_id)
121+
);
122+
123+
alter table process_tracker.source_contact owner to pt_admin;
124+
94125
create table process_status_lkup
95126
(
96127
process_status_id serial not null

process_tracker/process_tracker.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from process_tracker.utilities import utilities
1717

1818
from process_tracker.models.actor import Actor
19+
from process_tracker.models.contact import Contact
1920
from process_tracker.models.extract import (
2021
Extract,
2122
ExtractProcess,
@@ -39,6 +40,7 @@
3940
from process_tracker.models.source import (
4041
DatasetType,
4142
Source,
43+
SourceContact,
4244
SourceDatasetType,
4345
SourceObject,
4446
SourceObjectDatasetType,
@@ -399,6 +401,37 @@ def find_extracts_by_process(self, extract_process_name, status="ready"):
399401

400402
return process_files
401403

404+
def find_process_contacts(self, process):
405+
"""
406+
Based on the process, find the process' contacts as well as the contacts for any sources used and return them
407+
as a list.
408+
:param process: The process' process_id
409+
:type process: int
410+
:return:
411+
"""
412+
contacts = list()
413+
414+
result = (
415+
self.session.query(Contact.contact_name, Contact.contact_email)
416+
.join(SourceContact)
417+
.join(Source)
418+
.join(ProcessSource)
419+
.join(Process)
420+
.join(ProcessTracking)
421+
.filter(ProcessTracking.process_id == process)
422+
)
423+
424+
for contact in result:
425+
contacts.append(
426+
{
427+
"contact_name": contact.contact_name,
428+
"contact_email": contact.contact_email,
429+
"contact_type": "source",
430+
}
431+
)
432+
433+
return contacts
434+
402435
def get_latest_tracking_record(self, process):
403436
"""
404437
For the given process, find the latest tracking record.

tests/test_process_tracker.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from moto import mock_s3
1414
from sqlalchemy.orm import aliased, Session
1515

16+
from process_tracker.models.contact import Contact
1617
from process_tracker.models.extract import (
1718
Extract,
1819
ExtractDatasetType,
@@ -35,19 +36,21 @@
3536
from process_tracker.models.source import (
3637
DatasetType,
3738
Source,
39+
SourceContact,
3840
SourceDatasetType,
3941
SourceObject,
4042
SourceObjectDatasetType,
4143
)
4244

43-
from process_tracker.utilities.data_store import DataStore
45+
from process_tracker.utilities.data_store import DataStore, ClusterProcess
4446
from process_tracker.extract_tracker import ExtractTracker
4547
from process_tracker.process_tracker import ProcessTracker
4648
from process_tracker.utilities import utilities
4749

4850
test_bucket = "test_bucket"
4951

5052

53+
5154
# @mock_s3
5255
class TestProcessTracker(unittest.TestCase):
5356
@classmethod
@@ -64,6 +67,7 @@ def setUpClass(cls):
6467

6568
@classmethod
6669
def tearDownClass(cls):
70+
cls.session.query(ClusterProcess).delete()
6771
cls.session.query(Location).delete()
6872
cls.session.query(DatasetType).delete()
6973
cls.session.query(ProcessSourceObject).delete()
@@ -656,6 +660,39 @@ def test_find_extracts_by_process_not_descending(self):
656660

657661
self.assertNotEqual(expected_result, given_result)
658662

663+
def test_find_process_contacts(self):
664+
"""
665+
Testing that when passed a process_id, a list of source contacts will be returned.
666+
:return:
667+
"""
668+
contact = DataStore().get_or_create_item(
669+
model=Contact,
670+
contact_name="Test Contact",
671+
contact_email="testcontact@test.com",
672+
)
673+
674+
source = DataStore().get_or_create_item(model=Source, source_name="Unittests")
675+
676+
DataStore().get_or_create_item(
677+
model=SourceContact,
678+
source_id=source.source_id,
679+
contact_id=contact.contact_id,
680+
)
681+
682+
given_result = self.process_tracker.find_process_contacts(
683+
process=self.process_id
684+
)
685+
686+
expected_result = [
687+
{
688+
"contact_name": "Test Contact",
689+
"contact_email": "testcontact@test.com",
690+
"contact_type": "source",
691+
}
692+
]
693+
694+
self.assertEqual(expected_result, given_result)
695+
659696
def test_initializing_process_tracking(self):
660697
"""
661698
Testing that when ProcessTracking is initialized, the necessary objects are created.

0 commit comments

Comments
 (0)