Exemple #1
0
    def test_validate_gafi(self):
        """ test the gafi validation """

        # --- invalid street
        shareholder = ShareholderGenerator().generate()
        # must be in switzerland
        shareholder.company.country = Country.objects.get(
            iso_code__iexact='ch')

        shareholder.user.userprofile.street = ''
        shareholder.user.userprofile.save()

        self.assertFalse(shareholder.validate_gafi()['is_valid'])

        # --- invalid company name
        shareholder = ShareholderGenerator().generate()
        # must be in switzerland
        shareholder.company.country = Country.objects.get(
            iso_code__iexact='ch')

        shareholder.user.userprofile.company_name = None
        shareholder.user.userprofile.save()

        self.assertFalse(shareholder.validate_gafi()['is_valid'])

        # --- valid data
        shareholder = ShareholderGenerator().generate()
        # must be in switzerland
        shareholder.company.country = Country.objects.get(
            iso_code__iexact='ch')

        self.assertTrue(shareholder.validate_gafi()['is_valid'])
Exemple #2
0
    def test_call(self):

        with self.assertRaises(ValueError):
            self.validator('')

        plan_name = settings.DJSTRIPE_PLANS.keys()[0]

        self.assertIsNone(self.validator(plan_name))

        MODIFIED_DJSTRIPE_PLANS = copy.deepcopy(settings.DJSTRIPE_PLANS)
        MODIFIED_DJSTRIPE_PLANS[plan_name]['features']['shareholders'] = {
            'max': 1
        }

        with self.settings(DJSTRIPE_PLANS=MODIFIED_DJSTRIPE_PLANS):
            self.assertIsNone(self.validator(plan_name))

            # add shareholder
            ShareholderGenerator().generate(company=self.validator.company)

            self.assertIsNone(self.validator(plan_name))

            # add another shareholder
            ShareholderGenerator().generate(company=self.validator.company)

            with self.assertRaises(ValidationError):
                self.validator(plan_name)
Exemple #3
0
    def setUp(self):
        super(BaseViewTestCase, self).setUp()

        self.client = Client()
        self.shareholder1 = ShareholderGenerator().generate()
        self.company = self.shareholder1.company
        self.operator = OperatorGenerator().generate(company=self.company)
        self.operator2 = OperatorGenerator().generate()
        self.shareholder2 = ShareholderGenerator().generate()
        self.position1 = PositionGenerator().generate(buyer=self.shareholder1)
        self.position2 = PositionGenerator().generate(buyer=self.shareholder2)
        self.optiontransaction1 = OptionTransactionGenerator().generate(
            buyer=self.shareholder1)
        self.optiontransaction2 = OptionTransactionGenerator().generate(
            buyer=self.shareholder2)
        self.optionplan = self.optiontransaction1.option_plan

        self.statement_report = mommy.make(ShareholderStatementReport,
                                           company=self.shareholder1.company)
        self.statement = mommy.make(ShareholderStatement,
                                    user=self.shareholder1.user,
                                    pdf_file='example.pdf',
                                    report=self.statement_report)

        # add company subscription
        self.add_subscription(self.company)

        self.shareholder1_url = reverse('shareholder',
                                        kwargs={'pk': self.shareholder1.pk})
Exemple #4
0
    def test_share_value(self):
        """
        share value is last trated price
        """
        company = CompanyGenerator().generate(share_count=1000000)
        security = SecurityGenerator().generate(company=company)
        sc = ShareholderGenerator().generate(company=company)
        s1 = ShareholderGenerator().generate(company=company)
        now = datetime.datetime.now()

        PositionGenerator().generate(buyer=sc,
                                     count=1000000,
                                     value=1,
                                     security=security,
                                     bought_at=now -
                                     datetime.timedelta(days=11))
        p = PositionGenerator().generate(buyer=s1,
                                         seller=sc,
                                         count=500000,
                                         value=100,
                                         security=security,
                                         bought_at=now -
                                         datetime.timedelta(days=10))
        p.value = None
        p.save()

        self.assertEqual(s1.share_value(), Decimal('500000.0000'))
