Skip to content

Commit

Permalink
Test fix for new groups columns
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed May 23, 2023
1 parent 6c6798f commit 863eb59
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
10 changes: 9 additions & 1 deletion mapswipe_workers/mapswipe_workers/project_types/base/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,15 @@ def save_to_postgres(self, project, groups, groupsOfTasks):
"""

query_insert_raw_groups = """
INSERT INTO groups
INSERT INTO groups (
project_id,
group_id,
number_of_tasks,
finished_count,
required_count,
progress,
project_type_specifics
)
SELECT
project_id,
group_id,
Expand Down
21 changes: 17 additions & 4 deletions mapswipe_workers/tests/integration/set_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import os
import time
from typing import List, Union

from mapswipe_workers import auth

Expand All @@ -32,7 +33,7 @@ def set_firebase_test_data(


def set_postgres_test_data(
project_type: str, data_type: str, fixture_name: str
project_type: str, data_type: str, fixture_name: str, columns: Union[None, List[str]] = None
) -> None:
test_dir = os.path.dirname(__file__)
fixture_name = fixture_name + ".csv"
Expand All @@ -41,7 +42,7 @@ def set_postgres_test_data(
)
pg_db = auth.postgresDB()
with open(file_path) as test_file:
pg_db.copy_from(test_file, data_type)
pg_db.copy_from(test_file, data_type, columns=columns)


def create_test_project(
Expand All @@ -50,9 +51,21 @@ def create_test_project(
"""Create a test data in Firebase and Posgres."""
project_id = "test_{0}".format(fixture_name)

for data_type in ["projects", "groups", "tasks"]:
for data_type, columns in [
("projects", None),
("groups", [
"project_id",
"group_id",
"number_of_tasks",
"finished_count",
"required_count",
"progress",
"project_type_specifics",
]),
("tasks", None),
]:
set_firebase_test_data(project_type, data_type, fixture_name, project_id)
set_postgres_test_data(project_type, data_type, fixture_name)
set_postgres_test_data(project_type, data_type, fixture_name, columns=columns)

if results:
set_firebase_test_data(project_type, "users", "user", project_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ def setUp(self):
fixture_name = "build_area_sandoa"
self.project_id = "-NFNr55R_LYJvxP7wmte"

for data_type in [
"projects",
"groups",
"tasks",
"users",
"mapping_sessions",
"mapping_sessions_results",
for data_type, columns in [
("projects", None),
("groups", [
"project_id",
"group_id",
"number_of_tasks",
"finished_count",
"required_count",
"progress",
"project_type_specifics",
]),
("tasks", None),
("users", None),
("mapping_sessions", None),
("mapping_sessions_results", None),
]:
set_up.set_postgres_test_data(project_type, data_type, fixture_name)
set_up.set_postgres_test_data(project_type, data_type, fixture_name, columns=columns)

self.results_filename = os.path.join(
tempfile._get_default_tempdir(), f"results_{self.project_id}.csv.gz"
Expand Down
24 changes: 16 additions & 8 deletions mapswipe_workers/tests/integration/test_user_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ def setUp(self):
fixture_name = "osm_validation_malawi"
self.project_id = "-NEaU7GXxWRqKaFUYp_2"

for data_type in [
"projects",
"groups",
"tasks",
"users",
"mapping_sessions",
"mapping_sessions_results",
for data_type, columns in [
("projects", None),
("groups", [
"project_id",
"group_id",
"number_of_tasks",
"finished_count",
"required_count",
"progress",
"project_type_specifics",
]),
("tasks", None),
("users", None),
("mapping_sessions", None),
("mapping_sessions_results", None),
]:
set_up.set_postgres_test_data(project_type, data_type, fixture_name)
set_up.set_postgres_test_data(project_type, data_type, fixture_name, columns=columns)

self.results_filename = os.path.join(
tempfile._get_default_tempdir(), f"results_{self.project_id}.csv.gz"
Expand Down

0 comments on commit 863eb59

Please sign in to comment.