Beispiel #1
0
// InitTock initalizes the tock struct
func InitTock() *Tock {
	// Get the tock url
	tockURL := os.Getenv("TOCK_URL")
	if tockURL == "" {
		log.Fatal("TOCK_URL environment variable not found")
	}
	userTockURL := os.Getenv("USER_TOCK_URL")
	if userTockURL == "" {
		log.Fatal("USER_TOCK_URL environment variable not found")
	}
	auditEndpoint := tockURL + "/api/reporting_period_audit/"
	// Initalize a new data fetcher
	dataFetcher := helpers.NewDataFetcher(helpers.FetchData)
	return &Tock{tockURL, userTockURL, auditEndpoint, dataFetcher}
}
Beispiel #2
0
	        "id":2,
	        "username":"******",
	        "first_name":"user",
	        "last_name":"two",
	        "email":"*****@*****.**"
	      }
	    ]
	  }`)
	}
}

var tock = Tock{
	"TockURL",
	"UserTockURL",
	"AuditEndpoint",
	helpers.NewDataFetcher(mockDataFetcher),
}

func TestFetchTockReportingPeriods(t *testing.T) {
	reportingPeriod := tock.fetchReportingPeriod()
	if reportingPeriod != "2014-11-22" {
		t.Errorf(reportingPeriod)
	}
}

func TestFetchTockUsers(t *testing.T) {
	reportingPeriod := tock.fetchReportingPeriod()
	baseEndpoint := fmt.Sprintf("%s%s", tock.AuditEndpoint, reportingPeriod)
	userData := tock.FetchTockUsers(baseEndpoint)
	if len(userData.Users) != 2 {
		t.Error(userData)