Skip to content

Commit 614b4f3

Browse files
Test fixes 12. Tests pass
1 parent 36296d9 commit 614b4f3

File tree

2 files changed

+53
-44
lines changed

2 files changed

+53
-44
lines changed

tmcrstudioaddin/tests/testthat.R

+42-42
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,49 @@ library(tmcrstudioaddin)
1010

1111
test_check("tmcrstudioaddin")
1212

13-
response <- login("a", "b", "c", "d", "tmc.mooc.fi")
13+
# response <- login("a", "b", "c", "d", "tmc.mooc.fi")
1414

15-
login <- function(clientID, secret, username, password, serverAddress) {
16-
body <- list("grant_type" = "password",
17-
"client_id" = clientID,
18-
"client_secret" = secret,
19-
"username" = username,
20-
"password" = password)
21-
# Authenticate
22-
url <- paste(serverAddress, "/oauth/token", sep = "")
23-
req <- httr::POST(url = url,
24-
body = body,
25-
config = httr::timeout(30),
26-
encode = "form")
27-
# if http status is ok return token
28-
.dcat("req", req)
29-
# print(req)
30-
if (status_code(req) == 200) {
31-
token <- paste("Bearer", httr::content(req)$access_token)
32-
credentials <- list(username = username,
33-
token = token,
34-
serverAddress = serverAddress,
35-
organization = NULL)
36-
# print("saveCredentials site A")
37-
tmcrstudioaddin::saveCredentials(credentials)
38-
response <- list(token = token,
39-
error = NULL,
40-
error_description = NULL)
41-
} else if (status_code(req) == 400) {
42-
response <- list(token = NULL,
43-
error = "Bad request",
44-
error_description = "Check your username and/or password")
45-
} else if (status_code(req) == 401) {
46-
response <- list(token = NULL,
47-
error = "Invalid credentials",
48-
error_description = "Check your username and/or password")
49-
} else {
50-
response <- list(token = NULL,
51-
error = "Error",
52-
error_description = "Something went wrong. Try again later")
53-
}
54-
return(response)
55-
}
15+
# login <- function(clientID, secret, username, password, serverAddress) {
16+
# body <- list("grant_type" = "password",
17+
# "client_id" = clientID,
18+
# "client_secret" = secret,
19+
# "username" = username,
20+
# "password" = password)
21+
# # Authenticate
22+
# url <- paste(serverAddress, "/oauth/token", sep = "")
23+
# req <- httr::POST(url = url,
24+
# body = body,
25+
# config = httr::timeout(30),
26+
# encode = "form")
27+
# # if http status is ok return token
28+
# .dcat("req", req)
29+
# # print(req)
30+
# if (status_code(req) == 200) {
31+
# token <- paste("Bearer", httr::content(req)$access_token)
32+
# credentials <- list(username = username,
33+
# token = token,
34+
# serverAddress = serverAddress,
35+
# organization = NULL)
36+
# # print("saveCredentials site A")
37+
# tmcrstudioaddin::saveCredentials(credentials)
38+
# response <- list(token = token,
39+
# error = NULL,
40+
# error_description = NULL)
41+
# } else if (status_code(req) == 400) {
42+
# response <- list(token = NULL,
43+
# error = "Bad request",
44+
# error_description = "Check your username and/or password")
45+
# } else if (status_code(req) == 401) {
46+
# response <- list(token = NULL,
47+
# error = "Invalid credentials",
48+
# error_description = "Check your username and/or password")
49+
# } else {
50+
# response <- list(token = NULL,
51+
# error = "Error",
52+
# error_description = "Something went wrong. Try again later")
53+
# }
54+
# return(response)
55+
# }
5656

5757
.dcat <- function(name, x) {
5858
cat(paste0("<", name, ">\n"))

tmcrstudioaddin/tests/testthat/testSubmissions.R

+11-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ mockProcessingSubmitJson <- function() {
2727
}
2828

2929
test_that("If no metadata file, does not submit", {
30-
credentials <- list()
30+
credentials <- list(token = "token", serverAddress = "local.host.nowhere")
31+
# stub(submit_current, "upload_current_exercise",
32+
# list(error = list("Could not read json")))
33+
print("AA")
34+
print(noMetadata)
35+
print(credentials)
3136
submitJson <- submit_current(path = noMetadata, credentials = credentials)
32-
expect_equal(submitJson$error[[1]], "Could not read json")
37+
print(submitJson)
38+
print("BB")
39+
expect_equal(submitJson$error[[1]], "Corrupted project: missing RTMC metadata")
40+
print("CC")
3341
})
3442

3543
test_that("submit_current works when no errors", {
@@ -190,3 +198,4 @@ test_that("Message function is called", {
190198
"<p>You can now view the model solution on the server.")
191199
expect_equal(args[[2]], expected_message)
192200
})
201+

0 commit comments

Comments
 (0)