Skip to content

Commit

Permalink
Merge branch 'master' into feature_promoting_hosted_lessons
Browse files Browse the repository at this point in the history
  • Loading branch information
f213 committed Dec 29, 2016
2 parents 875b0b2 + 63b214d commit 4aac814
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 79 deletions.
5 changes: 0 additions & 5 deletions acc/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def __init__(self, *args, **kwargs):
self.backend = kwargs['backend']

def run(self):
customer = Customer()
customer.save()

self.user.crm = customer

self.save_social_source()

self.fetch_picture()
Expand Down
7 changes: 4 additions & 3 deletions acc/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from os.path import basename, join

import responses
from mixer.backend.django import mixer

from elk.utils.testing import ClientTestCase, TestCase, create_user
from elk.utils.testing import ClientTestCase, TestCase

from .pipelines import SaveSocialProfile

Expand Down Expand Up @@ -39,7 +40,7 @@ def test_fetch_picture(self):
self.assertIsNotNone(profile_saver.profile_picture.read())

def test_save_source(self):
user = create_user()
user = mixer.blend('auth.User')

class TestBackend:
name = 'social-test-source-name'
Expand All @@ -51,7 +52,7 @@ class TestBackend:
self.assertEqual(user.crm.source, 'social-test-source-name')

def test_save_picture(self):
user = create_user()
user = mixer.blend('auth.user')
responses.add(responses.GET,
'http://testing.test/testpic.jpg',
body=b'testbytes',
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ machine:
version: 3.4.3

node:
version: 4.2.6
version: 6.1.0

services:
- redis
Expand Down
27 changes: 27 additions & 0 deletions crm/migrations/0023_user_field_is_mandatory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models


def drop_customer_profiles_without_user(apps, schema_editor):
Customer = apps.get_model('crm.Customer')
Customer.objects.filter(user__isnull=True).delete()


class Migration(migrations.Migration):

dependencies = [
('crm', '0022_auto_20161220_1234'),
]

operations = [
migrations.RunSQL('SET CONSTRAINTS ALL IMMEDIATE'),
migrations.RunPython(drop_customer_profiles_without_user),
migrations.AlterField(
model_name='customer',
name='user',
field=models.OneToOneField(to=settings.AUTH_USER_MODEL, related_name='crm'),
),
]
2 changes: 1 addition & 1 deletion crm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Customer(models.Model):
('subscription-finished', "user's subscription has finished, but he has some non-subscription-lessons"),
)

user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True, related_name='crm')
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='crm')

curator = models.ForeignKey('teachers.Teacher', on_delete=models.SET_NULL, null=True, blank=True, related_name='patronized_customers')
company = models.ForeignKey(Company, on_delete=models.SET_NULL, null=True, blank=True, related_name='customers')
Expand Down
19 changes: 19 additions & 0 deletions crm/signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.apps import apps
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import Signal, receiver

from mailer.owl import Owl
Expand All @@ -16,3 +19,19 @@ def notify_new_customer_about_trial_lesson(sender, **kwargs):
timezone=sender.timezone,
)
owl.send()


@receiver(post_save, sender=User, dispatch_uid='create_profile_for_new_users')
def create_profile_for_new_users(sender, **kwargs):
if not kwargs['created']:
return

user = kwargs['instance']
Customer = apps.get_model('crm.Customer')
try:
if user.crm is not None:
return
except Customer.DoesNotExist:
pass

Customer.objects.create(user=user)
26 changes: 18 additions & 8 deletions crm/tests/unit/tests_customer.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
from django.core.exceptions import ValidationError
from mixer.backend.django import mixer

from crm.models import Customer
from elk.utils.testing import TestCase, create_customer
from lessons import models as lessons
from market.models import Class


class CustomerTestCase(TestCase):
fixtures = ('crm',)
# fixtures = ('crm',)

def test_username(self):
def test_user_model(self):
"""
Customer objects with assigned django user should take user data from
the django table.
"""
customer_with_user = Customer.objects.get(pk=1)
self.assertEqual(customer_with_user.full_name, 'Fedor Borshev')
self.assertEqual(customer_with_user.first_name, 'Fedor')
self.assertEqual(customer_with_user.last_name, 'Borshev')
self.assertEqual(customer_with_user.email, '[email protected]')
customer = create_customer()

customer.user.first_name = 'Fedor'
customer.user.last_name = 'Borshev'
customer.user.email = '[email protected]'
customer.user.save()

self.assertEqual(customer.full_name, 'Fedor Borshev')
self.assertEqual(customer.first_name, 'Fedor')
self.assertEqual(customer.last_name, 'Borshev')
self.assertEqual(customer.email, '[email protected]')

def test_can_cancel_classes(self):
customer = create_customer()
Expand Down Expand Up @@ -66,3 +72,7 @@ def test_get_absolute_url(self):
url = c.get_absolute_url()
self.assertIn(str(c.pk), url)
self.assertIn('/admin/', url)

def test_customer_profile_automaticaly_emerges_when_creating_stock_django_user(self):
u = mixer.blend('auth.User')
self.assertIsNotNone(u.crm)
1 change: 0 additions & 1 deletion elk/templates/admin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<link rel="stylesheet" href="{% static 'css/admin.css' %}?rev={{ REVISION }}">
{% endblock %}


{% block suit_jquery %}
<!-- Please checkout this version if you've updated django-suit -->
<script src="{% static 'suit/js/jquery-2.2.4.min.js' %}"></script>
Expand Down
Empty file removed elk/tests/smoke/__init__.py
Empty file.
6 changes: 0 additions & 6 deletions elk/tests/smoke/tests_admin.py

This file was deleted.

4 changes: 2 additions & 2 deletions elk/tests/unit/tests_bundled_admin_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.admin.models import LogEntry

from elk.logging import write_admin_log_entry
from elk.utils.testing import TestCase, create_customer, create_user
from elk.utils.testing import TestCase, create_customer
from lessons import models as lessons


Expand All @@ -19,7 +19,7 @@ def test_write_admin_log_entry(self):
lesson_type=lessons.OrdinaryLesson.get_contenttype()
)

user = create_user()
user = create_customer().user
write_admin_log_entry(user, c, msg='Testing')

log_entry = LogEntry.objects.first()
Expand Down
8 changes: 1 addition & 7 deletions elk/tests/unit/tests_fixture_generator.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from django.apps import apps

from elk.utils.testing import TestCase, create_customer, create_teacher, create_user
from elk.utils.testing import TestCase, create_customer, create_teacher


class TestFixtures(TestCase):
"""
Test if my fixtures helper generates fixtures with correct relations
"""
def test_create_user(self):
User = apps.get_model('auth.user')
user = create_user()
self.assertEquals(User.objects.get(username=user.username), user)
self.assertIsNotNone(user.crm)

def test_create_customer(self):
Customer = apps.get_model('crm.customer')
customer = create_customer()
Expand Down
29 changes: 8 additions & 21 deletions elk/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,21 @@ def __add_working_hours_24x7(teacher):
)


def create_user(**kwargs):
def create_customer(password=None, **kwargs):
"""
Generate a simple user object.
You can pass `mixer<https://github.com/klen/mixer>` keyword arguments for :model:`crm.Customer`
or 'password' argument if you want to log in with this user
Generate a simple customer object.
"""
user = mixer.blend('auth.user')

if kwargs.get('password'):
user.set_password(kwargs.pop('password'))
if password is not None:
user.set_password(password)
user.save()

user.crm = create_customer(user=user, **kwargs)

return user

if(kwargs):
for attr, value in kwargs.items():
setattr(user.crm, attr, value)

def create_customer(user=None, **kwargs):
"""
Generate a simple customer object.
"""
if user is None:
user = create_user(**kwargs)
else:
kwargs['timezone'] = kwargs.get('timezone', 'Europe/Moscow') # the timezone value here deffers from default one in settings.py for early timezone error detection
mixer.blend('crm.customer', user=user, **kwargs)
user.crm.save()

return user.crm

Expand Down Expand Up @@ -167,7 +155,6 @@ class SuperUserTestCaseMixin():
@classmethod
def _generate_superuser(cls):
cls.superuser = User.objects.create_superuser('root', '[email protected]', 'ohGh7jai4Cee')
create_customer(user=cls.superuser)
cls.superuser_login = 'root'
cls.superuser_password = 'ohGh7jai4Cee' # store, if children will need it

Expand Down
2 changes: 1 addition & 1 deletion history/tests_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class TestEvent(TestCase):
fixtures = ('crm', 'products', 'lessons')
fixtures = ('products', 'lessons')
TEST_PRODUCT_ID = 1

def test_storing_request(self):
Expand Down
2 changes: 1 addition & 1 deletion market/tests/functional/tests_buy_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class BuySubscriptionTestCase(TestCase):
fixtures = ('crm', 'lessons', 'products')
fixtures = ('lessons', 'products')
TEST_PRODUCT_ID = 1

def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion market/tests/functional/tests_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@freeze_time('2005-12-01 01:30')
class ScheduleTestCase(TestCase):
fixtures = ('crm', 'lessons')
fixtures = ['lessons']

def setUp(self):
self.host = create_teacher(works_24x7=True)
Expand Down
2 changes: 1 addition & 1 deletion market/tests/unit/tests_buyable_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class testBuyable(TestCase):
fixtures = ('crm', 'lessons', 'products')
fixtures = ('lessons', 'products')
TEST_PRODUCT_ID = 1

def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions market/tests/unit/tests_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib.admin.models import LogEntry

from elk.utils.testing import TestCase, create_customer, create_teacher, create_user
from elk.utils.testing import TestCase, create_customer, create_teacher
from lessons import models as lessons
from market import signals
from market.models import Class, Subscription
Expand All @@ -19,7 +19,7 @@ def setUp(self):
product=Product1.objects.get(pk=1),
buy_price=150,
)
self.deactivator = create_user()
self.deactivator = create_customer().user

def test_deactivation_signal_is_beeing_sent(self):
handler = MagicMock()
Expand Down
2 changes: 1 addition & 1 deletion products/tests/unit/tests_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestSubscriptionDisplayTestCase(TestCase):
fixtures = ('crm', 'lessons', 'products')
fixtures = ('lessons', 'products')

def setUp(self):
self.product = Product1.objects.get(pk=1)
Expand Down
12 changes: 0 additions & 12 deletions teachers/fixtures/teachers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,3 @@
permissions: []
model: auth.group
pk: 2
- fields:
allowed_lessons: [4, 5, 6, 7, 8]
announce: Admin is a test teacher, that i created to test stuff
user: 1
model: teachers.teacher
pk: 1
- fields: {end: '19:00:00+00:00', start: '08:00:00+00:00', teacher: 1, weekday: 0}
model: teachers.workinghours
pk: 1
- fields: {end: '19:00:00+00:00', start: '15:00:00+00:00', teacher: 1, weekday: 1}
model: teachers.workinghours
pk: 2
7 changes: 4 additions & 3 deletions teachers/tests/functional/tests_teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@


class TestTeacherFunctional(TestCase):
fixtures = ('crm', 'teachers', 'lessons')
fixtures = ['teachers']

def setUp(self):
self.teacher = create_teacher(accepts_all_lessons=False)
@classmethod
def setUpTestData(cls):
cls.teacher = create_teacher(accepts_all_lessons=False)

def test_automatic_group_assignment(self):
"""
Expand Down
2 changes: 0 additions & 2 deletions timeline/tests/unit/tests_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

@freeze_time('2005-05-03 12:41')
class EntryTestCase(TestCase):
fixtures = ('crm',)

def setUp(self):
self.teacher1 = create_teacher(works_24x7=True)
self.teacher2 = create_teacher(works_24x7=True)
Expand Down

0 comments on commit 4aac814

Please sign in to comment.