diff options
author | shivam kohli <kohlishivam5522@gmail.com> | 2018-07-23 04:29:14 +0530 |
---|---|---|
committer | shivam kohli <kohlishivam5522@gmail.com> | 2018-07-23 04:29:14 +0530 |
commit | c60f075634178d2212364c842552c256f22dae92 (patch) | |
tree | 3bd06f4bf0b6fe497902229fb9acf480e6520c9a /inventory | |
parent | 94be0d7216ec3c5f253b895681b11e7b0678211a (diff) | |
download | codeless-c60f075634178d2212364c842552c256f22dae92.tar.gz codeless-c60f075634178d2212364c842552c256f22dae92.tar.bz2 codeless-c60f075634178d2212364c842552c256f22dae92.zip |
testcase added and improved user interface
Diffstat (limited to 'inventory')
-rw-r--r-- | inventory/forms.py | 18 | ||||
-rw-r--r-- | inventory/migrations/0002_merchant_website.py | 19 | ||||
-rw-r--r-- | inventory/models.py | 2 | ||||
-rw-r--r-- | inventory/tests.py | 68 | ||||
-rw-r--r-- | inventory/views.py | 63 |
5 files changed, 129 insertions, 41 deletions
diff --git a/inventory/forms.py b/inventory/forms.py index b4b35e6..1fbfa43 100644 --- a/inventory/forms.py +++ b/inventory/forms.py @@ -26,10 +26,20 @@ from django.contrib.auth.models import User from inventory.models import Merchant, Product +ADDRESS_CHOICES= [ + ('SEPA', 'sepa'), + ('UPI', 'upi'), + ('BITCOIN', 'bitcoin'), + ('ACH', 'ach'), + ] + + class SignUpForm(UserCreationForm): first_name = forms.CharField(max_length=30, required=False) last_name = forms.CharField(max_length=30, required=False) email = forms.EmailField(max_length=254) + website = forms.URLField(label='Enter website URL', max_length=250, required=False) + address = forms.CharField(label='What is your favorite fruit?', widget=forms.Select(choices=ADDRESS_CHOICES)) class Meta: model = User @@ -40,6 +50,8 @@ class SignUpForm(UserCreationForm): 'email', 'password1', 'password2', + 'address', + 'website' ) def __init__(self, *args, **kwargs): @@ -49,12 +61,6 @@ class SignUpForm(UserCreationForm): self.fields[fieldname].help_text = None -class MerchantDetailForm(forms.ModelForm): - class Meta: - model = Merchant - fields = ("address",) - - class LoginForm(forms.ModelForm): class Meta: model = User diff --git a/inventory/migrations/0002_merchant_website.py b/inventory/migrations/0002_merchant_website.py new file mode 100644 index 0000000..8cc270f --- /dev/null +++ b/inventory/migrations/0002_merchant_website.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('inventory', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='merchant', + name='website', + field=models.URLField(max_length=250, default='NULL'), + ), + ] diff --git a/inventory/models.py b/inventory/models.py index 9fc1539..a65142c 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -33,6 +33,8 @@ class Merchant(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) address = models.TextField() pay_url = models.URLField(max_length=250, default='NULL') + website = models.URLField(max_length=250, default='NULL') + def __str__(self): return self.user.username diff --git a/inventory/tests.py b/inventory/tests.py index 7ce503c..276cfdc 100644 --- a/inventory/tests.py +++ b/inventory/tests.py @@ -1,3 +1,69 @@ from django.test import TestCase +from django.test import LiveServerTestCase +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +import time -# Create your tests here. + +class SignUpTestCase(LiveServerTestCase): + + def setUp(self): + self.selenium = webdriver.Firefox(executable_path=r'/geckodriver') + super(SignUpTestCase, self).setUp() + + def tearDown(self): + self.selenium.quit() + super(SignUpTestCase, self).tearDown() + + def test_register(self): + selenium = self.selenium + #Opening the link we want to test + selenium.get('http://localhost:8000/signup/') + username = selenium.find_element_by_id('id_username') + first_name = selenium.find_element_by_id('id_first_name') + last_name = selenium.find_element_by_id('id_last_name') + email = selenium.find_element_by_id('id_email') + password1 = selenium.find_element_by_id('id_password1') + password2 = selenium.find_element_by_id('id_password2') + submit = selenium.find_element_by_name('add_product') + #Fill the form with data + first_name.send_keys('eeeeee') + last_name.send_keys('Unaryk') + username.send_keys('test1') + email.send_keys('yusuf@qawba.com') + password1.send_keys('123456') + password2.send_keys('123456') + #submitting the form + submit.send_keys(Keys.RETURN) + #check the returned result + time.sleep(1) + # print(selenium.page_source) + assert 'DIGITAL INVENTORY' in selenium.page_source + + +class LoginTestCase(LiveServerTestCase): + + def setUp(self): + self.selenium = webdriver.Firefox(executable_path=r'/geckodriver') + super(LoginTestCase, self).setUp() + + def tearDown(self): + self.selenium.quit() + super(LoginTestCase, self).tearDown() + + def test_register(self): + selenium = self.selenium + #Opening the link we want to test + selenium.get('http://localhost:8000/accounts/login/') + username = selenium.find_element_by_id('id_username') + password = selenium.find_element_by_id('id_password') + submit = selenium.find_element_by_name('add_product') + #Fill the form with data + username.send_keys('admin') + password.send_keys('admin') + #submitting the form + submit.send_keys(Keys.RETURN) + #check the returned result + time.sleep(1) + # print(selenium.page_source) + assert 'DIGITAL INVENTORY' in selenium.page_source diff --git a/inventory/views.py b/inventory/views.py index e8b4686..e4e6a4c 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -21,7 +21,7 @@ # @author Shivam Kohli -from inventory.forms import SignUpForm, MerchantDetailForm, LoginForm, DocumentForm +from inventory.forms import SignUpForm, LoginForm, DocumentForm from inventory.models import Merchant, Product, Order from django.contrib.auth.models import User from django.contrib.auth import authenticate @@ -126,6 +126,11 @@ def fulfillment(request): context_dict['price'] = product[item].price context_dict['delivery_date'] = order_instance.order_date context_dict['address'] = order_instance.address + merchant = order_instance.merchant + user = User.objects.get(username=merchant) + primary_key = user.pk + merchant_instance = Merchant.objects.get(pk=primary_key) + context_dict['website'] = merchant_instance.website if order_instance.status=='order_processing': context_dict['order_processing'] = 'True' context_dict['pre_production'] = 'False' @@ -156,7 +161,6 @@ def fulfillment(request): context_dict['in_production'] = 'True' context_dict['shipped'] = 'True' context_dict['delivered'] = 'True' - print(context_dict) return render(request, 'inventory/fulfillment.html', context_dict) @@ -195,6 +199,7 @@ def order(request): data['summary'] = i.summary data['order_date'] = i.order_date data['address'] = i.address + data['status'] = i.status data['url'] = "/update_status/"+str(i.uid) array.append(data) context_dict['data'] = array @@ -361,6 +366,10 @@ def home(request): data['price'] = i.price data['inventory_on_hand'] = i.inventory_on_hand data['url'] = '/home/product/' + str(i.product_id) + if i.document: + data['digital'] = 'True' + else: + data['digital'] = 'False' array.append(data) context_dict['data'] = array return render(request, 'inventory/home.html', context_dict) @@ -371,15 +380,8 @@ def update_stock(request, uid): product_instance = Product.objects.get(name=uid) product_instance.inventory_on_hand = request.POST.get('stock_updated') product_instance.save() - product_instance = Product.objects.get(name=uid) - context_dict = {} - context_dict['name'] = product_instance.name - context_dict['description'] = product_instance.description - context_dict['price'] = product_instance.price - context_dict['inventory_on_hand'] = product_instance.inventory_on_hand - url_update_inventory = str('/update_stock/') + product_instance.name - context_dict['url_update_inventory'] = url_update_inventory - return render(request, 'inventory/product.html', context_dict) + base_url = request.build_absolute_uri().rsplit('/', 3)[0] + return redirect(base_url+'home/product/'+str(product_instance.product_id)) @login_required @@ -411,19 +413,8 @@ def add_product(request): user_instance = User.objects.get(username=current_merchant) product_instance.user = user_instance product_instance.save() - product = Product.objects.filter(user=user_instance) - context_dict = {} - array = [] - for i in product: - data = {} - data['name'] = i.name - data['description'] = i.description - data['price'] = i.price - data['inventory_on_hand'] = i.inventory_on_hand - data['url'] = '/home/product/' + str(i.product_id) - array.append(data) - context_dict['data'] = array - return render(request, 'inventory/home.html', context_dict) + base_url = request.build_absolute_uri().rsplit('/', 3)[0] + return redirect(base_url+'home/') @login_required @@ -444,8 +435,17 @@ def product(request, uid): parameters = "name="+item.name+'&price='+item.price+'&merchant='+merchant if item.document: context_dict['href'] = base_url+"/payment?"+parameters + context_dict['digital'] = 'True' else: context_dict['href'] = base_url+"/shipment?"+parameters + context_dict['digital'] = 'False' + user_instance = User.objects.get(username=merchant) + order = Order.objects.filter(merchant=user_instance) + count = 0 + for i in order: + product = i.product_id.filter(name=item.name) + count = count+1 + context_dict['count'] = count return render(request, 'inventory/product.html', context_dict) @@ -483,7 +483,6 @@ def digital_inventory(request): def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) - details_form = MerchantDetailForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') @@ -491,17 +490,13 @@ def signup(request): user = authenticate(username=username, password=raw_password) auth_login(request, user) instance = get_object_or_404(Merchant, user=user) - if details_form.is_valid(): - instance.address = details_form.cleaned_data.get('address') - instance.save() - else: - print("somethings wrong with the form") - # Redirect to a success page. + instance.address = form.cleaned_data.get('address') + instance.website = form.cleaned_data.get('website') + instance.save() return redirect('home') else: form = SignUpForm() - details_form = MerchantDetailForm() - dictionary = {'form': form, 'details_form': details_form} + dictionary = {'form': form} return render(request, 'inventory/signup.html', dictionary) @@ -521,7 +516,7 @@ def login(request): # Redirect to a success page. return redirect('home') else: - error_message = "You are not a registered user please sign up" + error_message = "Incorrect username or password" form = LoginForm() context_dict['form'] = form context_dict['error_message'] = error_message |