Skip to content

Commit ecaa4a1

Browse files
author
Alex Meadows
committed
process_tracker_python-84 Add contact to process relationship
✨ Added Contact Process relationship ProcessContact relationship added. Added to the finder for obtaining contacts. Closes #84
1 parent beb7f06 commit ecaa4a1

File tree

5 files changed

+100
-9
lines changed

5 files changed

+100
-9
lines changed

dbscripts/mysql_process_tracker.sql

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,26 @@ create table source_lkup
144144
unique (source_name)
145145
);
146146

147-
create table process_tracker.source_contact
147+
create table source_contact
148148
(
149149
source_id int not null,
150150
contact_id int not null,
151151
primary key (source_id, contact_id),
152152
constraint source_contact_fk01
153-
foreign key (source_id) references process_tracker.source_lkup (source_id),
153+
foreign key (source_id) references source_lkup (source_id),
154154
constraint source_contact_fk02
155-
foreign key (contact_id) references process_tracker.contact_lkup (contact_id)
155+
foreign key (contact_id) references contact_lkup (contact_id)
156+
);
157+
158+
create table process_contact
159+
(
160+
process_id int not null,
161+
contact_id int not null,
162+
primary key (process_id, contact_id),
163+
constraint process_contact_fk01
164+
foreign key (process_id) references process (process_id),
165+
constraint process_contact_fk02
166+
foreign key (contact_id) references contact_lkup (contact_id)
156167
);
157168

158169
create table system_lkup

dbscripts/postgresql_process_tracker.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ create table process_tracker.source_contact
122122

123123
alter table process_tracker.source_contact owner to pt_admin;
124124

125+
create table process_tracker.process_contact
126+
(
127+
process_id integer not null
128+
constraint process_contact_fk01
129+
references process_tracker.process,
130+
contact_id integer not null
131+
constraint process_contact_fk02
132+
references process_tracker.contact_lkup,
133+
constraint process_contact_pk
134+
primary key (process_id, contact_id)
135+
);
136+
137+
alter table process_tracker.process_contact owner to pt_admin;
138+
125139
create table process_status_lkup
126140
(
127141
process_status_id serial not null

process_tracker/models/process.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,37 @@ def __repr__(self):
164164
)
165165

166166

167+
class ProcessContact(Base):
168+
169+
__tablename__ = "process_contact"
170+
__table_args__ = {"schema": "process_tracker"}
171+
172+
process_id = Column(
173+
Integer,
174+
ForeignKey("process_tracker.process.process_id"),
175+
primary_key=True,
176+
nullable=False,
177+
)
178+
contact_id = Column(
179+
Integer,
180+
ForeignKey("process_tracker.contact_lkup.contact_id"),
181+
primary_key=True,
182+
nullable=False,
183+
)
184+
185+
UniqueConstraint(process_id, contact_id)
186+
187+
processes = relationship("Process")
188+
contacts = relationship("Contact")
189+
190+
def __repr__(self):
191+
192+
return "<ProcessContact process=%s, contact=%s>" % (
193+
self.process_id,
194+
self.contact_id,
195+
)
196+
197+
167198
class ProcessDatasetType(Base):
168199

169200
__tablename__ = "process_dataset_type"

process_tracker/process_tracker.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
ErrorTracking,
2828
ErrorType,
2929
Process,
30+
ProcessContact,
3031
ProcessDatasetType,
3132
ProcessDependency,
3233
ProcessTracking,
@@ -417,8 +418,7 @@ def find_process_contacts(self, process):
417418
.join(Source)
418419
.join(ProcessSource)
419420
.join(Process)
420-
.join(ProcessTracking)
421-
.filter(ProcessTracking.process_id == process)
421+
.filter(Process.process_id == process)
422422
)
423423

424424
for contact in result:
@@ -430,6 +430,22 @@ def find_process_contacts(self, process):
430430
}
431431
)
432432

433+
result = (
434+
self.session.query(Contact.contact_name, Contact.contact_email)
435+
.join(ProcessContact)
436+
.join(Process)
437+
.filter(Process.process_id == process)
438+
)
439+
440+
for contact in result:
441+
contacts.append(
442+
{
443+
"contact_name": contact.contact_name,
444+
"contact_email": contact.contact_email,
445+
"contact_type": "process",
446+
}
447+
)
448+
433449
return contacts
434450

435451
def get_latest_tracking_record(self, process):

tests/test_process_tracker.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ErrorType,
2626
ErrorTracking,
2727
Process,
28+
ProcessContact,
2829
ProcessDatasetType,
2930
ProcessDependency,
3031
ProcessSource,
@@ -67,6 +68,7 @@ def setUpClass(cls):
6768
@classmethod
6869
def tearDownClass(cls):
6970
cls.session.query(ClusterProcess).delete()
71+
cls.session.query(ProcessContact).delete()
7072
cls.session.query(Location).delete()
7173
cls.session.query(DatasetType).delete()
7274
cls.session.query(ProcessSourceObject).delete()
@@ -661,21 +663,33 @@ def test_find_extracts_by_process_not_descending(self):
661663

662664
def test_find_process_contacts(self):
663665
"""
664-
Testing that when passed a process_id, a list of source contacts will be returned.
666+
Testing that when passed a process_id, a list of source and process contacts will be returned.
665667
:return:
666668
"""
667-
contact = DataStore().get_or_create_item(
669+
source_contact = DataStore().get_or_create_item(
668670
model=Contact,
669671
contact_name="Test Contact",
670672
contact_email="testcontact@test.com",
671673
)
672674

675+
process_contact = DataStore().get_or_create_item(
676+
model=Contact,
677+
contact_name="Process Contact",
678+
contact_email="processcontact@test.com",
679+
)
680+
673681
source = DataStore().get_or_create_item(model=Source, source_name="Unittests")
674682

675683
DataStore().get_or_create_item(
676684
model=SourceContact,
677685
source_id=source.source_id,
678-
contact_id=contact.contact_id,
686+
contact_id=source_contact.contact_id,
687+
)
688+
689+
DataStore().get_or_create_item(
690+
model=ProcessContact,
691+
process_id=self.process_id,
692+
contact_id=process_contact.contact_id,
679693
)
680694

681695
given_result = self.process_tracker.find_process_contacts(
@@ -687,7 +701,12 @@ def test_find_process_contacts(self):
687701
"contact_name": "Test Contact",
688702
"contact_email": "testcontact@test.com",
689703
"contact_type": "source",
690-
}
704+
},
705+
{
706+
"contact_name": "Process Contact",
707+
"contact_email": "processcontact@test.com",
708+
"contact_type": "process",
709+
},
691710
]
692711

693712
self.assertEqual(expected_result, given_result)

0 commit comments

Comments
 (0)