Exemple #5
0
 def test_is_company_shareholder(self):
     """
     is shareholder company shareholder?
     """
     s = ShareholderGenerator().generate()
     s2 = ShareholderGenerator().generate(company=s.company)
     self.assertTrue(s.is_company_shareholder())
     self.assertFalse(s2.is_company_shareholder())
Exemple #6
0
 def setUp(self):
     self.operator = OperatorGenerator().generate()
     TwoInitialSecuritiesGenerator().generate(company=self.operator.company)
     self.company_shareholder = CompanyShareholderGenerator().generate(
         company=self.operator.company)
     self.buyer = ShareholderGenerator().generate(
         company=self.operator.company)
     self.seller = ShareholderGenerator().generate(
         company=self.operator.company)
Exemple #7
0
    def test_share_percent(self):
        """
        proper share percent math
        """
        company = CompanyGenerator().generate(share_count=1000000)
        security = SecurityGenerator().generate(company=company)
        sc = ShareholderGenerator().generate(company=company)
        s1 = ShareholderGenerator().generate(company=company)
        s2 = ShareholderGenerator().generate(company=company)
        s3 = ShareholderGenerator().generate(company=company)
        now = datetime.datetime.now()

        PositionGenerator().generate(buyer=sc,
                                     count=1000000,
                                     value=100,
                                     security=security,
                                     bought_at=now -
                                     datetime.timedelta(days=11))
        PositionGenerator().generate(buyer=s1,
                                     seller=sc,
                                     count=500000,
                                     value=100,
                                     security=security,
                                     bought_at=now -
                                     datetime.timedelta(days=10))
        PositionGenerator().generate(buyer=s2,
                                     seller=sc,
                                     count=5000,
                                     value=100,
                                     security=security,
                                     bought_at=now -
                                     datetime.timedelta(days=9))
        PositionGenerator().generate(buyer=s3,
                                     seller=sc,
                                     count=50,
                                     value=100,
                                     security=security,
                                     bought_at=now -
                                     datetime.timedelta(days=8))

        self.assertEqual(s1.share_percent(), '99.00')
        self.assertEqual(s2.share_percent(), '0.99')
        self.assertEqual(s3.share_percent(), '0.01')

        PositionGenerator().generate(buyer=s2,
                                     seller=s1,
                                     count=250000,
                                     value=100,
                                     security=security,
                                     bought_at=now -
                                     datetime.timedelta(days=7))

        self.assertEqual(s1.share_percent(), '49.50')
Exemple #8
0
    def _prepare_split_scenario(self):
        company = CompanyGenerator().generate()
        security = SecurityGenerator().generate(company=company)
        cshareholder = ShareholderGenerator().generate(company=company)
        shareholder1 = ShareholderGenerator().generate(company=company)
        shareholder2 = ShareholderGenerator().generate(company=company)
        shareholder3 = ShareholderGenerator().generate(company=company)
        shareholder4 = ShareholderGenerator().generate(company=company)
        PositionGenerator().generate(buyer=cshareholder,
                                     count=10000,
                                     value=1000,
                                     security=security,
                                     seller=None)
        p1 = PositionGenerator().generate(buyer=shareholder1,
                                          count=100,
                                          value=20,
                                          seller=cshareholder,
                                          security=security)
        p2 = PositionGenerator().generate(buyer=shareholder2,
                                          count=200,
                                          value=40,
                                          seller=cshareholder,
                                          security=security)
        p3 = PositionGenerator().generate(buyer=shareholder3,
                                          count=900,
                                          value=60,
                                          seller=cshareholder,
                                          security=security)
        p4 = PositionGenerator().generate(buyer=cshareholder,
                                          count=600,
                                          value=80,
                                          seller=shareholder3,
                                          security=security)
        PositionGenerator().generate(buyer=cshareholder,
                                     count=1000,
                                     value=1000,
                                     security=security,
                                     seller=None)
        company.share_count = 11000
        company.save()

        return dict(company=company,
                    cshareholder=cshareholder,
                    shareholder1=shareholder1,
                    shareholder2=shareholder2,
                    shareholder3=shareholder3,
                    shareholder4=shareholder4,
                    p1=p1,
                    p2=p2,
                    p3=p3,
                    p4=p4,
                    security=security)
