Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KingCSharp committed Oct 3, 2017
0 parents commit 35bb590
Show file tree
Hide file tree
Showing 174 changed files with 21,592 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.pyc
*~
*.swo
*.swp
db.sqlite3
media
media-images
cache
.idea
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[![build status](http://git.micropyramid.com/mp/crm/badges/master/build.svg)](http://git.micropyramid.com/mp/crm/commits/master)
[![coverage report](http://git.micropyramid.com/mp/crm/badges/master/coverage.svg)](http://git.micropyramid.com/mp/crm/commits/master)

1. follow gitflow.
2. write code comments.
3. write tests cases for what ever you develop.
4. write good comments in git commits.
5. add lables to merge requests.
6. add lables to issues.
7. add issues in related merge requests.
8. discuss in gitlab issues.
9. think of security, performance and elegance as priorities.
10. use prospector
Empty file added accounts/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from accounts.models import Account
# Register your models here.


admin.site.register(Account)
5 changes: 5 additions & 0 deletions accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
name = 'accounts'
49 changes: 49 additions & 0 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django import forms
from .models import Account
from common.models import Address, Comment


class AccountForm(forms.ModelForm):

class Meta:
model = Account
fields = ['name', 'email', 'phone', 'website',
'industry', 'description', 'teams', 'assigned_to']
phone = forms.RegexField(regex=r'(^[0-9]{10,12}$)', error_messages={'invalid': ("Phone number must be Minimum of 10 Digits and Maximum of 12 Digits.")})


class BillingAddressForm(forms.ModelForm):

class Meta:
model = Address
exclude = []


class ShippingAddressForm(forms.ModelForm):
class Meta:
model = Address
exclude = []

def __init__(self, *args, **kwargs):
super(ShippingAddressForm, self).__init__(*args, **kwargs)


class CommentForm(forms.ModelForm):
comment = forms.CharField(max_length=64, required=True)

class Meta:
model = Comment
fields = ['comment', ]
exclude = ('comment_date', 'comment_user', 'accountid')


# class CountryBillingForm(forms.ModelForm):
# class Meta:
# model = Country
# fields = ['printable_name', ]


# class CountryShippingForm(forms.ModelForm):
# class Meta:
# model = Country
# fields = ['printable_name', ]
30 changes: 30 additions & 0 deletions accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-26 12:22
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Account',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=64, verbose_name='Name')),
('email', models.EmailField(max_length=254)),
('phone', models.CharField(max_length=20)),
('industry', models.CharField(blank=True, choices=[('ADVERTISING', 'ADVERTISING'), ('AGRICULTURE', 'AGRICULTURE'), ('APPAREL & ACCESSORIES', 'APPAREL & ACCESSORIES'), ('AUTOMOTIVE', 'AUTOMOTIVE'), ('BANKING', 'BANKING'), ('BIOTECHNOLOGY', 'BIOTECHNOLOGY'), ('BUILDING MATERIALS & EQUIPMENT', 'BUILDING MATERIALS & EQUIPMENT'), ('CHEMICAL', 'CHEMICAL'), ('COMPUTER', 'COMPUTER'), ('EDUCATION', 'EDUCATION'), ('ELECTRONICS', 'ELECTRONICS'), ('ENERGY', 'ENERGY'), ('ENTERTAINMENT & LEISURE', 'ENTERTAINMENT & LEISURE'), ('FINANCE', 'FINANCE'), ('FOOD & BEVERAGE', 'FOOD & BEVERAGE'), ('GROCERY', 'GROCERY'), ('HEALTHCARE', 'HEALTHCARE'), ('INSURANCE', 'INSURANCE'), ('LEGAL', 'LEGAL'), ('MANUFACTURING', 'MANUFACTURING'), ('PUBLISHING', 'PUBLISHING'), ('REAL ESTATE', 'REAL ESTATE'), ('SERVICE', 'SERVICE'), ('SOFTWARE', 'SOFTWARE'), ('SPORTS', 'SPORTS'), ('TECHNOLOGY', 'TECHNOLOGY'), ('TELECOMMUNICATIONS', 'TELECOMMUNICATIONS'), ('TELEVISION', 'TELEVISION'), ('TRANSPORTATION', 'TRANSPORTATION'), ('VENTURE CAPITAL', 'VENTURE CAPITAL')], max_length=255, null=True, verbose_name='Industry Type')),
('website', models.URLField(blank=True, null=True, verbose_name='Website')),
('description', models.TextField(blank=True, null=True)),
('created_on', models.DateTimeField(auto_now_add=True, verbose_name='Created on')),
('is_active', models.BooleanField(default=False)),
],
),
]
46 changes: 46 additions & 0 deletions accounts/migrations/0002_auto_20170926_1752.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-26 12:22
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('accounts', '0001_initial'),
('common', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='account',
name='assigned_to',
field=models.ManyToManyField(related_name='account_assigned_to', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='account',
name='billing_address',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='account_billing_address', to='common.Address'),
),
migrations.AddField(
model_name='account',
name='created_by',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='account_created_by', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='account',
name='shipping_address',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='account_shipping_address', to='common.Address'),
),
migrations.AddField(
model_name='account',
name='teams',
field=models.ManyToManyField(to='common.Team'),
),
]
Empty file added accounts/migrations/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.db import models
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _

