mirror of
https://github.com/google/nomulus
synced 2026-09-20 06:54:43 +00:00
Add activity report generation code
This adds Bigquery API client code to generate the activity reports from our now standardSQL queries. The naming mirrors that of RDE (Staging generates the reports and uploads them to GCS). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=164656344
This commit is contained in:
@@ -16,6 +16,7 @@ package google.registry.reporting;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.reporting.IcannReportingModule.ReportType.ACTIVITY;
|
||||
import static google.registry.reporting.IcannReportingModule.ReportType.TRANSACTIONS;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.GcsTestingUtils.writeGcsFile;
|
||||
@@ -54,18 +55,18 @@ public class IcannReportingUploadActionTest {
|
||||
private final FakeResponse response = new FakeResponse();
|
||||
private final GcsService gcsService = GcsServiceFactory.createGcsService();
|
||||
private final GcsFilename reportFile =
|
||||
new GcsFilename("basin/icann/monthly", "test-transactions-201706.csv");
|
||||
new GcsFilename("basin/icann/monthly/2017-05", "test-transactions-201705.csv");
|
||||
|
||||
private IcannReportingUploadAction createAction() {
|
||||
IcannReportingUploadAction action = new IcannReportingUploadAction();
|
||||
action.icannReporter = mockReporter;
|
||||
action.gcsUtils = new GcsUtils(gcsService, 1024);
|
||||
action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
|
||||
action.yearMonth = "2017-06";
|
||||
action.yearMonth = "2017-05";
|
||||
action.reportType = TRANSACTIONS;
|
||||
action.subdir = Optional.absent();
|
||||
action.tld = "test";
|
||||
action.reportingBucket = "basin";
|
||||
action.icannReportingBucket = "basin";
|
||||
action.response = response;
|
||||
return action;
|
||||
}
|
||||
@@ -80,7 +81,7 @@ public class IcannReportingUploadActionTest {
|
||||
public void testSuccess() throws Exception {
|
||||
IcannReportingUploadAction action = createAction();
|
||||
action.run();
|
||||
verify(mockReporter).send(FAKE_PAYLOAD, "test", "2017-06", TRANSACTIONS);
|
||||
verify(mockReporter).send(FAKE_PAYLOAD, "test", "2017-05", TRANSACTIONS);
|
||||
verifyNoMoreInteractions(mockReporter);
|
||||
assertThat(((FakeResponse) action.response).getPayload())
|
||||
.isEqualTo("OK, sending: test,csv\n13,37");
|
||||
@@ -92,9 +93,9 @@ public class IcannReportingUploadActionTest {
|
||||
doThrow(new IOException("Expected exception."))
|
||||
.doNothing()
|
||||
.when(mockReporter)
|
||||
.send(FAKE_PAYLOAD, "test", "2017-06", TRANSACTIONS);
|
||||
.send(FAKE_PAYLOAD, "test", "2017-05", TRANSACTIONS);
|
||||
action.run();
|
||||
verify(mockReporter, times(2)).send(FAKE_PAYLOAD, "test", "2017-06", TRANSACTIONS);
|
||||
verify(mockReporter, times(2)).send(FAKE_PAYLOAD, "test", "2017-05", TRANSACTIONS);
|
||||
verifyNoMoreInteractions(mockReporter);
|
||||
assertThat(((FakeResponse) action.response).getPayload())
|
||||
.isEqualTo("OK, sending: test,csv\n13,37");
|
||||
@@ -155,7 +156,27 @@ public class IcannReportingUploadActionTest {
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"ICANN report object test-transactions-123456.csv "
|
||||
+ "in bucket basin/icann/monthly not found");
|
||||
+ "in bucket basin/icann/monthly/1234-56 not found");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_CreateFilename() throws Exception{
|
||||
assertThat(IcannReportingUploadAction.createFilename("test", "2017-05", ACTIVITY))
|
||||
.isEqualTo("test-activity-201705.csv");
|
||||
assertThat(IcannReportingUploadAction.createFilename("foo", "1234-56", TRANSACTIONS))
|
||||
.isEqualTo("foo-transactions-123456.csv");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_CreateBucketname() throws Exception{
|
||||
assertThat(
|
||||
IcannReportingUploadAction
|
||||
.createReportingBucketName("gs://my-reporting", Optional.absent(), "2017-05"))
|
||||
.isEqualTo("gs://my-reporting/icann/monthly/2017-05");
|
||||
assertThat(
|
||||
IcannReportingUploadAction
|
||||
.createReportingBucketName("gs://my-reporting", Optional.of("manual"), "2017-05"))
|
||||
.isEqualTo("gs://my-reporting/manual");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user