Exemple #9
0
    def setUp(self):
        super(StartFunctionalTestCase, self).setUp()

        self.operator = OperatorGenerator().generate()
        TwoInitialSecuritiesGenerator().generate(company=self.operator.company)
        self.company_shareholder = CompanyShareholderGenerator().generate(
            company=self.operator.company)
        self.buyer = ShareholderGenerator().generate(
            company=self.operator.company)
        self.seller = ShareholderGenerator().generate(
            company=self.operator.company)

        # add a subscription for the company
        self.add_subscription(self.operator.company)
Exemple #10
0
    def test_add_shareholder_with_existing_number(self):
        """
        add shareholder with existing number
        """
        op = OperatorGenerator().generate()
        self.add_subscription(op.company)
        user = UserGenerator().generate()
        shareholder = ShareholderGenerator().generate(company=op.company)
        user.email = None

        try:
            start = page.StartPage(self.selenium, self.live_server_url,
                                   op.user)
            # wait for list
            start.wait_until_visible((By.CSS_SELECTOR, '#shareholder_list'))
            start.is_properly_displayed()
            self.assertEqual(
                start.has_shareholder_count(),
                Shareholder.objects.filter(company=op.company).count())
            start.click_open_add_shareholder()
            start.wait_until_modal_opened('addShareholder')
            start.add_shareholder(user, number=shareholder.number)
            start.click_save_add_shareholder()
            start.close_modal('addShareholder')
            time.sleep(2)

            self.assertEqual(
                Shareholder.objects.filter(company=op.company,
                                           number=shareholder.number).count(),
                1)

        except Exception, e:
            self._handle_exception(e)
Exemple #11
0
    def test_stripe_company_shareholder_invoice_item(self,
                                                     mock_invoice_item_create):
        customer = self.company.get_customer()

        stripe_company_shareholder_invoice_item(customer, 'test', None)
        mock_invoice_item_create.assert_not_called()

        from django.conf import settings

        plans = copy.deepcopy(settings.DJSTRIPE_PLANS)
        plans['test']['features']['shareholders']['price'] = 10

        with self.settings(DJSTRIPE_PLANS=plans):
            stripe_company_shareholder_invoice_item(customer, 'test', None)
            mock_invoice_item_create.assert_not_called()

            shareholder_generator = ShareholderGenerator()
            shareholder_generator.generate(company=self.company)
            shareholder_generator.generate(company=self.company, number='0')

            # shareholder have no shares
            stripe_company_shareholder_invoice_item(customer, 'test', None)
            mock_invoice_item_create.assert_not_called()

            with mock.patch('shareholder.models.Shareholder.share_count',
                            return_value=10):
                stripe_company_shareholder_invoice_item(customer, 'test', None)
                mock_invoice_item_create.assert_called()
                mock_invoice_item_create.assert_called_with(
                    customer=customer.stripe_id,
                    amount=10,
                    currency=settings.DJSTRIPE_CURRENCIES[0][0],
                    invoice=None,
                    description=_(u'Shareholders (1 x 0.10)')
                )
Exemple #12
0
    def test_confirm_optiontransaction(self):

        operator = OperatorGenerator().generate()
        user = operator.user
        seller = ShareholderGenerator().generate(company=operator.company)
        optiontransaction = OptionTransactionGenerator().generate(
            seller=seller)

        logged_in = self.client.login(username=user.username, password='******')
        self.assertTrue(logged_in)

        # get and prep data
        res = self.client.login(username=user.username, password='******')
        self.assertTrue(res)

        res = self.client.get('/services/rest/optiontransaction/{}'.format(
            optiontransaction.pk),
                              format='json')

        # update data
        res = self.client.post(
            '/services/rest/optiontransaction/{}/confirm'.format(
                optiontransaction.pk), {},
            format='json')

        self.assertEqual(res.status_code, 200)
        self.assertFalse(
            OptionTransaction.objects.get(id=optiontransaction.id).is_draft)
