Skip to content

Commit

Permalink
fix verification service and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wesjdj committed Jan 22, 2024
1 parent 319cc9e commit b0404cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
3 changes: 0 additions & 3 deletions verification_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def check_user_verification(email, verified_users_file):


def get_user_email_address(event_type, event_data):
event_data = json.loads(event_data)
if event_type in [e.value for e in ProjectEvent]:
return event_data.get("owner_email")

Expand Down Expand Up @@ -181,9 +180,7 @@ def process_event(self, event_type, data):
)
max_access_level = 0
user_id_with_max_access = None
data = json.loads(data)
group_id = data.get("group_id")
data = json.dumps(data)

# Get all members of the group
response = requests.get(
Expand Down
31 changes: 19 additions & 12 deletions verification_service/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_process_events(self):
# load json data from file
with open(f"test/json_data/{event_type}.json", "r") as file:
data = json.load(file)
json_data[event_type] = json.dumps(data)
json_data[event_type] = data

# true cases, i.e. not verified
test_cases.append(
Expand All @@ -75,10 +75,12 @@ def test_process_events(self):
# false cases, i.e. verified domains / users
if event_type == GroupEvent.GROUP_CREATE.value:
for group_id in ["2", "3"]:
modified_json_data = json_data[event_type].copy()
modified_json_data['group_id'] = group_id
test_cases.append(
(
GroupEvent.GROUP_CREATE.value,
json_data[event_type].replace("1", group_id),
modified_json_data,
False,
)
)
Expand All @@ -103,10 +105,12 @@ def test_process_events(self):

elif event_type == GroupEvent.GROUP_RENAME.value:
for group_id in ["6", "7"]:
modified_json_data = json_data[event_type].copy()
modified_json_data['group_id'] = group_id
test_cases.append(
(
GroupEvent.GROUP_RENAME.value,
json_data[event_type].replace("5", group_id),
modified_json_data,
False,
)
)
Expand All @@ -130,15 +134,18 @@ def test_process_events(self):

else:
for replacement in email_replacements:
test_cases.append(
(
event_type,
json_data[event_type].replace(
"non-verified-user@non-verified-domain.com", replacement
),
False,
modified_json_data = json_data[event_type].copy()
if 'email' in modified_json_data:
modified_json_data['email'] = modified_json_data['email'].replace(
"non-verified-user@non-verified-domain.com", replacement
)
)
test_cases.append((event_type, modified_json_data, False))
elif 'owner_email' in modified_json_data:
modified_json_data['owner_email'] = modified_json_data['owner_email'].replace(
"non-verified-user@non-verified-domain.com", replacement
)
test_cases.append((event_type, modified_json_data, False))


# Test case for snippet check
# load json data from file
Expand Down Expand Up @@ -216,7 +223,7 @@ def test_process_events(self):
print(f"Message in output stream arrived: {decoded_key}")

self.assertIsNotNone(decoded_value)
self.assertIn(event_data, decoded_value)
self.assertEqual(event_data, decoded_value)

print("Clearing all messages from output stream")
self.redis_mock.xtrim('verification', maxlen=0)
Expand Down

0 comments on commit b0404cd

Please sign in to comment.