Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
KawowyDzienniczek
Project
Project
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
Rafal
KawowyDzienniczek
Commits
ba71abf6
Commit
ba71abf6
authored
Jul 25, 2016
by
lizonr1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests
parent
1c081ea8
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
125 additions
and
31 deletions
+125
-31
init_products.py
...niczek/App/loyaltyMe/management/commands/init_products.py
+2
-7
init_tasks.py
...ienniczek/App/loyaltyMe/management/commands/init_tasks.py
+10
-6
products.py
KawowyDzienniczek/App/loyaltyMe/test_data/products.py
+12
-0
test_models.py
KawowyDzienniczek/App/loyaltyMe/test_models.py
+23
-4
test_serializers.py
KawowyDzienniczek/App/loyaltyMe/test_serializers.py
+20
-0
init_users.py
KawowyDzienniczek/App/user/management/commands/init_users.py
+3
-6
init_usertasks.py
...zienniczek/App/user/management/commands/init_usertasks.py
+9
-8
users.py
KawowyDzienniczek/App/user/test_data/users.py
+6
-0
test_serializers.py
KawowyDzienniczek/App/user/test_serializers.py
+40
-0
No files found.
KawowyDzienniczek/App/loyaltyMe/management/commands/init_products.py
View file @
ba71abf6
from
django.core.management.base
import
BaseCommand
from
App.loyaltyMe.models
import
Product
from
App.loyaltyMe.test_data.products
import
PRODUCTS_SAMPLE_DATA
class
Command
(
BaseCommand
):
help
=
'Closes the specified poll for voting'
def
handle
(
self
,
*
args
,
**
options
):
products
=
[
# ['name', 'description', 'price', 'img' ],
[
'Kawa Latte'
,
'Z nutą czekolady'
,
'7 zł'
,
'/static/img/photo_1.jpg'
],
[
'Herbata'
,
'Z nutą czekolady'
,
'4 zł'
,
'/static/img/photo_1.jpg'
],
[
'Ciasto'
,
'Z nutą czekolady'
,
'5 zł'
,
'/static/img/photo_1.jpg'
],
[
'Espresso'
,
'Mała czarna'
,
'5 zł'
,
'/static/img/photo_1.jpg'
],
]
products
=
PRODUCTS_SAMPLE_DATA
print
(
"Creating Products"
)
for
product
in
products
:
print
(
'Create {0}'
.
format
(
product
[
0
]))
...
...
KawowyDzienniczek/App/loyaltyMe/management/commands/init_tasks.py
View file @
ba71abf6
import
datetime
from
datetime
import
datetime
,
timedelta
from
django.core.management.base
import
BaseCommand
...
...
@@ -9,18 +9,22 @@ class Command(BaseCommand):
help
=
'Closes the specified poll for voting'
def
handle
(
self
,
*
args
,
**
options
):
tasks
=
[
# 'name',products
[
'Bądź u nas 10 godzin'
,
datetime
.
datetime
.
now
(),
'description'
,
'TM'
,
datetime
.
timedelta
(
seconds
=
15
)
,
15
,
15
,
datetime
.
timedelta
(
seconds
=
15
)],
[
'Przyjdz 10 razy'
,
datetime
.
datetime
.
now
(),
'description'
,
'PR'
,
datetime
.
timedelta
(
seconds
=
15
)
,
15
,
15
,
datetime
.
timedelta
(
seconds
=
15
)],
[
'Bądź u nas 10 godzin'
,
timedelta
(
seconds
=
10
),
'description'
,
'TM'
,
4
,
15
,
15
,
timedelta
(
seconds
=
15
)],
[
'Przyjdz 10 razy'
,
timedelta
(
seconds
=
10
),
'description'
,
'TM'
,
4
,
15
,
15
,
timedelta
(
seconds
=
15
)],
]
print
(
"Creating Tasks"
)
for
task
in
tasks
:
print
(
'Create {0}'
.
format
(
task
[
0
]))
new_task
=
Task
.
objects
.
create
(
name
=
task
[
0
],
update_delay
=
task
[
1
],
description
=
task
[
2
],
type
=
task
[
3
],
counter_target
=
task
[
4
],
beacon_counter_target
=
task
[
5
],
counter_incrementation
=
task
[
6
],
beacon_signal_delay
=
task
[
7
])
new_task
.
save
()
KawowyDzienniczek/App/loyaltyMe/test_data/products.py
0 → 100644
View file @
ba71abf6
PRODUCTS_SAMPLE_DATA
=
[
# ['name', 'description', 'price', 'img' ],
{
'name'
:
'Kawa Latte'
,
'description'
:
'Z nutą czekolady'
,
'price'
:
'7 zł'
,
'img'
:
'/static/img/photo_1.jpg'
},
{
'name'
:
'Herbata'
,
'description'
:
'Z nutą czekolady'
,
'price'
:
'4 zł'
,
'img'
:
'/static/img/photo_1.jpg'
},
{
'name'
:
'Ciasto'
,
'description'
:
'Z nutą czekolady'
,
'price'
:
'5 zł'
,
'img'
:
'/static/img/photo_1.jpg'
},
{
'name'
:
'Espresso'
,
'description'
:
'Mała czarna'
,
'price'
:
'5 zł'
,
'img'
:
'/static/img/photo_1.jpg'
},
]
PRODUCTS_SAMPLE_SERIALIZED_DATA
=
[
# ['name', 'description', 'price', 'img' ],
{
'description'
:
'Z nutą czekolady'
,
'url'
:
'http://testserver/api/products/1/'
,
'img'
:
'http://testserver/static/img/photo_1.jpg'
,
'price'
:
'7 zł'
,
'id'
:
1
,
'name'
:
'Kawa Latte'
},
]
KawowyDzienniczek/App/loyaltyMe/test_models.py
View file @
ba71abf6
...
...
@@ -10,10 +10,10 @@ from App.user.models import UserTask
class
TaskTestCase
(
TestCase
):
def
setUp
(
self
):
Task
.
objects
.
get_or_create
(
type
=
"TM"
,
update_delay
=
timedelta
(
seconds
=
10
),
description
=
"Test_description"
,
name
=
"test_name"
,
counter_target
=
5
,
beacon_counter_target
=
5
,
counter_incrementation
=
1
,
beacon_signal_delay
=
timedelta
(
seconds
=
10
))
self
.
task
=
Task
.
objects
.
get_or_create
(
type
=
"TM"
,
update_delay
=
timedelta
(
seconds
=
10
),
description
=
"Test_description"
,
name
=
"test_name"
,
counter_target
=
1
,
beacon_counter_target
=
2
,
counter_incrementation
=
1
,
beacon_signal_delay
=
timedelta
(
seconds
=
15
))[
0
]
class
UserTaskTestCase
(
TestCase
):
...
...
@@ -118,3 +118,22 @@ class UserTaskTestCase(TestCase):
result
=
self
.
user_task
.
update
()
self
.
assertTrue
(
self
.
user_task
.
done
)
self
.
assertTrue
(
result
)
def
test_update_test_not_ready_to_update
(
self
):
self
.
user_task
.
signal_last_update
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
signal_delay
=
datetime
.
now
()
-
timedelta
(
seconds
=
14
)
result
=
self
.
user_task
.
update
()
self
.
assertFalse
(
result
)
def
test_update_test_task_is_done
(
self
):
self
.
set_data_task_signal_passed
()
self
.
set_data_beacon_singal_passed
()
self
.
user_task
.
beacon_counter
=
0
self
.
user_task
.
task
.
beacon_counter_target
=
1
self
.
user_task
.
counter
=
0
self
.
user_task
.
task
.
counter_target
=
1
self
.
user_task
.
done
=
True
result
=
self
.
user_task
.
update
()
self
.
assertFalse
(
result
)
\ No newline at end of file
KawowyDzienniczek/App/loyaltyMe/test_serializers.py
0 → 100644
View file @
ba71abf6
from
django.test
import
TestCase
,
RequestFactory
from
rest_framework.test
import
APIRequestFactory
# Using the standard RequestFactory API to create a form POST request
from
App.loyaltyMe.models
import
Product
from
App.loyaltyMe.serializers
import
ProductSerializer
from
App.loyaltyMe.test_data.products
import
PRODUCTS_SAMPLE_DATA
,
PRODUCTS_SAMPLE_SERIALIZED_DATA
class
ProductSerializerTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
product_data
=
PRODUCTS_SAMPLE_DATA
[
0
]
self
.
product_data_serialized
=
PRODUCTS_SAMPLE_SERIALIZED_DATA
[
0
]
self
.
product
=
Product
.
objects
.
create
(
**
self
.
product_data
)
def
test_serializer
(
self
):
context
=
dict
(
request
=
RequestFactory
()
.
get
(
'/'
))
serializer
=
ProductSerializer
(
self
.
product
,
context
=
context
)
self
.
assertEqual
(
serializer
.
data
,
self
.
product_data_serialized
)
\ No newline at end of file
KawowyDzienniczek/App/user/management/commands/init_users.py
View file @
ba71abf6
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
from
App.user.test_data.users
import
USERS_SAMPLE_DATA
class
Command
(
BaseCommand
):
help
=
'Closes the specified poll for voting'
def
handle
(
self
,
*
args
,
**
options
):
users
=
[
[
'admin'
,
'admin'
,
'admin@gmail.com'
,
],
[
'Antek'
,
'Antek'
,
'antek@gmail.com'
],
[
'Rafal'
,
'Rafal'
,
'rafal@gmail.com'
],
[
'Klaudia'
,
'Klaudia'
,
'klaudia@gmail.com'
]
]
users
=
USERS_SAMPLE_DATA
print
(
"Creating Users"
)
for
user
in
users
:
print
(
'Create {0}'
.
format
(
user
[
0
]))
...
...
KawowyDzienniczek/App/user/management/commands/init_usertasks.py
View file @
ba71abf6
...
...
@@ -10,10 +10,10 @@ from App.user.models import UserTask
class
Command
(
BaseCommand
):
def
handle
(
self
,
*
args
,
**
options
):
data
=
[
[
'Bądź u nas 10 godzin'
,
'admin'
,
True
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetime
.
now
()],
[
'Bądź u nas 10 godzin'
,
'Klaudia'
,
False
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetime
.
now
()],
[
'Przyjdz 10 razy'
,
'admin'
,
False
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetime
.
now
()],
[
'Przyjdz 10 razy'
,
'Antek'
,
True
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetime
.
now
()],
[
'Bądź u nas 10 godzin'
,
'admin'
,
True
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetime
.
now
()],
[
'Bądź u nas 10 godzin'
,
'Klaudia'
,
False
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetime
.
now
()],
[
'Przyjdz 10 razy'
,
'admin'
,
False
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetime
.
now
()],
[
'Przyjdz 10 razy'
,
'Antek'
,
True
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetime
.
now
()],
]
print
(
"Creating UsersTasks"
)
...
...
@@ -21,8 +21,9 @@ class Command(BaseCommand):
print
(
"{0} take {1} Task"
.
format
(
user_task
[
0
],
user_task
[
1
]))
task
=
Task
.
objects
.
filter
(
name
=
user_task
[
0
])[
0
]
user
=
User
.
objects
.
filter
(
username
=
user_task
[
1
])[
0
]
counter
=
datetime
.
timedelta
(
seconds
=
user_task
[
4
])
beacon_counter
=
datetime
.
timedelta
(
seconds
=
user_task
[
5
])
new_usertask
=
UserTask
.
objects
.
create
(
task
=
task
,
user
=
user
,
done
=
user_task
[
2
],
last_update
=
user_task
[
3
],
counter
=
counter
,
beacon_counter
=
beacon_counter
,
beacon_signal_last_update
=
user_task
[
6
])
counter
=
user_task
[
4
]
beacon_counter
=
user_task
[
5
]
new_usertask
=
UserTask
.
objects
.
create
(
task
=
task
,
user
=
user
,
done
=
user_task
[
2
],
last_update
=
user_task
[
3
],
counter
=
counter
,
beacon_counter
=
beacon_counter
,
beacon_signal_last_update
=
user_task
[
6
])
new_usertask
.
save
()
KawowyDzienniczek/App/user/test_data/users.py
0 → 100644
View file @
ba71abf6
USERS_SAMPLE_DATA
=
[
[
'admin'
,
'admin'
,
'admin@gmail.com'
,
],
[
'Antek'
,
'Antek'
,
'antek@gmail.com'
],
[
'Rafal'
,
'Rafal'
,
'rafal@gmail.com'
],
[
'Klaudia'
,
'Klaudia'
,
'klaudia@gmail.com'
]
]
\ No newline at end of file
KawowyDzienniczek/App/user/test_serializers.py
0 → 100644
View file @
ba71abf6
import
rest_framework
from
django.test
import
TestCase
from
App.user.serializers
import
AuthTokenSerializerByEmail
from
django.contrib.auth.models
import
User
from
App.user.test_data.users
import
USERS_SAMPLE_DATA
class
AuthTokenSerializerByEmailTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
auth_by_email
=
AuthTokenSerializerByEmail
()
user
=
USERS_SAMPLE_DATA
[
0
]
self
.
test_user
=
User
.
objects
.
create_user
(
username
=
user
[
0
],
password
=
user
[
1
],
email
=
user
[
2
],
is_active
=
True
,
is_superuser
=
True
,
is_staff
=
True
,
)
self
.
test_user
.
save
()
def
test_success_validate
(
self
):
test
=
{
'email'
:
'admin@gmail.com'
,
'password'
:
'admin'
}
validation
=
self
.
auth_by_email
.
validate
(
test
)
self
.
assertIn
(
'user'
,
validation
)
def
test_fail_validate_wrong_password
(
self
):
test
=
{
'email'
:
'admin@gmail.com'
,
'password'
:
'admin12'
}
self
.
assertRaises
(
rest_framework
.
exceptions
.
ValidationError
,
self
.
auth_by_email
.
validate
,
test
)
def
test_fail_validate_user_not_exist
(
self
):
test
=
{
'email'
:
'admined2@gmail.com'
,
'password'
:
'admin12'
}
self
.
assertRaises
(
rest_framework
.
exceptions
.
ValidationError
,
self
.
auth_by_email
.
validate
,
test
)
def
test_fail_validate_lack_of_data
(
self
):
test
=
{
'email'
:
'admin@gmail.com'
,
}
self
.
assertRaises
(
rest_framework
.
exceptions
.
ValidationError
,
self
.
auth_by_email
.
validate
,
test
)
def
test_fail_validate_user_blocked
(
self
):
self
.
test_user
.
is_active
=
False
self
.
test_user
.
save
()
test
=
{
'email'
:
'admin@gmail.com'
,
'password'
:
'admin'
}
self
.
assertRaises
(
rest_framework
.
exceptions
.
ValidationError
,
self
.
auth_by_email
.
validate
,
test
)
\ No newline at end of file
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