Exemple #13
0
    def test_authenticate(self):
        """ authenticate, get token, and call for shareholder details """

        # prepare test data
        operator = OperatorGenerator().generate()
        shareholder = ShareholderGenerator().generate(company=operator.company)
        user = operator.user
        user.set_password('test')
        user.save()

        # authenticate
        response = self.client.post('/services/rest/api-token-auth/', {
            'username': user.username,
            'password': '******'
        },
                                    format='json')

        self.assertEqual(response.data.get('token'), user.auth_token.key)

        # get shareholder details
        token = user.auth_token
        response = self.client.get(
            '/services/rest/shareholders', **{
                'HTTP_AUTHORIZATION': 'Token {}'.format(token.key),
                'format': 'json'
            })

        self.assertTrue(len(response.data.get('results')) == 1)
        self.assertEqual(
            response.data['results'][0].get('user').get('userprofile').get(
                'birthday'),
            shareholder.user.userprofile.birthday.strftime('%Y-%m-%d'))
Exemple #14
0
    def test_add_duplicate_new_shareholder(self):
        """
        adds a new shareholder with same id"""

        operator = OperatorGenerator().generate()
        shareholder = ShareholderGenerator().generate(company=operator.company)
        user = operator.user

        logged_in = self.client.login(username=user.username, password='******')
        self.assertTrue(logged_in)

        data = {
            u"user": {
                u"first_name": u"Mike2Grüße",
                u"last_name": u"Hildebrand2Grüße",
                u"email": u"*****@*****.**",
            },
            u"number": shareholder.number
        }

        response = self.client.post(
            '/services/rest/shareholders', data, **{
                'HTTP_AUTHORIZATION': 'Token {}'.format(user.auth_token.key),
                'format': 'json'
            })

        self.assertEqual(response.status_code, 400)
        self.assertEqual(response.data.get('number'), [
            u'Diese Aktion\xe4rsnummer wird bereits verwendet. Bitte '
            u'w\xe4hlen Sie eine andere.'
        ])
Exemple #15
0
    def setUp(self):
        self.shareholder = ShareholderGenerator().generate()
        self.company = self.shareholder.company
        self.position = PositionGenerator().generate(buyer=self.shareholder,
                                                     count=30,
                                                     vesting_months=24)
        self.option = OptionTransactionGenerator().generate(
            buyer=self.shareholder, count=16, vesting_months=120)

        # noise ... not to be fetched
        PositionGenerator().generate(buyer=self.shareholder, count=30)
        OptionTransactionGenerator().generate(buyer=self.shareholder, count=16)

        self.date_passed = (timezone.now() - relativedelta(years=2)).date()
        self.future_date = (timezone.now() + relativedelta(years=3)).date()

        # vesting expired
        PositionGenerator().generate(buyer=self.shareholder,
                                     count=30,
                                     bought_at=self.date_passed,
                                     vesting_months=6)
        OptionTransactionGenerator().generate(buyer=self.shareholder,
                                              count=16,
                                              bought_at=self.date_passed,
                                              vesting_months=6)
Exemple #16
0
 def __serialize(self, segments):
     seller = ShareholderGenerator().generate()
     option_plan = OptionPlanGenerator().generate(company=seller.company,
                                                  number_segments=segments)
     # initial seeding
     OptionTransactionGenerator().generate(number_segments=segments,
                                           count=8,
                                           option_plan=option_plan,
                                           buyer=seller,
                                           seller=None)
     # to test transaction
     position = OptionTransactionGenerator().generate(
         number_segments=segments,
         count=8,
         seller=seller,
         option_plan=option_plan,
         save=False)
     url = reverse('optiontransaction-detail', kwargs={'pk': position.id})
     request = self.factory.get(url)
     request.user = OperatorGenerator().generate(
         company=option_plan.company).user
     # prepare data
     data = OptionTransactionSerializer(position,
                                        context={
                                            'request': request
                                        }).data
     # clear bad datetimedata
     data['buyer']['user']['userprofile']['birthday'] = None
     data['seller']['user']['userprofile']['birthday'] = None
     data['bought_at'] = '2014-01-01'
     return (OptionTransactionSerializer(data=data,
                                         context={'request':
                                                  request}), position)
Exemple #17
0
    def test_split_shares_GET(self):
        operator = OperatorGenerator().generate()
        user = operator.user

        ShareholderGenerator().generate(company=operator.company)
        ShareholderGenerator().generate(company=operator.company)
        TwoInitialSecuritiesGenerator().generate(company=operator.company)

        logged_in = self.client.login(username=user.username, password='******')
        self.assertTrue(logged_in)
        response = self.client.get(
            '/services/rest/split/', {}, **{
                'HTTP_AUTHORIZATION': 'Token {}'.format(user.auth_token.key),
                'format': 'json'
            })

        self.assertEqual(response.status_code, 405)
