Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ecommerce
Commits
3e158fb0
Commit
3e158fb0
authored
Feb 10, 2017
by
Vedran Karacic
Committed by
Vedran Karačić
Feb 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove obsolete management commands.
parent
551e6b04
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
0 additions
and
312 deletions
+0
-312
ecommerce/coupons/management/__init__.py
+0
-0
ecommerce/coupons/management/commands/__init__.py
+0
-0
ecommerce/coupons/management/commands/populate_coupon_categories.py
+0
-29
ecommerce/coupons/tests/test_command.py
+0
-34
ecommerce/extensions/offer/management/__init__.py
+0
-0
ecommerce/extensions/offer/management/commands/__init__.py
+0
-0
ecommerce/extensions/offer/management/commands/set_max_applications_to_none.py
+0
-22
ecommerce/extensions/offer/tests/test_commands.py
+0
-58
ecommerce/invoice/management/__init__.py
+0
-0
ecommerce/invoice/management/commands/__init__.py
+0
-0
ecommerce/invoice/management/commands/populate_invoice_orders.py
+0
-38
ecommerce/invoice/management/commands/squash_duplicate_invoices.py
+0
-26
ecommerce/invoice/tests.py
+0
-105
No files found.
ecommerce/coupons/management/__init__.py
deleted
100644 → 0
View file @
551e6b04
ecommerce/coupons/management/commands/__init__.py
deleted
100644 → 0
View file @
551e6b04
ecommerce/coupons/management/commands/populate_coupon_categories.py
deleted
100644 → 0
View file @
551e6b04
import
logging
from
django.core.management
import
BaseCommand
from
oscar.core.loading
import
get_model
Category
=
get_model
(
'catalogue'
,
'Category'
)
Product
=
get_model
(
'catalogue'
,
'Product'
)
ProductCategory
=
get_model
(
'catalogue'
,
'ProductCategory'
)
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
""" Populate the category field for coupons that do not have a category. """
ch
=
logging
.
StreamHandler
()
ch
.
setLevel
(
logging
.
DEBUG
)
logger
.
addHandler
(
ch
)
def
handle
(
self
,
*
args
,
**
options
):
support_other_cat
=
Category
.
objects
.
get
(
name
=
'Support-Other'
)
for
coupon
in
Product
.
objects
.
filter
(
product_class__name
=
'Coupon'
):
try
:
ProductCategory
.
objects
.
get
(
product
=
coupon
)
except
ProductCategory
.
DoesNotExist
:
ProductCategory
.
objects
.
create
(
product
=
coupon
,
category
=
support_other_cat
)
logger
.
info
(
'Added category for coupon [
%
s]'
,
coupon
.
id
)
ecommerce/coupons/tests/test_command.py
deleted
100644 → 0
View file @
551e6b04
from
django.core.management
import
call_command
from
oscar.core.loading
import
get_model
from
ecommerce.coupons.tests.mixins
import
CouponMixin
from
ecommerce.tests.testcases
import
TestCase
Category
=
get_model
(
'catalogue'
,
'Category'
)
ProductCategory
=
get_model
(
'catalogue'
,
'ProductCategory'
)
class
TestCouponCommand
(
CouponMixin
,
TestCase
):
""" Test coupon populate_coupon_category command. """
def
setUp
(
self
):
super
(
TestCouponCommand
,
self
)
.
setUp
()
self
.
filler_category
,
__
=
Category
.
objects
.
get_or_create
(
name
=
'Support-Other'
,
defaults
=
{
'depth'
:
1
})
self
.
coupon
=
self
.
create_coupon
()
def
test_add_category_to_coupon
(
self
):
""" Verify the correct category is assigned to a coupon without category. """
ProductCategory
.
objects
.
filter
(
product
=
self
.
coupon
)
.
delete
()
self
.
assertEqual
(
ProductCategory
.
objects
.
count
(),
0
)
call_command
(
'populate_coupon_categories'
)
self
.
assertEqual
(
ProductCategory
.
objects
.
count
(),
1
)
self
.
assertEqual
(
ProductCategory
.
objects
.
get
(
product
=
self
.
coupon
)
.
category
,
self
.
filler_category
)
def
test_coupon_with_category_unaffected
(
self
):
""" Verify coupon with category is unchanged after running command. """
self
.
assertEqual
(
ProductCategory
.
objects
.
count
(),
1
)
category
=
ProductCategory
.
objects
.
get
(
product
=
self
.
coupon
)
.
category
call_command
(
'populate_coupon_categories'
)
self
.
assertEqual
(
ProductCategory
.
objects
.
count
(),
1
)
self
.
assertEqual
(
ProductCategory
.
objects
.
get
(
product
=
self
.
coupon
)
.
category
,
category
)
ecommerce/extensions/offer/management/__init__.py
deleted
100644 → 0
View file @
551e6b04
ecommerce/extensions/offer/management/commands/__init__.py
deleted
100644 → 0
View file @
551e6b04
ecommerce/extensions/offer/management/commands/set_max_applications_to_none.py
deleted
100644 → 0
View file @
551e6b04
""" Changes ConditionalOffer max_global_applications for single use vouchers from one to None. """
from
__future__
import
unicode_literals
from
django.core.management
import
BaseCommand
from
oscar.core.loading
import
get_model
ConditionalOffer
=
get_model
(
'offer'
,
'ConditionalOffer'
)
class
Command
(
BaseCommand
):
def
handle
(
self
,
*
args
,
**
options
):
offers
=
ConditionalOffer
.
objects
.
filter
(
max_global_applications
=
1
,
vouchers__usage
=
'Single use'
)
if
offers
:
for
offer
in
offers
:
self
.
stdout
.
write
(
'Setting max_global_applications field to None for ConditionalOffer [{}]...'
.
format
(
offer
)
)
offer
.
max_global_applications
=
None
offer
.
save
()
self
.
stdout
.
write
(
'Done.'
)
else
:
self
.
stdout
.
write
(
'Nothing to do here.'
)
ecommerce/extensions/offer/tests/test_commands.py
deleted
100644 → 0
View file @
551e6b04
from
__future__
import
unicode_literals
from
StringIO
import
StringIO
from
django.core.management
import
call_command
from
oscar.core.loading
import
get_model
from
oscar.test
import
factories
from
ecommerce.tests.testcases
import
TestCase
ConditionalOffer
=
get_model
(
'offer'
,
'ConditionalOffer'
)
Voucher
=
get_model
(
'voucher'
,
'Voucher'
)
class
SetMaxApplicationsToNoneCommandTest
(
TestCase
):
command
=
'set_max_applications_to_none'
filter_condition
=
{
'max_global_applications'
:
1
,
'vouchers__usage'
:
Voucher
.
SINGLE_USE
}
def
call_command_and_return_output
(
self
):
output
=
StringIO
()
call_command
(
self
.
command
,
stdout
=
output
)
return
output
def
test_command_on_one_sample
(
self
):
"""Verify the command changes single use vouchers offer with max_global_applications value set to one."""
offer
=
factories
.
ConditionalOfferFactory
(
max_global_applications
=
1
)
voucher
=
factories
.
VoucherFactory
(
usage
=
Voucher
.
SINGLE_USE
)
voucher
.
offers
.
add
(
offer
)
self
.
assertEqual
(
ConditionalOffer
.
objects
.
filter
(
**
self
.
filter_condition
)
.
count
(),
1
)
output
=
self
.
call_command_and_return_output
()
actual_output
=
output
.
getvalue
()
.
strip
()
self
.
assertTrue
(
actual_output
.
startswith
(
'Setting max_global_applications field to None for ConditionalOffer [{}]...'
.
format
(
offer
)
))
self
.
assertTrue
(
actual_output
.
endswith
(
'Done.'
))
self
.
assertEqual
(
ConditionalOffer
.
objects
.
filter
(
**
self
.
filter_condition
)
.
count
(),
0
)
def
test_command_without_sample
(
self
):
"""Verify the command is only showing a message when no queryset is found."""
self
.
assertEqual
(
ConditionalOffer
.
objects
.
filter
(
**
self
.
filter_condition
)
.
count
(),
0
)
output
=
self
.
call_command_and_return_output
()
self
.
assertEqual
(
'Nothing to do here.'
,
output
.
getvalue
()
.
strip
())
self
.
assertEqual
(
ConditionalOffer
.
objects
.
filter
(
**
self
.
filter_condition
)
.
count
(),
0
)
def
test_command_only_target_single_use_vouchers
(
self
):
"""Verify the command doesn't target multi-use vouchers."""
offer
=
factories
.
ConditionalOfferFactory
(
max_global_applications
=
1
)
voucher
=
factories
.
VoucherFactory
(
usage
=
Voucher
.
MULTI_USE
)
voucher
.
offers
.
add
(
offer
)
output
=
self
.
call_command_and_return_output
()
self
.
assertEqual
(
'Nothing to do here.'
,
output
.
getvalue
()
.
strip
())
unaffected_offer
=
ConditionalOffer
.
objects
.
get
(
id
=
offer
.
id
)
self
.
assertEqual
(
unaffected_offer
.
max_global_applications
,
1
)
self
.
assertEqual
(
unaffected_offer
.
vouchers
.
first
()
.
usage
,
Voucher
.
MULTI_USE
)
ecommerce/invoice/management/__init__.py
deleted
100644 → 0
View file @
551e6b04
ecommerce/invoice/management/commands/__init__.py
deleted
100644 → 0
View file @
551e6b04
ecommerce/invoice/management/commands/populate_invoice_orders.py
deleted
100644 → 0
View file @
551e6b04
import
logging
from
django.core.management
import
BaseCommand
from
oscar.core.loading
import
get_model
from
ecommerce.core.models
import
BusinessClient
from
ecommerce.invoice.models
import
Invoice
logger
=
logging
.
getLogger
(
__name__
)
Order
=
get_model
(
'order'
,
'Order'
)
class
Command
(
BaseCommand
):
"""
Populate the order field for all invoices from the basket order,
and set the basket values to None. Creates a new business client object
from the basket owner username value and assigns it to the invoice if there
is not one assigned already.
"""
ch
=
logging
.
StreamHandler
()
ch
.
setLevel
(
logging
.
DEBUG
)
logger
.
addHandler
(
ch
)
def
handle
(
self
,
*
args
,
**
options
):
for
invoice
in
Invoice
.
objects
.
all
():
if
invoice
.
basket
:
try
:
order
=
Order
.
objects
.
get
(
basket
=
invoice
.
basket
)
invoice
.
order
=
order
if
not
invoice
.
business_client
:
invoice
.
business_client
,
__
=
BusinessClient
.
objects
.
get_or_create
(
name
=
invoice
.
basket
.
owner
.
username
)
invoice
.
basket
=
None
invoice
.
save
()
logger
.
info
(
'Order [
%
d] saved to invoice [
%
d].'
,
order
.
id
,
invoice
.
id
)
except
Order
.
DoesNotExist
:
logger
.
info
(
'Order for basket [
%
s] does not exist.'
,
invoice
.
basket
)
ecommerce/invoice/management/commands/squash_duplicate_invoices.py
deleted
100644 → 0
View file @
551e6b04
import
logging
from
django.core.management
import
BaseCommand
from
ecommerce.extensions.catalogue.models
import
Product
from
ecommerce.invoice.models
import
Invoice
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
"""
Squash duplicate invoices for coupon orders.
When we moved from re-using a coupon some of them had already more than one invoice,
and we are not having that! Monogamy rulez here, yerr damn hippies!
"""
ch
=
logging
.
StreamHandler
()
ch
.
setLevel
(
logging
.
DEBUG
)
logger
.
addHandler
(
ch
)
def
handle
(
self
,
*
args
,
**
options
):
for
coupon
in
Product
.
objects
.
filter
(
product_class__name
=
'Coupon'
):
qs
=
Invoice
.
objects
.
filter
(
order__lines__product
=
coupon
)
.
order_by
(
'created'
)
if
qs
.
count
()
>
1
:
qs
.
exclude
(
pk
=
qs
.
first
()
.
id
)
.
delete
()
logger
.
info
(
'Deleted douplicate invoices of coupon
%
s'
,
coupon
.
id
)
ecommerce/invoice/tests.py
View file @
3e158fb0
from
django.core.management
import
call_command
from
oscar.core.loading
import
get_model
from
oscar.test
import
factories
from
oscar.test
import
factories
from
ecommerce.core.models
import
BusinessClient
from
ecommerce.invoice.models
import
Invoice
from
ecommerce.invoice.models
import
Invoice
from
ecommerce.tests.testcases
import
TestCase
from
ecommerce.tests.testcases
import
TestCase
Order
=
get_model
(
'order'
,
'Order'
)
class
InvoiceTests
(
TestCase
):
class
InvoiceTests
(
TestCase
):
"""Test to ensure Invoice objects are created correctly"""
"""Test to ensure Invoice objects are created correctly"""
...
@@ -30,103 +25,3 @@ class InvoiceTests(TestCase):
...
@@ -30,103 +25,3 @@ class InvoiceTests(TestCase):
def
test_total
(
self
):
def
test_total
(
self
):
"""Test to check invoice total"""
"""Test to check invoice total"""
self
.
assertEqual
(
self
.
basket
.
order
.
total_incl_tax
,
self
.
invoice
.
total
)
self
.
assertEqual
(
self
.
basket
.
order
.
total_incl_tax
,
self
.
invoice
.
total
)
class
PopulateInvoiceOrdersCommandTests
(
TestCase
):
"""Tests for the populate_invoice_orders command."""
def
setUp
(
self
):
super
(
PopulateInvoiceOrdersCommandTests
,
self
)
.
setUp
()
self
.
order
=
factories
.
OrderFactory
()
self
.
basket
=
factories
.
BasketFactory
()
self
.
basket
.
owner
=
factories
.
UserFactory
()
self
.
basket
.
save
()
def
test_order_populated
(
self
):
"""Verify the order field is populated and basket set to None."""
self
.
order
.
basket
=
self
.
basket
self
.
order
.
save
()
invoice_before
=
Invoice
.
objects
.
create
(
basket
=
self
.
basket
)
self
.
assertIsNone
(
invoice_before
.
order
)
call_command
(
'populate_invoice_orders'
)
invoice_after
=
Invoice
.
objects
.
first
()
self
.
assertIsNone
(
invoice_after
.
basket
)
self
.
assertEqual
(
invoice_after
.
order
,
self
.
order
)
def
test_non_existing_order
(
self
):
"""Verify the invoice is not altered if no order exists."""
self
.
assertIsNone
(
self
.
order
.
basket
)
invoice_before
=
Invoice
.
objects
.
create
(
basket
=
self
.
basket
)
invoice_before_no_basket
=
Invoice
.
objects
.
create
()
self
.
assertIsNone
(
invoice_before
.
order
)
self
.
assertIsNone
(
invoice_before_no_basket
.
order
)
call_command
(
'populate_invoice_orders'
)
invoices_after
=
Invoice
.
objects
.
all
()
self
.
assertEqual
(
invoices_after
.
count
(),
2
)
self
.
assertIsNone
(
invoices_after
.
first
()
.
order
)
self
.
assertIsNone
(
invoices_after
.
last
()
.
order
)
self
.
assertEqual
(
invoices_after
.
get
(
id
=
invoice_before
.
id
)
.
basket
,
self
.
basket
)
def
test_client_changed
(
self
):
"""Verify the business client value is added if it doesn't exist."""
self
.
assertIsNotNone
(
self
.
basket
.
owner
)
self
.
order
.
basket
=
self
.
basket
self
.
order
.
save
()
invoice_before
=
Invoice
.
objects
.
create
(
basket
=
self
.
basket
)
self
.
assertIsNone
(
invoice_before
.
business_client
)
self
.
assertEqual
(
BusinessClient
.
objects
.
count
(),
0
)
call_command
(
'populate_invoice_orders'
)
invoice_after
=
Invoice
.
objects
.
first
()
self
.
assertEqual
(
BusinessClient
.
objects
.
count
(),
1
)
self
.
assertEqual
(
invoice_after
.
business_client
,
BusinessClient
.
objects
.
first
())
def
test_client_unchanged
(
self
):
"""Verify the business client value is unchanged if it exist."""
self
.
order
.
basket
=
self
.
basket
self
.
order
.
save
()
business_client
=
BusinessClient
.
objects
.
create
(
name
=
'Tester'
)
Invoice
.
objects
.
create
(
basket
=
self
.
basket
,
business_client
=
business_client
)
call_command
(
'populate_invoice_orders'
)
invoice_after
=
Invoice
.
objects
.
first
()
self
.
assertEqual
(
invoice_after
.
business_client
,
business_client
)
class
SquashDuplicateInvoicesCommandTests
(
TestCase
):
"""Tests for the squash_duplicate_invoices command."""
def
setUp
(
self
):
super
(
SquashDuplicateInvoicesCommandTests
,
self
)
.
setUp
()
coupon_pc
=
factories
.
ProductClassFactory
(
name
=
'Coupon'
)
self
.
product
=
factories
.
ProductFactory
(
product_class
=
coupon_pc
)
self
.
basket
=
factories
.
BasketFactory
()
self
.
basket
.
add_product
(
self
.
product
,
1
)
self
.
order
=
factories
.
create_order
(
basket
=
self
.
basket
)
self
.
invoice
=
Invoice
.
objects
.
create
(
order
=
self
.
order
)
def
assert_unique_invoice
(
self
,
product
,
invoice
):
"""Helper method for asserting there is only one invoice for given product."""
invoice_qs
=
Invoice
.
objects
.
filter
(
order__lines__product
=
product
)
self
.
assertEqual
(
invoice_qs
.
count
(),
1
)
self
.
assertEqual
(
invoice_qs
.
first
(),
invoice
)
def
test_squashing_invoices
(
self
):
"""Verify after calling the command the duplicate invoices are squashed."""
Invoice
.
objects
.
create
(
order
=
self
.
order
)
self
.
assertEqual
(
Invoice
.
objects
.
filter
(
order__lines__product
=
self
.
product
)
.
count
(),
2
)
call_command
(
'squash_duplicate_invoices'
)
self
.
assert_unique_invoice
(
self
.
product
,
self
.
invoice
)
def
test_not_squashing_invoices
(
self
):
"""Verify the non-duplicate invoices are left the same."""
self
.
assertEqual
(
Invoice
.
objects
.
filter
(
order__lines__product
=
self
.
product
)
.
count
(),
1
)
call_command
(
'squash_duplicate_invoices'
)
self
.
assert_unique_invoice
(
self
.
product
,
self
.
invoice
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment