Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
469fc63c
Commit
469fc63c
authored
3 years ago
by
sandeepsajan0
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for EditInvoiceForm
parent
25fb78e4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hypha/apply/projects/tests/test_forms.py
+74
-0
74 additions, 0 deletions
hypha/apply/projects/tests/test_forms.py
with
74 additions
and
0 deletions
hypha/apply/projects/tests/test_forms.py
+
74
−
0
View file @
469fc63c
import
json
from
io
import
BytesIO
from
io
import
BytesIO
from
unittest
import
mock
from
unittest
import
mock
...
@@ -15,6 +16,7 @@ from ..files import get_files
...
@@ -15,6 +16,7 @@ from ..files import get_files
from
..forms.payment
import
(
from
..forms.payment
import
(
ChangeInvoiceStatusForm
,
ChangeInvoiceStatusForm
,
CreateInvoiceForm
,
CreateInvoiceForm
,
EditInvoiceForm
,
SelectDocumentForm
,
SelectDocumentForm
,
filter_request_choices
,
filter_request_choices
,
)
)
...
@@ -39,6 +41,7 @@ from .factories import (
...
@@ -39,6 +41,7 @@ from .factories import (
DocumentCategoryFactory
,
DocumentCategoryFactory
,
InvoiceFactory
,
InvoiceFactory
,
ProjectFactory
,
ProjectFactory
,
SupportingDocumentFactory
,
address_to_form_data
,
address_to_form_data
,
)
)
...
@@ -365,6 +368,77 @@ class TestCreateInvoiceForm(TestCase):
...
@@ -365,6 +368,77 @@ class TestCreateInvoiceForm(TestCase):
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertFalse
(
form
.
is_valid
())
class
TestEditInvoiceForm
(
TestCase
):
def
test_remove_existing_supporting_document
(
self
):
invoice
=
InvoiceFactory
()
SupportingDocumentFactory
(
invoice
=
invoice
,
document
=
invoice
.
document
)
self
.
assertTrue
(
invoice
.
supporting_documents
.
exists
())
form
=
EditInvoiceForm
(
data
=
{
'
document
'
:
invoice
.
document
,
'
supporting_documents-uploads
'
:
'
[]
'
,
'
date_from
'
:
'
2018-08-15
'
,
'
date_to
'
:
'
2019-08-15
'
,
'
amount
'
:
invoice
.
amount
,
},
files
=
{
'
supporting_documents
'
:
[],
},
instance
=
invoice
)
self
.
assertTrue
(
form
.
is_valid
())
form
.
save
()
self
.
assertFalse
(
invoice
.
supporting_documents
.
exists
())
def
test_keep_existing_supporting_document
(
self
):
invoice
=
InvoiceFactory
()
supporting_document
=
SupportingDocumentFactory
(
invoice
=
invoice
)
self
.
assertEqual
(
invoice
.
supporting_documents
.
count
(),
1
)
form
=
EditInvoiceForm
(
data
=
{
'
document
'
:
invoice
.
document
,
'
supporting_documents-uploads
'
:
json
.
dumps
(
[{
"
name
"
:
supporting_document
.
document
.
name
,
"
size
"
:
supporting_document
.
document
.
size
,
"
type
"
:
"
existing
"
}]
),
'
date_from
'
:
'
2018-08-15
'
,
'
date_to
'
:
'
2019-08-15
'
,
'
amount
'
:
invoice
.
amount
,
},
instance
=
invoice
)
self
.
assertTrue
(
form
.
is_valid
())
invoice
=
form
.
save
()
self
.
assertEqual
(
invoice
.
supporting_documents
.
count
(),
1
)
def
test_add_new_supporting_document
(
self
):
invoice
=
InvoiceFactory
()
self
.
assertEqual
(
invoice
.
supporting_documents
.
count
(),
0
)
supporting_document
=
[
SimpleUploadedFile
(
'
invoice.pdf
'
,
BytesIO
(
b
'
somebinarydata
'
).
read
())]
form
=
EditInvoiceForm
(
data
=
{
'
document
'
:
invoice
.
document
,
'
supporting_documents-uploads
'
:
'
[]
'
,
'
date_from
'
:
'
2018-08-15
'
,
'
date_to
'
:
'
2019-08-15
'
,
'
amount
'
:
invoice
.
amount
,
},
files
=
{
'
supporting_documents
'
:
supporting_document
,
},
instance
=
invoice
,
)
self
.
assertTrue
(
form
.
is_valid
())
invoice
=
form
.
save
()
self
.
assertEqual
(
invoice
.
supporting_documents
.
count
(),
1
)
@override_settings
(
ROOT_URLCONF
=
'
hypha.apply.urls
'
)
@override_settings
(
ROOT_URLCONF
=
'
hypha.apply.urls
'
)
class
TestSelectDocumentForm
(
TestCase
):
class
TestSelectDocumentForm
(
TestCase
):
def
test_copying_files
(
self
):
def
test_copying_files
(
self
):
...
...
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