Exemple #18
0
 def setUp(self):
     self.shareholder = ShareholderGenerator().generate()
     self.company = self.shareholder.company
     self.position = PositionGenerator().generate(
         buyer=self.shareholder, count=30, vesting_months=24)
     self.option = OptionTransactionGenerator().generate(
         buyer=self.shareholder, count=16, vesting_months=120)
     self.mixin = DiscountedTaxByVestingModelMixin()
Exemple #19
0
    def test_csv_download(self):
        """ rest download of captable csv """

        # data
        company = CompanyGenerator().generate()
        shareholder_list = []
        for x in range(1, 6):  # don't statt with 0, Generators 'if' will fail
            shareholder_list.append(ShareholderGenerator().generate(
                company=company, number=str(x)))

        # initial share creation
        PositionGenerator().generate(
            buyer=shareholder_list[0], count=1000, value=10)
        # single transaction
        PositionGenerator().generate(
            buyer=shareholder_list[1], count=10, value=10,
            seller=shareholder_list[0])
        # shareholder bought and sold
        PositionGenerator().generate(
            buyer=shareholder_list[2], count=20, value=20,
            seller=shareholder_list[0])
        PositionGenerator().generate(
            buyer=shareholder_list[0], count=20, value=20,
            seller=shareholder_list[2])

        # run test
        response = self.client.get(
            reverse('captable_csv', kwargs={"company_id": company.id}))

        # not logged in user
        self.assertEqual(response.status_code, 302)

        # login and retest
        user = UserGenerator().generate()
        OperatorGenerator().generate(user=user, company=company)
        is_loggedin = self.client.login(username=user.username, password='******')
        self.assertTrue(is_loggedin)
        response = self.client.get(reverse('captable_csv',
                                   kwargs={"company_id": company.id}))

        # assert response code
        self.assertEqual(response.status_code, 200)
        # assert proper csv
        lines = response.content.split('\r\n')
        lines.pop()  # remove last element based on final '\r\n'
        for row in lines:
            self.assertEqual(row.count(','), 7)
        self.assertEqual(len(lines), 3)  # ensure we have the right data
        # assert company itself
        self.assertEqual(shareholder_list[0].number, lines[1].split(',')[0])
        # assert share owner
        self.assertEqual(shareholder_list[1].number, lines[2].split(',')[0])
        # assert shareholder witout position not in there
        for line in lines:
            self.assertNotEqual(line[0], shareholder_list[3].number)
        # assert shareholder which bought and sold again
        for line in lines:
            self.assertNotEqual(line[0], shareholder_list[2].number)
Exemple #20
0
 def setUp(self):
     self.operator = OperatorGenerator().generate()
     # initial position
     shareholder = ShareholderGenerator().generate(user=self.operator.user)
     PositionGenerator().generate(company=self.operator.company,
                                  number_segments=[u'0-9999'],
                                  buyer=shareholder,
                                  count=10000)
     TwoInitialSecuritiesGenerator().generate(company=self.operator.company)
Exemple #21
0
 def test_update_order_cache_task(self):
     """ update shareholder objs order_cache field """
     shareholder = ShareholderGenerator().generate()
     update_order_cache_task(shareholder.pk)
     shareholder.refresh_from_db()
     self.assertEqual(
         shareholder.order_cache,
         {u'cumulated_face_value': 0, u'number': u'234543',
          u'postal_code': u'12345', u'share_count': 0})
