Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
SMASCH
scheduling-system
Commits
54e070e9
There was a problem fetching the pipeline metadata.
Commit
54e070e9
authored
7 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
validation paterns added for configuration items
parent
53f0ed4e
No related branches found
No related tags found
1 merge request
!47
Resolve "Email to technician"
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
smash/web/models/configuration_item.py
+23
-1
23 additions, 1 deletion
smash/web/models/configuration_item.py
smash/web/tests/test_api_configuration_item.py
+21
-0
21 additions, 0 deletions
smash/web/tests/test_api_configuration_item.py
with
44 additions
and
1 deletion
smash/web/models/configuration_item.py
+
23
−
1
View file @
54e070e9
# coding=utf-8
import
re
from
django.db
import
models
from
web.models.constants
import
CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE
,
\
NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE
,
KIT_EMAIL_HOUR_CONFIGURATION_TYPE
,
\
KIT_EMAIL_DAY_OF_WEEK_CONFIGURATION_TYPE
class
ConfigurationItem
(
models
.
Model
):
type
=
models
.
CharField
(
max_length
=
50
,
...
...
@@ -24,4 +29,21 @@ class ConfigurationItem(models.Model):
@staticmethod
def
is_valid
(
item
):
return
True
message
=
ConfigurationItem
.
validation_error
(
item
)
return
message
==
""
@staticmethod
def
validation_error
(
item
):
pattern
=
None
if
item
.
type
==
CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE
\
or
item
.
type
==
NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE
:
pattern
=
"
^#[0-9a-fA-F]+$
"
if
item
.
type
==
KIT_EMAIL_HOUR_CONFIGURATION_TYPE
:
pattern
=
"
^[0-9]{2}:[0-9]{2}$
"
if
item
.
type
==
KIT_EMAIL_DAY_OF_WEEK_CONFIGURATION_TYPE
:
pattern
=
"
^(MONDAY|TUESDAY|WEDNESDAY|THURSDAY|FRIDAY|SATURDAY|SUNDAY)$
"
if
pattern
is
not
None
:
if
not
re
.
compile
(
pattern
).
match
(
item
.
value
):
return
"
Invalid value of param:
"
+
item
.
name
+
"
. It should match regex pattern:
"
+
pattern
return
""
This diff is collapsed.
Click to expand it.
smash/web/tests/test_api_configuration_item.py
+
21
−
0
View file @
54e070e9
...
...
@@ -6,6 +6,9 @@ from django.urls import reverse
from
web.models
import
ConfigurationItem
from
web.tests.functions
import
create_configuration_item
from
.
import
LoggedInTestCase
from
web.models.constants
import
CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE
,
\
NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE
,
KIT_EMAIL_HOUR_CONFIGURATION_TYPE
,
\
KIT_EMAIL_DAY_OF_WEEK_CONFIGURATION_TYPE
class
TestConfigurationItemApi
(
LoggedInTestCase
):
...
...
@@ -31,3 +34,21 @@ class TestConfigurationItemApi(LoggedInTestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
updated_item
=
ConfigurationItem
.
objects
.
get
(
id
=
item
.
id
)
self
.
assertEqual
(
new_val
,
updated_item
.
value
)
def
test_configuration_modify_CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE_invalid_value
(
self
):
item
=
ConfigurationItem
.
objects
.
get
(
type
=
CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE
)
invalid_val
=
'
invalid color
'
response
=
self
.
client
.
get
(
reverse
(
'
web.api.update_configuration_item
'
),
{
'
id
'
:
item
.
id
,
'
value
'
:
invalid_val
})
self
.
assertEqual
(
response
.
status_code
,
200
)
updated_item
=
ConfigurationItem
.
objects
.
get
(
type
=
CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE
)
self
.
assertNotEqual
(
invalid_val
,
updated_item
.
value
)
def
test_configuration_modify_CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE_valid_value
(
self
):
item
=
ConfigurationItem
.
objects
.
get
(
type
=
CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE
)
invalid_val
=
'
#FFFFFF
'
response
=
self
.
client
.
get
(
reverse
(
'
web.api.update_configuration_item
'
),
{
'
id
'
:
item
.
id
,
'
value
'
:
invalid_val
})
self
.
assertEqual
(
response
.
status_code
,
200
)
updated_item
=
ConfigurationItem
.
objects
.
get
(
type
=
CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE
)
self
.
assertEqual
(
invalid_val
,
updated_item
.
value
)
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