Пример #1
0
func Mock(w http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	pw, _ := password.Hash([]byte("passwordpassword"))

	coduno, err := model.Company{
		Address: mail.Address{
			Name:    "Coduno",
			Address: "*****@*****.**",
		},
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	victor, err := model.User{
		Address: mail.Address{
			Name:    "Victor Balan",
			Address: "*****@*****.**",
		},
		Nick:           "vbalan",
		HashedPassword: pw,
		Company:        coduno,
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	paul, err := model.User{
		Address: mail.Address{
			Name:    "Paul Bochis",
			Address: "*****@*****.**",
		},
		Nick:           "pbochis",
		HashedPassword: pw,
		Company:        coduno,
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	lorenz, err := model.User{
		Address: mail.Address{
			Name:    "Lorenz Leutgeb",
			Address: "*****@*****.**",
		},
		Nick:           "flowlo",
		HashedPassword: pw,
		Company:        coduno,
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	model.Profile{
		Skills:     model.Skills{1, .5, 1},
		LastUpdate: time.Now(),
	}.PutWithParent(ctx, victor)

	model.Profile{
		Skills:     model.Skills{.5, 1, 1},
		LastUpdate: time.Now(),
	}.PutWithParent(ctx, paul)

	model.Profile{
		Skills:     model.Skills{1, 1, .5},
		LastUpdate: time.Now(),
	}.PutWithParent(ctx, lorenz)

	taskOne, err := model.Task{
		Assignment: model.Assignment{
			Name:         "Hello, world!",
			Description:  "This is a welcome task to our platform. It is the easiest one so you can learn the ui and the workflow.",
			Instructions: "Create a program that outputs 'Hello, world!' in a language of your preference.",
			Duration:     time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "output-match-task",
			},
		},
		Languages:    []string{"java", "py", "c", "cpp"},
		SkillWeights: model.SkillWeights{.1, .2, .3},
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	_, err = model.Test{
		Tester: int64(test.Simple),
		Name:   "Hello world test",
		Params: map[string]string{
			"tests": "coduno-tests/helloworld",
		},
	}.PutWithParent(ctx, taskOne)
	if err != nil {
		panic(err)
	}

	taskTwo, err := model.Task{
		Assignment: model.Assignment{
			Name: "Fizzbuzz",
			Description: `Fizz buzz is a group word game for children to teach them about division.
			 Players take turns to count incrementally, replacing any number divisible by three with the word 'fizz',
			 and any number divisible by five with the word 'buzz'.`,
			Instructions: `Your job is to create the 'fizzbuzz(int n)' function.
			The n parameter represents the max number to wich you need to generate the fizzbuzz data.
			The output needs to be separated by '\n'.`,
			Duration: time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "output-match-task",
			},
		},
		SkillWeights: model.SkillWeights{.1, .2, .3},
		Languages:    []string{"java", "py", "c", "cpp"},
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	model.Test{
		Tester: int64(test.Simple),
		Params: map[string]string{
			"tests": "coduno-tests/fizzbuzz",
		},
	}.PutWithParent(ctx, taskTwo)

	taskThree, err := model.Task{
		Assignment: model.Assignment{
			Name: "N-Gram",
			Description: `In the fields of computational linguistics and probability, an n-gram is a contiguous sequence
			of n items from a given sequence of text or speech. The items can be phonemes, syllables, letters, words or base
			pairs according to the application. The n-grams typically are collected from a text or speech corpus.`,
			Instructions: `Your job is to create a function with the signature ngram(String content, int len)
			and outputs the number of ngrams of length len.`,
			Duration: time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "javaut-task",
			},
		},
		SkillWeights: model.SkillWeights{.1, .2, .3},
		Languages:    []string{"javaut"},
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	model.Test{
		Tester: int64(test.Junit),
		Params: map[string]string{
			"tests":      "coduno-tests/ngram",
			"resultPath": "/run/build/test-results/",
		},
	}.PutWithParent(ctx, taskThree)

	taskFour, err := model.Task{
		Assignment: model.Assignment{
			Name:         "Simple code run test",
			Description:  "This is a mocked task for testing the simple code run.",
			Instructions: "This task will not be tested against anything.",
			Duration:     time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "simple-code-task",
			},
		},
		SkillWeights: model.SkillWeights{.1, .2, .3},
		Languages:    []string{"java", "py", "c", "cpp"},
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	model.Test{
		Tester: int64(test.Simple),
	}.PutWithParent(ctx, taskFour)

	_, err = model.Challenge{
		Assignment: model.Assignment{
			Name:        "Coduno hiring challenge",
			Description: "This is a hiring challenge for the Coduno company.",
			Instructions: `You can select your preffered language from the languages
			dropdown at every run your code will be tested so be careful with what you run.
			You can finish anytime and start the next task but keep in mind that you will not be
			able to get back to the previous task. Good luck!`,
			Duration: time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "sequential-challenge",
			},
		},
		Tasks: []*datastore.Key{
			taskOne,
			taskTwo,
			taskThree,
		},
	}.PutWithParent(ctx, coduno)
	if err != nil {
		panic(err)
	}
}
Пример #2
0
func mockData(ctx context.Context) {
	var err error
	CompanyKey, err = model.Company{
		Address: mail.Address{
			Name:    "Coduno",
			Address: "*****@*****.**",
		},
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	pw, _ := password.Hash([]byte(testingPassword))
	CompanyUserKey, err = model.User{
		Address: mail.Address{
			Name:    companyUserName,
			Address: "*****@*****.**",
		},
		Nick:           "john",
		HashedPassword: pw,
		Company:        CompanyKey,
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	UserKey, err = model.User{
		Address: mail.Address{
			Name:    coderUserName,
			Address: "*****@*****.**",
		},
		Nick:           "andy",
		HashedPassword: pw,
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	TaskKey, err = model.Task{
		Assignment: model.Assignment{
			Name:         "Task one",
			Description:  "Description of task one",
			Instructions: "Instructions of task one",
			Duration:     time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "coding-task",
			},
		},
		Languages:    []string{"py", "java"},
		SkillWeights: model.SkillWeights{0.25, 0.25, 0.25, 0.25},
	}.Put(ctx, nil)
	if err != nil {
		panic(err)
	}

	challengeKey, err = model.Challenge{
		Assignment: model.Assignment{
			Name:         "Challenge one",
			Description:  "Description of challenge one",
			Instructions: "Instructions of challenge one yay",
			Duration:     time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "sequential-challenge",
			},
		},
		Tasks: []*datastore.Key{TaskKey},
	}.PutWithParent(ctx, CompanyKey)
	if err != nil {
		panic(err)
	}

	var cmp model.User
	datastore.Get(ctx, CompanyUserKey, &cmp)
}
Пример #3
0
func createUser(ctx context.Context, w http.ResponseWriter, r *http.Request) (status int, err error) {
	var body = struct {
		Address, Nick, Password, Company string
	}{}

	if err = json.NewDecoder(r.Body).Decode(&body); err != nil {
		return http.StatusBadRequest, err
	}

	var companyKey *datastore.Key
	if body.Company != "" {
		companyKey, err = datastore.DecodeKey(body.Company)
		if err != nil {
			return http.StatusBadRequest, err
		}
	}

	if err = util.CheckNick(body.Nick); err != nil {
		return http.StatusBadRequest, err
	}

	var address *mail.Address
	if address, err = mail.ParseAddress(body.Address); err != nil {
		return http.StatusBadRequest, err
	}

	// Duplicate length check. If we move this after the conflict checks,
	// we could end up returning with a short password after querying Datastore.
	// The other way round, we would have to hash the password, and then throw it
	// away because of possible conflicts.
	pw := []byte(body.Password)
	if err = password.CheckLen(pw); err != nil {
		return http.StatusBadRequest, err
	}

	var emailConflict bool
	if emailConflict, err = alreadyExists(ctx, "Address", address.Address); err != nil {
		return http.StatusInternalServerError, err
	}
	if emailConflict {
		return http.StatusConflict, errors.New("duplicate e-mail address")
	}

	var nickConflict bool
	if nickConflict, err = alreadyExists(ctx, "Nick", body.Nick); err != nil {
		return http.StatusInternalServerError, err
	}
	if nickConflict {
		return http.StatusConflict, errors.New("duplicate nick")
	}

	var hashedPassword []byte
	if hashedPassword, err = password.Hash(pw); err != nil {
		return http.StatusInternalServerError, err
	}

	user := model.User{
		Address:        *address,
		Nick:           body.Nick,
		HashedPassword: hashedPassword,
	}

	var key *datastore.Key
	if companyKey == nil {
		key, err = user.Save(ctx)
	} else {
		// Bind user to company for eternity.
		key, err = user.SaveWithParent(ctx, companyKey)
	}

	if err != nil {
		return http.StatusInternalServerError, err
	}

	w.WriteHeader(http.StatusCreated)
	json.NewEncoder(w).Encode(user.Key(key))
	return http.StatusOK, nil
}
Пример #4
0
func Mock(w http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	pw, _ := password.Hash([]byte("passwordpassword"))

	coduno, _ := model.Company{
		Address: mail.Address{
			Name:    "Coduno",
			Address: "*****@*****.**",
		},
	}.Save(ctx)

	victor, _ := model.User{
		Address: mail.Address{
			Name:    "Victor Balan",
			Address: "*****@*****.**",
		},
		Nick:           "vbalan",
		HashedPassword: pw,
	}.SaveWithParent(ctx, coduno)

	paul, _ := model.User{
		Address: mail.Address{
			Name:    "Paul Bochis",
			Address: "*****@*****.**",
		},
		Nick:           "pbochis",
		HashedPassword: pw,
	}.SaveWithParent(ctx, coduno)

	model.User{
		Address: mail.Address{
			Name:    "Alin Mayer",
			Address: "*****@*****.**",
		},
		Nick:           "amayer",
		HashedPassword: pw,
	}.Save(ctx)

	lorenz, _ := model.User{
		Address: mail.Address{
			Name:    "Lorenz Leutgeb",
			Address: "*****@*****.**",
		},
		Nick:           "flowlo",
		HashedPassword: pw,
	}.SaveWithParent(ctx, coduno)

	model.Profile{
		Skills:     model.Skills{12, 40, 1231},
		LastUpdate: time.Now(),
	}.SaveWithParent(ctx, victor)

	model.Profile{
		Skills:     model.Skills{11, 1234, 14},
		LastUpdate: time.Now(),
	}.SaveWithParent(ctx, paul)

	model.Profile{
		Skills:     model.Skills{154, 12, 1123},
		LastUpdate: time.Now(),
	}.SaveWithParent(ctx, lorenz)

	model.User{
		Address: mail.Address{
			Name:    "Admin",
			Address: "*****@*****.**",
		},
		Nick:           "admin",
		HashedPassword: pw,
	}.SaveWithParent(ctx, coduno)

	taskOne, _ := model.CodeTask{
		Task: model.Task{
			Assignment: model.Assignment{
				Name:         "Task one",
				Description:  "Description of task one",
				Instructions: "Instructions of task one",
				Duration:     time.Hour,
				Endpoints: model.Endpoints{
					WebInterface: "coding-task",
				},
			},
			SkillWeights: model.SkillWeights{1, 2, 3},
		},
		Runner:    "simple",
		Languages: []string{"java", "py"},
	}.Save(ctx)

	taskTwo, _ := model.CodeTask{
		Task: model.Task{
			Assignment: model.Assignment{
				Name:         "Task two",
				Description:  "Description of task two",
				Instructions: "Instructions of task two",
				Duration:     time.Hour,
				Endpoints: model.Endpoints{
					WebInterface: "simple-code-task",
				},
			},
			SkillWeights: model.SkillWeights{1, 2, 3},
		},
		Runner:    "simple",
		Languages: []string{"java", "py"},
	}.Save(ctx)

	taskThree, _ := model.CodeTask{
		Task: model.Task{
			Assignment: model.Assignment{
				Name:         "Task three",
				Description:  "Description of task three",
				Instructions: "Instructions of task three",
				Duration:     time.Hour,
				Endpoints: model.Endpoints{
					WebInterface: "simple-code-task",
				},
			},
			SkillWeights: model.SkillWeights{1, 2, 3},
		},
		Runner:    "simple",
		Languages: []string{"java", "py"},
	}.Save(ctx)

	model.Challenge{
		Assignment: model.Assignment{
			Name:         "Challenge one",
			Description:  "Description of challenge one",
			Instructions: "Instructions of challenge one",
			Duration:     time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "sequential-challenge",
			},
		},
		Tasks: []*datastore.Key{taskThree},
	}.SaveWithParent(ctx, coduno)

	model.Challenge{
		Assignment: model.Assignment{
			Name:         "Challenge two",
			Description:  "Description of challenge two",
			Instructions: "Instructions of challenge two",
			Duration:     time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "paralel-challenge",
			},
		},
		Tasks: []*datastore.Key{
			taskOne,
			taskTwo,
			taskThree,
		},
	}.SaveWithParent(ctx, coduno)
}