Run the Spec11 pipeline daily without sending emails

Add a sendSpec11Email parameter that allows us to only send the email on
one run per month. Next, we will compute the diffs between the daily runs
and send daily emails with those diffs.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=224404653
This commit is contained in:
jianglai 2018-12-06 14:10:25 -08:00
parent 3ef8cd692d
commit ec26e3a96a
20 changed files with 434 additions and 158 deletions

View file

@ -19,9 +19,11 @@ import static google.registry.testing.JUnitBackports.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.common.truth.Truth8;
import google.registry.request.HttpException.BadRequestException;
import google.registry.testing.FakeClock;
import google.registry.util.Clock;
import java.time.LocalDate;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import org.joda.time.DateTime;
@ -37,6 +39,7 @@ public class ReportingModuleTest {
private HttpServletRequest req = mock(HttpServletRequest.class);
private Clock clock;
@Before
public void setUp() {
clock = new FakeClock(DateTime.parse("2017-07-01TZ"));
@ -45,7 +48,14 @@ public class ReportingModuleTest {
@Test
public void testEmptyYearMonthParameter_returnsEmptyYearMonthOptional() {
when(req.getParameter("yearMonth")).thenReturn("");
assertThat(ReportingModule.provideYearMonthOptional(req)).isEqualTo(Optional.empty());
Truth8.assertThat(ReportingModule.provideYearMonthOptional(req)).isEmpty();
}
@Test
public void testValidYearMonthParameter_returnsThatMonth() {
when(req.getParameter("yearMonth")).thenReturn("2017-05");
Truth8.assertThat(ReportingModule.provideYearMonthOptional(req))
.hasValue(new YearMonth(2017, 5));
}
@Test
@ -61,14 +71,50 @@ public class ReportingModuleTest {
@Test
public void testEmptyYearMonth_returnsLastMonth() {
assertThat(ReportingModule.provideYearMonth(Optional.empty(), clock))
assertThat(ReportingModule.provideYearMonth(Optional.empty(), LocalDate.of(2017, 7, 6)))
.isEqualTo(new YearMonth(2017, 6));
}
@Test
public void testGivenYearMonth_returnsThatMonth() {
assertThat(ReportingModule.provideYearMonth(Optional.of(new YearMonth(2017, 5)), clock))
assertThat(
ReportingModule.provideYearMonth(
Optional.of(new YearMonth(2017, 5)), LocalDate.of(2017, 7, 6)))
.isEqualTo(new YearMonth(2017, 5));
}
@Test
public void testEmptyDateParameter_returnsEmptyDateOptional() {
when(req.getParameter("date")).thenReturn("");
Truth8.assertThat(ReportingModule.provideDateOptional(req)).isEmpty();
}
@Test
public void testValidDateParameter_returnsThatDate() {
when(req.getParameter("date")).thenReturn("2017-05-13");
Truth8.assertThat(ReportingModule.provideDateOptional(req))
.hasValue(LocalDate.of(2017, 5, 13));
}
@Test
public void testInvalidDateParameter_throwsException() {
when(req.getParameter("date")).thenReturn("20170513");
BadRequestException thrown =
assertThrows(BadRequestException.class, () -> ReportingModule.provideDateOptional(req));
assertThat(thrown)
.hasMessageThat()
.contains("date must be in yyyy-MM-dd format, got 20170513 instead");
}
@Test
public void testEmptyDate_returnsToday() {
assertThat(ReportingModule.provideDate(Optional.empty(), clock))
.isEqualTo(LocalDate.of(2017, 7, 1));
}
@Test
public void testGivenDate_returnsThatDate() {
assertThat(ReportingModule.provideDate(Optional.of(LocalDate.of(2017, 7, 2)), clock))
.isEqualTo(LocalDate.of(2017, 7, 2));
}
}