Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Data Logistics Service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eFlows4HPC WP2
Data Logistics Service
Commits
f93d1dc3
Commit
f93d1dc3
authored
3 years ago
by
Jedrzej Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
fixing tests
parent
ad0eb633
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#78291
failed
3 years ago
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
dags/b2shareoperator.py
+3
-4
3 additions, 4 deletions
dags/b2shareoperator.py
requirements.txt
+3
-1
3 additions, 1 deletion
requirements.txt
tests/test_b2shareoperator.py
+30
-11
30 additions, 11 deletions
tests/test_b2shareoperator.py
with
36 additions
and
16 deletions
dags/b2shareoperator.py
+
3
−
4
View file @
f93d1dc3
...
@@ -40,18 +40,17 @@ class B2ShareOperator(BaseOperator):
...
@@ -40,18 +40,17 @@ class B2ShareOperator(BaseOperator):
self
.
name
=
name
self
.
name
=
name
self
.
conn_id
=
conn_id
self
.
conn_id
=
conn_id
self
.
target_dir
=
target_dir
self
.
target_dir
=
target_dir
print
(
self
.
target_dir
)
def
execute
(
self
,
**
kwargs
):
def
execute
(
self
,
**
kwargs
):
hook
=
HttpHook
(
http_conn_id
=
self
.
conn_id
,
method
=
'
GET
'
)
hook
=
HttpHook
(
http_conn_id
=
self
.
conn_id
,
method
=
'
GET
'
)
print
(
kwargs
)
params
=
kwargs
[
'
context
'
][
'
params
'
]
params
=
kwargs
[
'
context
'
][
'
params
'
]
oid
=
params
[
'
oid
'
]
oid
=
params
[
'
oid
'
]
hrespo
=
hook
.
run
(
endpoint
=
f
"
/api/records/
{
oid
}
"
)
hrespo
=
hook
.
run
(
endpoint
=
f
"
/api/records/
{
oid
}
"
)
print
(
hrespo
)
print
(
hrespo
)
flist
=
get_file_list
(
hrespo
.
json
())
flist
=
get_file_list
(
hrespo
.
json
())
print
(
flist
)
ti
=
kwargs
[
'
context
'
][
'
ti
'
]
ti
=
kwargs
[
'
context
'
][
'
ti
'
]
name_mappings
=
{}
name_mappings
=
{}
for
fname
,
url
in
flist
.
items
():
for
fname
,
url
in
flist
.
items
():
...
...
This diff is collapsed.
Click to expand it.
requirements.txt
+
3
−
1
View file @
f93d1dc3
requests
requests
urllib3
==1.26.6
urllib3
==1.26.6
apache-airflow-providers-ssh
apache-airflow-providers-ssh
apache-airflow-providers-http
apache-airflow-providers-sftp
This diff is collapsed.
Click to expand it.
tests/test_b2shareoperator.py
+
30
−
11
View file @
f93d1dc3
import
unittest
import
unittest
from
airflow.utils.state
import
State
from
unittest.mock
import
patch
,
Mock
from
airflow.utils.dates
import
days_ago
from
dags.b2shareoperator
import
B2ShareOperator
from
airflow
import
DAG
from
airflow
import
DAG
from
airflow.models.taskinstance
import
TaskInstance
from
airflow.models.taskinstance
import
TaskInstance
from
airflow.utils.dates
import
days_ago
from
airflow.utils.state
import
State
from
dags.b2shareoperator
import
B2ShareOperator
,
get_file_list
DEFAULT_DATE
=
'
2019-10-03
'
DEFAULT_DATE
=
'
2019-10-03
'
TEST_DAG_ID
=
'
test_my_custom_operator
'
TEST_DAG_ID
=
'
test_my_custom_operator
'
class
B2ShareOperatorTest
(
unittest
.
TestCase
):
class
B2ShareOperatorTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
dag
=
DAG
(
TEST_DAG_ID
,
schedule_interval
=
'
@daily
'
,
default_args
=
{
'
start_date
'
:
days_ago
(
2
)},
params
=
{
"
oid
"
:
"
111
"
})
self
.
dag
=
DAG
(
TEST_DAG_ID
,
schedule_interval
=
'
@daily
'
,
default_args
=
{
'
start_date
'
:
days_ago
(
2
)},
params
=
{
"
oid
"
:
"
111
"
})
self
.
op
=
B2ShareOperator
(
self
.
op
=
B2ShareOperator
(
dag
=
self
.
dag
,
dag
=
self
.
dag
,
task_id
=
'
test
'
,
task_id
=
'
test
'
,
...
@@ -19,9 +23,24 @@ class B2ShareOperatorTest(unittest.TestCase):
...
@@ -19,9 +23,24 @@ class B2ShareOperatorTest(unittest.TestCase):
)
)
self
.
ti
=
TaskInstance
(
task
=
self
.
op
,
execution_date
=
days_ago
(
1
))
self
.
ti
=
TaskInstance
(
task
=
self
.
op
,
execution_date
=
days_ago
(
1
))
def
test_execute_no_trigger
(
self
):
#with conf_vars({('params': {'oid': 1111})}):
@patch
(
'
dags.b2shareoperator.HttpHook
'
)
@patch
(
'
dags.b2shareoperator.get_file_list
'
)
@patch
(
'
dags.b2shareoperator.download_file
'
)
def
test_alt_execute_no_trigger
(
self
,
down
,
gfl
,
ht
):
gfl
.
return_value
=
{
'
ooo.txt
'
:
'
htt://file/to/download
'
}
down
.
return_value
=
'
tmp_name
'
self
.
ti
.
run
(
ignore_ti_state
=
False
)
self
.
ti
.
run
(
ignore_ti_state
=
False
)
print
(
self
.
ti
.
state
)
print
(
self
.
ti
.
state
)
self
.
assertEqual
(
State
.
SUCCESS
,
self
.
ti
.
state
)
self
.
assertEqual
(
State
.
SUCCESS
,
self
.
ti
.
state
)
# Assert something related to tasks results
# Assert something related to tasks results
def
test_get_files
(
self
):
with
patch
(
'
dags.b2shareoperator.requests.get
'
)
as
get
:
m
=
Mock
()
m
.
json
.
return_value
=
{
'
contents
'
:
[{
'
key
'
:
'
veryimportant.txt
'
,
'
links
'
:{
'
self
'
:
'
http://foo.bar
'
}}]}
get
.
return_value
=
m
ret
=
get_file_list
(
obj
=
{
'
links
'
:
{
'
files
'
:
[
'
bla
'
]}})
self
.
assertEqual
(
len
(
ret
),
1
)
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