Exemple #22
0
    def test_table_actions(self):
        """
        test on start page that diverse things are shown properly
        e.g. #128
        """
        optiontransactions, shs = \
            ComplexOptionTransactionsWithSegmentsGenerator().generate()
        for x in range(0, 30):
            ShareholderGenerator().generate(company=shs[0].company)

        # add a subscription for the company
        self.add_subscription(shs[0].company)

        try:
            start = page.StartPage(self.selenium, self.live_server_url,
                                   shs[0].company.operator_set.first().user)
            # wait for list
            start.wait_until_visible((By.CSS_SELECTOR, '#shareholder_list'))

            # search
            start.is_properly_displayed()
            # FIXME doing strang things here
            start.enter_search_term(shs[0].user.last_name)
            time.sleep(1)
            start.click_search()
            start.refresh()
            time.sleep(2)
            start.enter_search_term(shs[0].user.last_name)
            time.sleep(1)
            start.click_search()
            time.sleep(1)
            self.assertEqual(start.has_shareholder_count(), 1)

            # paginate
            start.refresh()
            start.is_properly_displayed()
            self.assertEqual(start.has_shareholder_count(), 20)
            start.click_paginate_next()
            time.sleep(1)
            self.assertEqual(start.has_shareholder_count(), 12)

            # sort
            start.refresh()
            start.is_properly_displayed()
            start.sort_table_by_number()
            time.sleep(2)
            numbers = start.driver.find_elements_by_class_name('number')
            prev = None
            for number in numbers:
                if prev is None:
                    prev = number.text
                    continue
                self.assertTrue(prev < number.text)

        except Exception, e:
            self._handle_exception(e)
Exemple #23
0
    def test_update_order_cache(self, task_mock):
        shareholder = ShareholderGenerator().generate()
        update_order_cache(Shareholder, shareholder, False)
        task_mock.apply_async.assert_called_with([shareholder.pk])

        task_mock.reset_mock()
        position = mommy.make(Position, _fill_optional=True)
        update_order_cache(Position, position, False)
        calls = (mock.call(position.buyer.pk), mock.call(position.seller.pk))
        task_mock.apply_async.has_calls(calls)
Exemple #24
0
    def test_shareholder_detail(self):
        """ test detail view access for shareholder user """

        shareholder = ShareholderGenerator().generate()

        response = self.client.force_login(shareholder.user)

        response = self.client.get(
            reverse("shareholder", args=(shareholder.id, )))

        self.assertEqual(response.status_code, 200)
Exemple #25
0
    def test_get_or_update_init_date(self):

        ShareholderGenerator().generate(company=self.company, number='1913')
        ShareholderGenerator().generate(company=self.company, number='1157')
        sx = ShareholderGenerator().generate(company=self.company,
                                             number='1914')
        profile = sx.user.userprofile
        profile.initial_registration_at = None
        profile.save()

        self.backend.company = self.company
        self.backend._get_or_update_init_date()
        self.assertEqual(
            list(
                Shareholder.objects.filter(
                    company=self.backend.company,
                    user__userprofile__initial_registration_at__isnull=False).
                values_list('user__userprofile__initial_registration_at',
                            flat=True)),
            [datetime.datetime.now().date(),
             datetime.datetime.now().date()])
Exemple #26
0
    def test_csv_download_number_segments(self):
        """ rest download of captable csv """

        # data
        company = CompanyGenerator().generate()
        secs = TwoInitialSecuritiesGenerator().generate(company=company)
        security = secs[1]
        security.track_numbers = True
        security.save()

        shareholder_list = []
        for x in range(1, 6):  # don't statt with 0, Generators 'if' will fail
            shareholder_list.append(ShareholderGenerator().generate(
                company=company, number=str(x)))

        # initial share creation
        PositionGenerator().generate(
            buyer=shareholder_list[0], count=1000, value=10, security=security)
        # single transaction
        PositionGenerator().generate(
            buyer=shareholder_list[1], count=10, value=10, security=security,
            seller=shareholder_list[0])
        # shareholder bought and sold
        PositionGenerator().generate(
            buyer=shareholder_list[2], count=20, value=20, security=security,
            seller=shareholder_list[0])
        PositionGenerator().generate(
            buyer=shareholder_list[0], count=20, value=20, security=security,
            seller=shareholder_list[2])

        # login and retest
        user = UserGenerator().generate()
        OperatorGenerator().generate(user=user, company=company)
        is_loggedin = self.client.login(username=user.username, password='******')
        self.assertTrue(is_loggedin)
        response = self.client.get(reverse('captable_csv',
                                   kwargs={"company_id": company.id}))

        # assert response code
        self.assertEqual(response.status_code, 200)
        # assert proper csv
        lines = response.content.split('\r\n')
        lines.pop()  # remove last element based on final '\r\n'
        for row in lines:
            if row == lines[0]:  # skip first row
                continue
            self.assertEqual(row.count(','), 8)
            fields = row.split(',')
            s = Shareholder.objects.get(company=company, number=fields[0])
            text = s.current_segments(security)
            if text:
                self.assertTrue(text in fields[8])
