Exemple #1
0
class ContactViewTest(TestCase):
    url = '/cms/contact'

    def setUp(self):
        self.factory = AsyncRequestFactory()
        self.admin = User.objects.create_user(username='******',
                                              email='',
                                              password='******')
        self.admin.is_superuser = True
        self.company = Company.objects.create(name='Company',
                                              street='street',
                                              number='1',
                                              zipcode='12345',
                                              city='city')
        self.contact = Contact.objects.create(username='******',
                                              email='',
                                              password='******',
                                              company=self.company)
        MailSetting.objects.create(smtp_user='******',
                                   smtp_server='localhost',
                                   smtp_port=587,
                                   smtp_password='******',
                                   stmp_use_tls=True)

        ShopSetting.objects.create(google_recaptcha_publickey='pub',
                                   google_recaptcha_privatekey='priv')

    def test_successful_login(self):
        request = self.factory.get(ContactViewTest.url)
        request.user = self.admin
        response = ContactView.as_view()(request)

        self.assertEqual(response.status_code, 200)

    def test_permission_denied_for_loggedin_user(self):
        request = self.factory.get(ContactViewTest.url)
        request.user = self.contact

        self.assertRaises(PermissionDenied)

    def test_permission_denied_for_anonymous_user(self):
        request = self.factory.get(ContactViewTest.url)
        request.user = AnonymousUser()

        self.assertRaises(PermissionDenied)

    @skip("Unkown internal http error, to be checked at a later time")
    def test_post_contact_form(self):
        request = self.factory.post(ContactViewTest.url,
                                    data={
                                        'name': 'test_user',
                                        'email': '*****@*****.**',
                                        'phone': '088/2654789',
                                        'message': 'This is a message'
                                    })
        response = ContactView.as_view()(request)

        self.assertEqual(response.status_code, 200)
Exemple #2
0
class GenericViewTest(TestCase):
    url = '/cms/home/'

    def setUp(self):
        self.factory = AsyncRequestFactory()
        self.admin = User.objects.create_user(username='******',
                                              email='',
                                              password='******')
        self.admin.is_superuser = True
        self.company = Company.objects.create(name='Company',
                                              street='street',
                                              number='1',
                                              zipcode='12345',
                                              city='city')
        self.contact = Contact.objects.create(username='******',
                                              email='',
                                              password='******',
                                              company=self.company)
        Page.objects.create(page_id=1, page_name='home')
        LegalSetting.objects.create(company_name='Test')
        CacheSetting.objects.create()

    def test_successful_login(self):
        request = self.factory.get(GenericViewTest.url)
        request.LANGUAGE_CODE = 'en'
        request.user = self.admin
        response = GenericView.as_view()(request, 'home')

        self.assertEqual(response.status_code, 200)

    def test_permission_denied_for_loggedin_user(self):
        request = self.factory.get(GenericViewTest.url)
        request.user = self.contact

        self.assertRaises(PermissionDenied)

    def test_permission_denied_for_anonymous_user(self):
        request = self.factory.get(GenericViewTest.url)
        request.user = AnonymousUser()

        self.assertRaises(PermissionDenied)

    def test_page_not_found(self):
        request = self.factory.get('/cms/not-found')
        request.LANGUAGE_CODE = 'en'
        request.user = self.admin
        response = GenericView.as_view()(request, 'not-found')

        self.assertEqual(response.status_code, 404)
Exemple #3
0
class CSSSettingsViewTest(TestCase):
    url = '/cms/css-setting'

    def setUp(self):
        self.factory = AsyncRequestFactory()
        self.admin = User.objects.create_user(username='******',
                                              email='',
                                              password='******')
        self.admin.is_superuser = True
        self.company = Company.objects.create(name='Company',
                                              street='street',
                                              number='1',
                                              zipcode='12345',
                                              city='city')
        self.contact = Contact.objects.create(username='******',
                                              email='',
                                              password='******',
                                              company=self.company)

    def test_successful_login(self):
        request = self.factory.get(CSSSettingsViewTest.url)
        request.user = self.admin
        response = CSSSettingsView.as_view()(request)

        self.assertEqual(response.status_code, 200)

    def test_permission_denied_for_loggedin_user(self):
        request = self.factory.get(CSSSettingsViewTest.url)
        request.user = self.contact

        self.assertRaises(PermissionDenied)

    def test_permission_denied_for_anonymous_user(self):
        request = self.factory.get(CSSSettingsViewTest.url)
        request.user = AnonymousUser()

        self.assertRaises(PermissionDenied)

    @skip("Unkown internal http error, to be checked at a later time")
    def test_post_csssetting_form(self):
        request = self.factory.post(CSSSettingsViewTest.url + '1', data={})
        request.user = self.admin
        response = CSSSettingsView.as_view()(request)

        self.assertEqual(response.status_code, 200)
Exemple #4
0
class PrivacyPolicyViewTest(TestCase):
    url = '/cms/privacy-policy'

    def setUp(self):
        self.factory = AsyncRequestFactory()
        self.admin = User.objects.create_user(username='******',
                                              email='',
                                              password='******')
        self.admin.is_superuser = True
        self.company = Company.objects.create(name='Company',
                                              street='street',
                                              number='1',
                                              zipcode='12345',
                                              city='city')
        self.contact = Contact.objects.create(username='******',
                                              email='',
                                              password='******',
                                              company=self.company)
        LegalSetting.objects.create()

    def test_successful_login(self):
        request = self.factory.get(PrivacyPolicyViewTest.url)
        request.user = self.admin
        response = PrivacyPolicyView.as_view()(request)

        self.assertEqual(response.status_code, 200)

    def test_permission_denied_for_loggedin_user(self):
        request = self.factory.get(PrivacyPolicyViewTest.url)
        request.user = self.contact

        self.assertRaises(PermissionDenied)

    def test_permission_denied_for_anonymous_user(self):
        request = self.factory.get(PrivacyPolicyViewTest.url)
        request.user = AnonymousUser()

        self.assertRaises(PermissionDenied)
Exemple #5
0
class AccountingViewTest(TestCase):
    url = '/accounting'

    def setUp(self):
        self.factory = AsyncRequestFactory()
        self.admin = User.objects.create_user(username='******',
                                              email='',
                                              password='******')
        self.admin.is_superuser = True
        self.company = Company.objects.create(name='Company',
                                              street='street',
                                              number='1',
                                              zipcode='12345',
                                              city='city')
        self.contact = Contact.objects.create(username='******',
                                              email='',
                                              password='******',
                                              company=self.company)
        initial_state = OrderState.objects.create(initial=True, name="Start")
        paid_state = OrderState.objects.create(initial=False,
                                               name="Paid",
                                               is_paid_state=True)
        sub_item = ProductSubItem.objects.create(price=10,
                                                 price_on_request=False,
                                                 name='product')
        order_open = OrderDetail.objects.create(company=self.contact.company,
                                                contact=self.contact,
                                                state=initial_state)
        OrderItem.objects.create(order_detail=order_open,
                                 price=10,
                                 tax_rate=0.19,
                                 product=sub_item,
                                 price_wt=11.9,
                                 price_discounted=10,
                                 price_discounted_wt=11.9)
        order_paid = OrderDetail.objects.create(company=self.contact.company,
                                                contact=self.contact,
                                                state=paid_state)
        OrderItem.objects.create(order_detail=order_paid,
                                 price=10,
                                 tax_rate=0.19,
                                 product=sub_item,
                                 price_wt=11.9,
                                 price_discounted=10,
                                 price_discounted_wt=11.9)

    def test_successful_login(self):
        request = self.factory.get(AccountingViewTest.url)
        request.user = self.admin
        response = AccountingView.as_view()(request)

        self.assertEqual(response.status_code, 200)

    def test_permission_denied_for_loggedin_user(self):
        request = self.factory.get(AccountingViewTest.url)
        request.user = self.contact

        self.assertRaises(PermissionDenied)

    def test_permission_denied_for_anonymous_user(self):
        request = self.factory.get(AccountingViewTest.url)
        request.user = AnonymousUser()

        self.assertRaises(PermissionDenied)

    def test_elements_in_context_data(self):
        request = self.factory.get(AccountingViewTest.url)
        view = AccountingView()
        view.setup(request)
        view.object_list = view.get_queryset()

        context = view.get_context_data()
        self.assertIn('total_net', context)
        self.assertIn('total_gross', context)
        self.assertIn('counted_open_orders', context)
        self.assertIn('counted_open_payments', context)
        self.assertIn('counted_open_shipments', context)
        self.assertIn('last_orders', context)
        self.assertIn('open_order_state_id', context)
        self.assertIn('stock', context)

    def test_filter_in_context_data(self):
        request = self.factory.get(AccountingViewTest.url)
        view = AccountingView()
        view.setup(request)
        view.object_list = view.get_queryset()

        context = view.get_context_data()
        self.assertEqual(context.get('total_net'), Decimal('20.00'))
        self.assertEqual(context.get('total_gross'), Decimal('23.8'))
        self.assertEqual(context.get('counted_open_orders'), 1)
        self.assertEqual(context.get('counted_open_payments'), 0)
        self.assertEqual(context.get('counted_open_shipments'), 1)
        self.assertQuerysetEqual(
            context.get('last_orders'),
            map(repr,
                OrderDetail.objects.all().order_by('-date_added')[:5]))
        self.assertEqual(context.get('open_order_state_id'), 1)