Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
IDATT2900-072
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mattias Agentoft Eggen
IDATT2900-072
Commits
79f335c3
Commit
79f335c3
authored
3 years ago
by
magnus2142
Browse files
Options
Downloads
Plain Diff
added env data to be use din endpoints
parents
9da8a05b
9352c2e6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+32
-3
32 additions, 3 deletions
README.md
bbcli/endpoints.py
+52
-23
52 additions, 23 deletions
bbcli/endpoints.py
tests/test_bbcli.py
+4
-6
4 additions, 6 deletions
tests/test_bbcli.py
with
88 additions
and
32 deletions
README.md
+
32
−
3
View file @
79f335c3
# IDATT2900-072
useful stuff
to run the tests:
python -m pytest tests
`
python -m pytest tests
`
python -m bbcli --version
\ No newline at end of file
## To download the project and install all the requirements
### 1. git clone project:
**With SSH:**
`git clone git@gitlab.stud.idi.ntnu.no:mattiaae/idatt2900-072.git`
`cd idatt2900-072`
**With HTTPS:**
`git clone https://gitlab.stud.idi.ntnu.no/mattiaae/idatt2900-072.git`
`cd idatt2900-072`
### 2. Install the virtual environement inside the project folder
`python -m venv ./venv`
**OR**
`python3 -m venv ./venv`
`source ./venv/bin/activate`
### 3. Install all the requirements
`python -m pip install -r requirements.txt`
### 4. To chech that it is successfully installed, check the version
`python -m bbcli --version`
### 5. Run the tests
`python -m pytest test`
This diff is collapsed.
Click to expand it.
bbcli/endpoints.py
+
52
−
23
View file @
79f335c3
import
requests
#from requests.auth import HTTPBasicAuth
import
json
import
pprint
import
pprint
import
typer
#from string_builder import StringBuilder
import
click
...
...
@@ -34,22 +34,39 @@ def get_user(user_name: str = typer.Argument('', help='Name of the user'))-> Non
cookies
=
cookies
)
data
=
x
.
json
()
# print(data)
print
(
pprint
.
pprint
(
data
))
data
=
x
.
json
()[
'
results
'
][
0
]
# typer.echo(data)
fn
=
data
[
'
name
'
][
'
given
'
]
sn
=
data
[
'
name
'
][
'
family
'
]
id
=
data
[
'
studentId
'
]
typer
.
echo
(
f
'
Name of the student:
{
fn
}
{
sn
}
'
)
typer
.
echo
(
f
'
The student id:
{
id
}
'
)
@app.command
(
name
=
'
get-course
'
)
def
get_course
(
course_id
:
str
=
'
IDATT2900
'
):
def
get_course
(
course_id
:
str
=
typer
.
Argument
(
''
,
help
=
'
Id of the course
'
)
):
'''
Get the course
'''
url
=
base_url
+
'
courses?courseId=%s
'
%
course_id
if
course_id
==
''
:
course_id
=
typer
.
prompt
(
"
What is the course id?
"
)
url
=
f
'
{
base_url
}
courses?courseId=
{
course_id
}
'
x
=
requests
.
get
(
url
,
cookies
=
cookies
)
data
=
x
.
json
()
print
(
pprint
.
pprint
(
data
))
data
=
x
.
json
()[
'
results
'
][
0
]
name
=
data
[
'
name
'
]
course_url
=
data
[
'
externalAccessUrl
'
]
typer
.
echo
(
name
)
typer
.
echo
(
f
'
URL for the course:
{
course_url
}
'
)
# def open_folder(data, map):
# key = 'hasChildren'
# acc = []
# if key in data and data[key] == True:
# acc.append
@app.command
(
name
=
'
get-course-contents
'
)
...
...
@@ -58,35 +75,45 @@ def get_course_contents(course_id: str = '_27251_1'):
Get the course contents
'''
url
=
f
'
{
base_url
}
courses/
{
course_id
}
/contents
'
typer
.
echo
(
url
)
x
=
requests
.
get
(
url
,
cookies
=
cookies
)
data
=
x
.
json
()
print
(
pprint
.
pprint
(
data
))
data
=
x
.
json
()[
'
results
'
]
typer
.
echo
(
'
Mapper:
'
)
map
=
dict
()
for
i
in
range
(
len
(
data
)):
title
=
data
[
i
][
'
title
'
]
map
[
i
+
1
]
=
data
[
i
][
'
id
'
]
typer
.
echo
(
f
'
{
i
+
1
}
{
title
}
'
)
# idx = typer.prompt("Open a folder by pressing a number: ")
typer
.
echo
(
map
)
# for d in data:
# typer.echo(d['title'])
def
get_children
(
d
,
url
,
acc
,
count
:
int
=
0
):
#count = count + 1
#
print
(f'kommer hit: {count}')
#
typer.echo
(f'kommer hit: {count}')
key
=
'
hasChildren
'
if
key
not
in
d
or
d
[
key
]
==
False
:
print
(
'
nei
'
)
typer
.
echo
(
'
nei
'
)
return
acc
else
:
print
(
'
ja
'
)
typer
.
echo
(
'
ja
'
)
id
=
d
[
'
id
'
]
url
=
f
'
{
url
}
/
{
id
}
/children
'
print
(
url
)
typer
.
echo
(
url
)
response
=
requests
.
get
(
url
,
cookies
=
cookies
)
child
=
response
.
json
()[
'
results
'
]
#
get_children(child, url, acc+child, count)
return
child
get_children
(
child
,
url
,
acc
+
child
,
count
)
#
return child
def
get_children
(
d
,
url
):
key
=
'
hasChildren
'
while
key
in
d
and
d
[
key
]
==
True
:
id
=
d
[
'
id
'
]
url
=
f
'
{
url
}
/
{
id
}
/children
'
print
()
print
(
url
)
print
()
typer
.
echo
()
typer
.
echo
(
url
)
typer
.
echo
()
response
=
requests
.
get
(
url
,
cookies
=
cookies
)
child
=
response
.
json
()[
'
results
'
]
return
child
...
...
@@ -103,8 +130,10 @@ def get_assignments(course_id: str = typer.Argument('_27251_1', help='The course
data
=
x
.
json
()[
'
results
'
]
#res = get_children(data[2], url, [])
res
=
get_children
(
data
[
2
],
url
)
print
(
pprint
.
pprint
(
res
))
#print(pprint.pprint(data))
#typer.echo(ptyper.echo.ptyper.echo(res))
for
o
in
res
:
typer
.
echo
(
o
[
'
title
'
])
#typer.echo(ptyper.echo.ptyper.echo(data))
#for d in data:
#
print
()
#
print
(get_children(d, url))
#
typer.echo
()
#
typer.echo
(get_children(d, url))
This diff is collapsed.
Click to expand it.
tests/test_bbcli.py
+
4
−
6
View file @
79f335c3
from
typer.testing
import
CliRunner
from
bbcli
import
__app_name__
,
__version__
,
cli
,
getuser
,
getcoursecontents
from
bbcli
import
__app_name__
,
__version__
,
cli
,
get
_
user
runner
=
CliRunner
()
...
...
@@ -10,12 +10,10 @@ def test_version():
assert
result
.
exit_code
==
0
assert
result
.
output
==
f
"
{
__app_name__
}
v
{
__version__
}
\n
"
#assert f"{__app_name__} v{__version__}\n" in result.stdout
assert
f
"
{
__app_name__
}
v
{
__version__
}
\n
"
in
result
.
stdout
def
test_endpoint_getuser
():
result
=
runner
.
invoke
(
getuser
,
input
=
'
hanswf
'
)
result
=
runner
.
invoke
(
get
_
user
,
input
=
'
hanswf
'
)
assert
not
result
.
exception
def
test_endpoint_getcoursecontents
():
res
=
runner
.
invoke
(
getcoursecontents
)
assert
not
res
.
exception
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment