This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rootart/ref-1
ref #1, Implement bonus/reward system and click statistics
- Loading branch information
Showing
17 changed files
with
497 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-11-02 19:38 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import referral_module.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('referral_module', '0003_auto_20171016_1258'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserReferrerStats', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('event_type', models.CharField(choices=[('click', 'click')], db_index=True, default=referral_module.models.StatsType('click'), max_length=50)), | ||
('ip', models.GenericIPAddressField()), | ||
('context', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)), | ||
('user_referrer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='referral_module.UserReferrer', verbose_name='stats')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='campaign', | ||
name='bonus_policy', | ||
field=django.contrib.postgres.fields.jsonb.JSONField(default=referral_module.models.default_bonus_policy), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-11-02 19:57 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('referral_module', '0004_auto_20171102_1938'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='userreferrerstats', | ||
options={'verbose_name': 'User referrer stats', 'verbose_name_plural': 'User referrer stats'}, | ||
), | ||
migrations.AddField( | ||
model_name='userreferrer', | ||
name='reward', | ||
field=models.DecimalField(decimal_places=3, default=0, max_digits=10), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.contrib.auth.models import User | ||
import factory as factory_boy | ||
|
||
from referral_module import models | ||
|
||
|
||
class UserFactory(factory_boy.DjangoModelFactory): | ||
username = factory_boy.Sequence(lambda n: 'user-{}'.format(n)) | ||
email = factory_boy.Sequence(lambda n: 'user-{}@moneypark.ch'.format(n)) | ||
|
||
class Meta: | ||
model = User | ||
|
||
|
||
class CampaignFactory(factory_boy.DjangoModelFactory): | ||
key = factory_boy.Sequence(lambda n: 'key-{}'.format(n)) | ||
is_active = True | ||
|
||
class Meta: | ||
model = models.Campaign | ||
|
||
|
||
class UserReferrerFactory(factory_boy.DjangoModelFactory): | ||
campaign = factory_boy.SubFactory(CampaignFactory) | ||
user = factory_boy.SubFactory(UserFactory) | ||
|
||
class Meta: | ||
model = models.UserReferrer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.test import TestCase | ||
|
||
from .factories import UserReferrerFactory | ||
|
||
|
||
class UserReferrerModelTestCase(TestCase): | ||
def test_key_autogeneration(self): | ||
user_referrer = UserReferrerFactory() | ||
self.assertTrue(user_referrer.key) | ||
|
||
user_referrer.key = None | ||
user_referrer.save() | ||
self.assertTrue(user_referrer.key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.test import TestCase | ||
|
||
from referral_module.utils import ChoiceEnum | ||
|
||
|
||
class ColorChoice(ChoiceEnum): | ||
green = 1 | ||
red = 2 | ||
|
||
|
||
class ChoicesEnumTestCase(TestCase): | ||
|
||
def test_choices_classmethod(self): | ||
assert ColorChoice.choices() == ( | ||
('green', 1), | ||
('red', 2) | ||
) | ||
assert ColorChoice.green.value == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
|
||
class CampaignListTestCase(TestCase): | ||
def setUp(self): | ||
self.url = reverse('campaign-list') | ||
|
||
def test_page_access(self): | ||
response = self.client.get(self.url) | ||
assert response.status_code == 200 | ||
self.assertTemplateUsed( | ||
response, | ||
'campaign/list.html' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from enum import Enum | ||
|
||
|
||
class ChoiceEnum(Enum): | ||
@classmethod | ||
def choices(cls): | ||
return tuple((x.name, x.value) for x in cls) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
django | ||
django-debug-toolbar | ||
django-extensions | ||
django-registration | ||
flake8 | ||
ipdb | ||
psycopg2 | ||
pyflakes | ||
werkzeug | ||
|
||
tox | ||
pytest | ||
pytest-cov | ||
pytest-django | ||
codecov | ||
factory_boy |
Oops, something went wrong.