Skip to content

Commit 60932e4

Browse files
Mr-Leshiyjmgilman
andauthored
feat: Update Review's importer, remove allocation step | NPG-8040 (#545)
# Description - Removed allocation step from review's importer, it will be moved as a separate tool later - Setup test in Earthly --------- Co-authored-by: Joshua Gilman <[email protected]>
1 parent d9a8e73 commit 60932e4

File tree

8 files changed

+61
-39
lines changed

8 files changed

+61
-39
lines changed

.github/workflows/ci-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ jobs:
3131
username: ${{ github.actor }}
3232
password: ${{ secrets.GITHUB_TOKEN }}
3333
- name: Run tests
34+
env:
35+
EARTHLY_SECRETS: "IDEASCALE_EMAIL=${{ secrets.IDEASCALE_EMAIL }}, IDEASCALE_PASSWORD=${{ secrets.IDEASCALE_PASSWORD }}, IDEASCALE_API_TOKEN=${{ secrets.IDEASCALE_API_TOKEN }}"
3436
run: |
3537
earthly -P --remote-cache=ghcr.io/${{ github.repository }}:cache +test

Earthfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ ci:
123123
test:
124124
BUILD ./src/event-db+test
125125
BUILD ./src/cat-data-service+test
126+
BUILD ./utilities/ideascale-importer+test
126127

127128
tag-workspace:
128129
ARG SVU_VERSION=1.10.2

utilities/ideascale-importer/Earthfile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ docker:
7373
SAVE IMAGE --push ${registry}ideascale-importer:$tag
7474

7575
# Run tests
76-
pytest:
76+
test:
7777
FROM +build
78-
RUN poetry run pytest -v --doctest-modules
78+
79+
COPY ../../src/event-db+docker-compose/docker-compose.yml docker-compose.yml
80+
WITH DOCKER \
81+
--compose docker-compose.yml \
82+
--pull postgres:14 \
83+
--load migrations:latest=(../../containers/event-db-migrations+docker --data=test) \
84+
--service migrations \
85+
--allow-privileged
86+
RUN --no-cache \
87+
--secret IDEASCALE_EMAIL \
88+
--secret IDEASCALE_PASSWORD \
89+
--secret IDEASCALE_API_TOKEN \
90+
EVENTDB_URL="postgres://catalyst-event-dev:CHANGE_ME@localhost/CatalystEventDev" \
91+
IDEASCALE_API_URL="https://temp-cardano-sandbox.ideascale.com" \
92+
poetry run pytest
93+
END

utilities/ideascale-importer/ideascale_importer/cli/reviews.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def import_reviews(
4040
envvar="IDEASCALE_API_TOKEN",
4141
help="IdeaScale API token"
4242
),
43-
pa_path: str = typer.Option(
43+
allocations_path: str = typer.Option(
4444
...,
45-
help="PAs file"
45+
help="allocations file"
4646
),
4747
output_path: str = typer.Option(
4848
...,
@@ -70,7 +70,7 @@ async def inner():
7070
password=password,
7171
api_token=api_token,
7272
event_id=event_id,
73-
pa_path=pa_path,
73+
allocations_path=allocations_path,
7474
output_path=output_path
7575
)
7676

utilities/ideascale-importer/ideascale_importer/reviews_importer/importer.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ async def login(self, email, password):
2929
'rememberMe': 'true',
3030
}
3131

32-
await self.inner.post(f"{login}", data=data)
32+
res = await self.inner.post(f"{login}", data=data)
3333

3434
async def download_reviews(self, reviews_path, review_stage_ids):
3535
async def download_file(self, review_stage_id):
3636
export_endpoint = "/a/admin/workflow/survey-tools/assessment/report/statistic/export/assessment-details/"
3737
file_name = f"{reviews_path}/{review_stage_id}.xlsx"
3838

39-
content = await self.inner.get(f"{export_endpoint}{review_stage_id}")
39+
content = await self.inner.get(f"{export_endpoint}{review_stage_id}")
4040
tree = html.fromstring(content)
4141

