Skip to content

Commit

Permalink
Merge pull request #223 from DemocracyDevelopers/Demo1-AddAssertionGe…
Browse files Browse the repository at this point in the history
…neration

Demo1 add assertion generation
  • Loading branch information
vteague authored Nov 22, 2024
2 parents 2ee014c + 4e664d9 commit 3f06c07
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.restassured.path.json.JsonPath;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
Expand All @@ -41,26 +40,16 @@
/**
* A demonstration workflow that uploads CVRs and ballot manifests for all 64 counties.
* At the moment, this seems to run fine if run alone, but not to run in parallel with
* EstimateSamplesVaryingManifests, or in * github actions. Hence currently disabled.
* EstimateSamplesVaryingManifests.
*/
@Test(enabled=true)
public class Demo1 extends Workflow {

/**
* Path for all the data files.
*/
private static final String dataPath = "src/test/resources/CSVs/";

/**
* Class-wide logger
*/
private static final Logger LOGGER = LogManager.getLogger(Demo1.class);

/**
* Container for the mock-up database.
*/
private final static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* Database init.
*/
Expand Down Expand Up @@ -149,15 +138,16 @@ public void runDemo1() throws InterruptedException {
assertEquals(dashboard.get(ASM_STATE), PARTIAL_AUDIT_INFO_SET.toString());

// 4. Generate assertions; sanity check
// TODO this is commented out for now while we figure out how to run the raire-service in the Docker container.
// generateAssertions(1);
// dashboard = getDoSDashBoardRefreshResponse();
generateAssertions("SQL/demo1-assertions.sql", 1);
dashboard = getDoSDashBoardRefreshResponse();

// There should be 4 IRV contests.
// assertEquals(4, dashboard.getList("generate_assertions_summaries").size());
assertEquals(4, dashboard.getList("generate_assertions_summaries").size());

// 5. Choose targeted contests for audit.
// For now, just target plurality contests.
targetContests(Map.of("City of Longmont - Mayor","COUNTY_WIDE_CONTEST"));
targetContests(Map.of("City of Longmont - Mayor","COUNTY_WIDE_CONTEST",
"Byron Mayoral", "STATE_WIDE_CONTEST",
"Kempsey Mayoral", "COUNTY_WIDE_CONTEST"));

// 6. Set the seed.
setSeed(defaultSeed);
Expand All @@ -171,7 +161,7 @@ public void runDemo1() throws InterruptedException {
Map<String, EstimateSampleSizes.EstimateData> sampleSizes = getSampleSizeEstimates();
assertFalse(sampleSizes.isEmpty());

// TODO get assertions, sanity check, but first get the raire-service working (see above).
// TODO Sanity check of assertions and sample size estimates.

LOGGER.debug("Successfully completed Demo1.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.http.HttpStatus;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testcontainers.jdbc.JdbcDatabaseDelegate;
import org.testng.annotations.BeforeClass;
import us.freeandfair.corla.model.UploadedFile;
import wiremock.net.minidev.json.JSONArray;
Expand Down Expand Up @@ -80,11 +83,21 @@ public class Workflow extends TestClassWithDatabase {
*/
private static final Logger LOGGER = LogManager.getLogger(Workflow.class);

/**
* Container for the mock-up database.
*/
protected final static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* Path for storing temporary config files
*/
private static final String tempConfigPath = "src/test/workflows/temp/";

/**
* Path for all the data files.
*/
protected static final String dataPath = "src/test/resources/CSVs/";

/**
* Strings for colorado-rla JSON structures.
*/
Expand Down Expand Up @@ -366,23 +379,31 @@ protected boolean uploadSuccessfulWithin(int timeAllowedSeconds, final Set<Integ
}

/**
* Generate assertions (for IRV contests)
* TODO At the moment this expects the raire-service to be running, which is a problem because it will be reading the
* Generate assertions (for IRV contests). At the moment, rather than call raire-service, we
* are mocking that functionality. To do so, we take the path to a file containing SQL insert
* statements for all assertion related content that would have been created by the raire-service,
* and inserted into the database, and insert it into the database here.
* TODO Replace this with a call to the raire-service. Currently problematic because it will be
* reading the wrong database.
* See <a href="https://github.com/DemocracyDevelopers/colorado-rla/issues/218">...</a>
* wrong database.
* Set it up so that we run raire-service inside the Docker container and tell main where to find it.
*/
protected void generateAssertions(final double timeLimitSeconds) {
protected void generateAssertions(final String sqlPath, final double timeLimitSeconds)
{
final var containerDelegate = new JdbcDatabaseDelegate(postgres, "");
ScriptUtils.runInitScript(containerDelegate, sqlPath);

// Version that connects to raire-service below:
// Login as state admin.
final SessionFilter filter = doLogin("stateadmin1");

given()
.filter(filter)
.header("Content-Type", "application/x-www-form-urlencoded")
.get("/generate-assertions?timeLimitSeconds="+timeLimitSeconds)
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);
//final SessionFilter filter = doLogin("stateadmin1");

//given()
// .filter(filter)
// .header("Content-Type", "application/x-www-form-urlencoded")
// .get("/generate-assertions?timeLimitSeconds="+timeLimitSeconds)
// .then()
// .assertThat()
// .statusCode(HttpStatus.SC_OK);
}

protected void startAuditRound() {
Expand Down
Loading

0 comments on commit 3f06c07

Please sign in to comment.