Exemple #27
0
    def test_shareholder_detail(self):
        """ test detail view for shareholder """

        shareholder = ShareholderGenerator().generate()

        response = self.client.login(username=shareholder.user.username,
                                     password="******")
        self.assertTrue(response)

        response = self.client.get(
            reverse("shareholder", args=(shareholder.id, )))

        self.assertEqual(response.status_code, 200)
Exemple #28
0
    def test_xls_download_number_segments(self):
        """ rest download of captable xls """

        # data
        company = CompanyGenerator().generate()
        self.add_subscription(company)
        secs = TwoInitialSecuritiesGenerator().generate(company=company)
        security = secs[1]
        security.track_numbers = True
        security.save()

        shareholder_list = []
        for x in range(1, 6):  # don't statt with 0, Generators 'if' will fail
            shareholder_list.append(ShareholderGenerator().generate(
                company=company, number=str(x)))

        # initial share creation
        PositionGenerator().generate(buyer=shareholder_list[0],
                                     count=1000,
                                     value=10,
                                     security=security)
        # single transaction
        PositionGenerator().generate(buyer=shareholder_list[1],
                                     count=10,
                                     value=10,
                                     security=security,
                                     seller=shareholder_list[0])
        # shareholder bought and sold
        PositionGenerator().generate(buyer=shareholder_list[2],
                                     count=20,
                                     value=20,
                                     security=security,
                                     seller=shareholder_list[0])
        PositionGenerator().generate(buyer=shareholder_list[0],
                                     count=20,
                                     value=20,
                                     security=security,
                                     seller=shareholder_list[2])

        # login and retest
        report = ReportGenerator().generate(company=company, file_type='XLS')
        report.render()
        user = report.user
        OperatorGenerator().generate(user=user, company=company)
        self.client.force_login(user)
        response = self.client.get(
            reverse('reports:download', kwargs={"report_id": report.id}))

        # assert response code
        self.assertEqual(response.status_code, 200)
Exemple #29
0
    def test_captable_xls_download(self):
        """ rest download of captable xls """

        # data
        company = CompanyGenerator().generate()
        shareholder_list = []
        for x in range(1, 6):  # don't statt with 0, Generators 'if' will fail
            shareholder_list.append(ShareholderGenerator().generate(
                company=company, number=str(x)))
        shareholder_list = sorted(shareholder_list,
                                  key=lambda t: t.user.last_name.lower())

        # initial share creation
        p = PositionGenerator().generate(seller=None,
                                         buyer=shareholder_list[0],
                                         count=1000,
                                         value=10)
        security = p.security
        # single transaction
        PositionGenerator().generate(buyer=shareholder_list[1],
                                     count=10,
                                     value=10,
                                     seller=shareholder_list[0],
                                     security=security)
        # shareholder bought and sold
        PositionGenerator().generate(buyer=shareholder_list[2],
                                     count=20,
                                     value=20,
                                     seller=shareholder_list[0],
                                     security=security)
        PositionGenerator().generate(buyer=shareholder_list[0],
                                     count=20,
                                     value=20,
                                     seller=shareholder_list[2],
                                     security=security)

        # login and retest
        report = ReportGenerator().generate(company=company, file_type='XLS')
        report.render()
        user = report.user
        OperatorGenerator().generate(user=user, company=company)
        self.add_subscription(company)
        self.client.force_login(user)
        response = self.client.get(
            reverse('reports:download', kwargs={"report_id": report.id}))

        # assert response code
        self.assertEqual(response.status_code, 200)
Exemple #30
0
    def test_delete_position_shareholder(self):
        """
        shareholder cannot delete positions
        """

        operator = ShareholderGenerator().generate()
        user = operator.user
        position = PositionGenerator().generate(company=operator.company)

        logged_in = self.client.login(username=user.username, password='******')
        self.assertTrue(logged_in)

        res = self.client.delete('/services/rest/position/{}'.format(
            position.pk))

        self.assertEqual(res.status_code, 404)