4242
# we are looking for '<div class="card panel export-result-progress" data-features="refresh-processing-item" data-processing-item-id="15622">'
@@ -70,7 +70,7 @@ def __init__(
7070
password,
7171
event_id,
7272
api_token,
73-
pa_path,
73+
allocations_path,
7474
output_path,
7575
):
7676
self.ideascale_url = ideascale_url
@@ -80,11 +80,10 @@ def __init__(
8080
self.event_id = event_id
8181
self.api_token = api_token
8282

83-
self.pa_path = pa_path
83+
self.allocations_path = allocations_path
8484
self.output_path = output_path
8585

8686
self.reviews_dir = tempfile.TemporaryDirectory()
87-
self.allocations_dir = tempfile.TemporaryDirectory()
8887

8988
self.frontend_client = None
9089
self.db = None
@@ -117,19 +116,20 @@ async def download_reviews(self):
117116

118117
self.reviews = await self.frontend_client.download_reviews(self.reviews_dir.name, self.config.review_stage_ids)
119118

120-
async def prepare_allocations(self):
121-
logger.info("Prepare allocations for proposal's reviews...")
122-
123-
self.allocations_path = await allocate(
124-
nr_allocations=self.config.nr_allocations,
125-
pas_path=self.pa_path,
126-
ideascale_api_key=self.api_token,
127-
ideascale_api_url=self.ideascale_url,
128-
stage_ids=self.config.stage_ids,
129-
challenges_group_id=self.config.campaign_group_id,
130-
group_id=self.config.group_id,
131-
output_path=self.allocations_dir.name,
132-
)
119+
# This code will be moved as a separate cli command
120+
# async def prepare_allocations(self):
121+
# logger.info("Prepare allocations for proposal's reviews...")
122+
123+
# self.allocations_path = await allocate(
124+
# nr_allocations=self.config.nr_allocations,
125+
# pas_path=self.pa_path,
126+
# ideascale_api_key=self.api_token,
127+
# ideascale_api_url=self.ideascale_url,
128+
# stage_ids=self.config.stage_ids,
129+
# challenges_group_id=self.config.campaign_group_id,
130+
# group_id=self.config.group_id,
131+
# output_path=self.output_path,
132+
# )
133133

134134
async def prepare_reviews(self):
135135
logger.info("Prepare proposal's reviews...")
@@ -155,12 +155,10 @@ async def run(self):
155155
await self.load_config()
156156

157157
await self.download_reviews()
158-
await self.prepare_allocations()
159158
await self.prepare_reviews()
160159

161160
async def close(self):
162161
self.reviews_dir.cleanup()
163-
self.allocations_dir.cleanup()
164162
await self.frontend_client.close()
165163

166164
class Config(pydantic.BaseModel):

utilities/ideascale-importer/ideascale_importer/tests/pa.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

utilities/ideascale-importer/ideascale_importer/tests/reviews_importer_test.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
import pytest
2-
import tempfile
2+
import os
33

44
from ideascale_importer.reviews_importer.importer import Importer
55

6-
@pytest.fixture
7-
def reviews_importer_mock():
8-
ideascale_url = "https://temp-cardano-sandbox.ideascale.com"
9-
database_url = "postgres://catalyst-event-dev:CHANGE_ME@localhost/CatalystEventDev"
10-
email = ""
11-
password = ""
6+
def get_env_var(env_var):
7+
if os.environ.get(env_var):
8+
return os.environ.get(env_var)
9+
else:
10+
raise Exception(f"could not find {env_var} env var")
11+
12+
@pytest.fixture(scope="session")
13+
def reviews_importer_mock(tmpdir_factory):
14+
ideascale_url = get_env_var("IDEASCALE_API_URL")
15+
database_url = get_env_var("EVENTDB_URL")
16+
email = get_env_var("IDEASCALE_EMAIL")
17+
password = get_env_var("IDEASCALE_PASSWORD")
1218
event_id = 0
13-
api_token = ""
14-
pa_path = "./pa.csv"
15-
output_path = tempfile.TemporaryDirectory()
19+
api_token = get_env_var("IDEASCALE_API_TOKEN")
20+
allocations_path = "./ideascale_importer/tests/test_data/allocations.csv"
21+
output_path = tmpdir_factory.mktemp("output")
1622
return Importer(
1723
ideascale_url=ideascale_url,
1824
database_url=database_url,
1925
email=email,
2026
password=password,
2127
api_token=api_token,
2228
event_id=event_id,
23-
pa_path=pa_path,
24-
output_path=output_path.name
29+
allocations_path=allocations_path,
30+
output_path=output_path
2531
)
2632

2733
@pytest.mark.asyncio
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pa_anon_id,pa_email,pa_level,proposal_id,proposal_url,proposal_title,proposal_challenge_id
2+
0,[email protected],0,109581,https://temp-cardano-sandbox.ideascale.com/c/idea/109581,Proposal 1,394

0 commit comments

Comments
 (0)