from common.models import User, Address, Team
from common.utils import INDCHOICES


class Account(models.Model):
name = models.CharField(pgettext_lazy("Name of Account", "Name"), max_length=64)
email = models.EmailField()
phone = models.CharField(max_length=20)
industry = models.CharField(_("Industry Type"), max_length=255, choices=INDCHOICES, blank=True, null=True)
billing_address = models.ForeignKey(Address, related_name='account_billing_address', on_delete=models.CASCADE, blank=True, null=True)
shipping_address = models.ForeignKey(Address, related_name='account_shipping_address', on_delete=models.CASCADE, blank=True, null=True)
website = models.URLField(_("Website"), blank=True, null=True)
description = models.TextField(blank=True, null=True)
assigned_to = models.ManyToManyField(User, related_name='account_assigned_to')
teams = models.ManyToManyField(Team)
created_by = models.ForeignKey(User, related_name='account_created_by', on_delete=models.CASCADE)
created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
is_active = models.BooleanField(default=False)

def __str__(self):
return self.name
106 changes: 106 additions & 0 deletions accounts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from django.test import TestCase
from common.models import *
from accounts.models import Account
from django.contrib.auth.models import User


# Create your tests here.


class AccountCreateTest(object):
def setUp(self):
self.country = Country.objects.create(
iso_3166_1_a2="IN", iso_3166_1_a3="IND", iso_3166_1_numeric="01", printable_name="INDIA", name="INDIA", is_shipping_country="True")
self.address = Address.objects.create(
street="KPHB", city="HYDERABAD", state="ANDHRA PRADESH", postcode="500073", country=Country.objects.get(pk=1))
self.account = Account.objects.create(
name="Uday", email="[email protected]", phone="8333855552", billing_address=self.address,
shipping_address=self.address, website="www.uday.com", account_type="PARTNER",
sis_code="UDAYMP2016", industry="SOFTWARE", description="Yes.. Testing Done")
self.user = User.objects.create(username='uday')
self.user.set_password('uday2293')
self.user.save()
self.client.login(username='uday', password='uday2293')


class AccountsCreateUrlTestCase(AccountCreateTest, TestCase):
def test_account_create_url(self):
response = self.client.get('/accounts/create/', {
'name': "Uday", 'email': "[email protected]", 'phone': "", 'billing_address': self.address,
'shipping_address': self.address, 'website': "www.uday.com", 'account_type': "PARTNER",
'sis_code': "UDAYMP2016", 'industry': "SOFTWARE", 'description': "Yes.. Testing Done"})
self.assertEqual(response.status_code, 200)

def test_account_create_html(self):
response = self.client.get('/accounts/create/', {
'name': "Uday", 'email': "[email protected]", 'phone': "", 'billing_address': self.address,
'shipping_address': self.address, 'website': "www.uday.com", 'account_type': "PARTNER",
'sis_code': "UDAYMP2016", 'industry': "SOFTWARE", 'description': "Yes.. Testing Done"})
self.assertTemplateUsed(response, 'accounts/create_account.html')


class AccountCreateTestCase(AccountCreateTest, TestCase):
def test_account_create(self):
self.assertEqual(self.account.id, 1)


class AccountsListTestCase(AccountCreateTest, TestCase):
def test_accounts_list(self):
self.accounts = Account.objects.all()
response = self.client.get('/accounts/list/')
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'accounts/accounts.html')


class AccountsCountTestCase(AccountCreateTest, TestCase):
def test_accounts_list_count(self):
count = Account.objects.all().count()
self.assertEqual(count, 1)


class AccountsViewTestCase(AccountCreateTest, TestCase):
def test_accounts_view(self):
self.accounts = Account.objects.all()
response = self.client.get('/accounts/1/view/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['ac'].id, 1)
self.assertTemplateUsed(response, 'accounts/view_account.html')


class AccountsRemoveTestCase(AccountCreateTest, TestCase):
def test_accounts_remove(self):
# self.account_del = Account.objects.filter(id=1).delete()
response = self.client.get('/accounts/1/delete/')
self.assertEqual(response['location'], '/accounts/list/')

def test_accounts_remove_status(self):
Account.objects.filter(id=self.account.id).delete()
response = self.client.get('/accounts/list/')
self.assertEqual(response.status_code, 200)


class AccountsUpdateUrlTestCase(AccountCreateTest, TestCase):
def test_accounts_update(self):
response = self.client.get('/accounts/1/edit/', {
'name': "Uday", 'email': "[email protected]", 'phone': "8333855552", 'billing_address': self.address,
'shipping_address': self.address, 'website': "www.uday.com", 'account_type': "PARTNER",
'sis_code': "UDAYMP2016", 'industry': "SOFTWARE", 'description': "Yes.. Testing Done"})
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'accounts/create_account.html')

def test_accounts_update_status(self):
response = self.client.get('/accounts/1/edit/')
self.assertEqual(response.status_code, 200)

def tst_accounts_update_html(self):
response = self.client.get('/accounts/1/edit/')
self.assertTemplateUsed(response, 'accounts/create_account.html')


class AccountCreateEmptyFormTestCase(AccountCreateTest, TestCase):

def test_account_creation_invalid_data(self):
data = {'name': "", 'email': "", 'phone': "", 'billing_address': self.address, 'shipping_address': self.address,
'website': "", 'account_type': "", 'sis_code': "", 'industry': "", 'description': ""}
response = self.client.post('/accounts/create/', data)
self.assertEqual(response.status_code, 200)
17 changes: 17 additions & 0 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.conf.urls import url
from accounts import views

app_name = 'accounts'


urlpatterns = [
url(r'^list/$', views.account, name='list'),
url(r'^create/$', views.new_account, name='new_account'),
url(r'^(?P<aid>\d*)/view/$', views.view_account, name="view_account"),
url(r'^(?P<edid>\d*)/edit/$', views.edit_account, name="edit_account"),
url(r'^(?P<aid>\d*)/delete/$', views.remove_account, name="remove_account"),
url(r'^comment/add/$', views.comment_add, name='comment_add'),
url(r'^comment/remove/$', views.comment_remove, name='comment_remove'),
url(r'^comment/edit/$', views.comment_edit, name='comment_edit'),
url(r'^get/list/$', views.get_accounts, name='get_accounts'),
]
Loading

0 comments on commit 35bb590

Please sign in to comment.