Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
netbox-awx-plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
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
Code review analytics
Issue 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
ICS Control System Infrastructure
netbox-awx-plugin
Commits
5fd4bfaa
Commit
5fd4bfaa
authored
5 months ago
by
Fahrudin Halilovic
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for views -
INFRA-10662
parent
25ada42a
No related branches found
No related tags found
1 merge request
!6
Add unit tests for views -INFRA-10662
Pipeline
#200827
passed
5 months ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
netbox_awx_plugin/tests/test_views.py
+85
-0
85 additions, 0 deletions
netbox_awx_plugin/tests/test_views.py
with
85 additions
and
0 deletions
netbox_awx_plugin/tests/test_views.py
0 → 100644
+
85
−
0
View file @
5fd4bfaa
# tests/test_views.py
from
django.test
import
TestCase
,
Client
from
django.urls
import
reverse
from
netbox_awx_plugin.models
import
AWX
,
AWXInventory
from
django.contrib.auth.models
import
User
from
unittest.mock
import
patch
class
ViewsTestCase
(
TestCase
):
def
setUp
(
self
):
# Create a test superuser and log in
self
.
user
=
User
.
objects
.
create_superuser
(
'
testuser
'
,
password
=
'
testpassword
'
)
self
.
client
=
Client
()
self
.
client
.
login
(
username
=
'
testuser
'
,
password
=
'
testpassword
'
)
# Create an AWX instance and inventory
self
.
awx
=
AWX
.
objects
.
create
(
name
=
'
Test AWX
'
,
url
=
'
https://awx.example.com
'
,
token
=
'
token123
'
)
self
.
awx_inventory
=
AWXInventory
.
objects
.
create
(
awx
=
self
.
awx
,
inventory_id
=
1
,
enabled
=
True
,
)
def
test_awx_list_view
(
self
):
url
=
reverse
(
'
plugins:netbox_awx_plugin:awx_list
'
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertContains
(
response
,
self
.
awx
.
name
)
def
test_awx_detail_view
(
self
):
url
=
reverse
(
'
plugins:netbox_awx_plugin:awx
'
,
args
=
[
self
.
awx
.
pk
])
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertContains
(
response
,
self
.
awx
.
name
)
def
test_awx_add_view
(
self
):
url
=
reverse
(
'
plugins:netbox_awx_plugin:awx_add
'
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
{
'
name
'
:
'
New AWX
'
,
'
url
'
:
'
https://new-awx.example.com
'
,
'
token
'
:
'
newtoken123
'
,
}
response
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertTrue
(
AWX
.
objects
.
filter
(
name
=
'
New AWX
'
).
exists
())
def
test_awx_edit_view
(
self
):
url
=
reverse
(
'
plugins:netbox_awx_plugin:awx_edit
'
,
args
=
[
self
.
awx
.
pk
])
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
{
'
name
'
:
'
Updated AWX
'
,
'
url
'
:
self
.
awx
.
url
,
'
token
'
:
self
.
awx
.
token
,
}
response
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
awx
.
refresh_from_db
()
self
.
assertEqual
(
self
.
awx
.
name
,
'
Updated AWX
'
)
def
test_awx_delete_view
(
self
):
url
=
reverse
(
'
plugins:netbox_awx_plugin:awx_delete
'
,
args
=
[
self
.
awx
.
pk
])
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response
=
self
.
client
.
post
(
url
,
data
=
{
'
confirm
'
:
True
})
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertFalse
(
AWX
.
objects
.
filter
(
pk
=
self
.
awx
.
pk
).
exists
())
@patch
(
'
netbox_awx_plugin.views.Job.enqueue
'
)
def
test_awxinventory_sync_view
(
self
,
mock_enqueue
):
url
=
reverse
(
'
plugins:netbox_awx_plugin:awxinventory_sync
'
,
args
=
[
self
.
awx_inventory
.
pk
])
response
=
self
.
client
.
post
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
messages
=
list
(
response
.
context
[
'
messages
'
])
self
.
assertTrue
(
any
(
"
Queued job
"
in
str
(
message
)
for
message
in
messages
))
mock_enqueue
.
assert_called_once
()
\ 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