示例#1
0
        def serialize(segments):
            operator = OperatorGenerator().generate()
            company = operator.company
            securities = TwoInitialSecuritiesGenerator().generate(
                company=company)
            security = securities[1]
            security.track_numbers = True
            security.save()
            position = PositionGenerator().generate(company=company,
                                                    number_segments=segments,
                                                    save=False,
                                                    security=security,
                                                    count=8)

            url = reverse('position-detail', kwargs={'pk': position.id})
            request = self.factory.get(url)
            request.user = operator.user

            # prepare data
            position.seller = None
            position.buyer = None
            # get test data dict
            data = PositionSerializer(position, context={
                'request': request
            }).data
            # clear bad datetimedata
            data['bought_at'] = '2014-01-01T10:00'
            del data['seller'], data['buyer']
            # feed data into serializer
            return PositionSerializer(data=data, context={'request': request})
示例#2
0
    def test_split_shares_POST(self):
        operator = OperatorGenerator().generate()
        user = operator.user
        company = operator.company

        s1, s2 = TwoInitialSecuritiesGenerator().generate(
            company=operator.company)
        PositionGenerator().generate(company=operator.company, security=s1)
        PositionGenerator().generate(company=operator.company, security=s1)

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

        security = Security.objects.filter(company=company, title="P")[0]
        data = {
            'dividend': 3,
            'divisor': 4,
            "security": {
                "pk": security.pk,
                "readable_title": security.get_title_display(),
                "title": security.title
            },
            'execute_at': datetime.datetime.now(),
        }

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

        self.assertEqual(response.status_code, 201)
示例#3
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)
示例#4
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)
示例#5
0
    def test_owns_segments_rma_performance(self):
        """
        speed of segment owning check to meet RMA data
        """
        logger.info('preparing test...')
        operator = OperatorGenerator().generate()
        sec1, sec2 = TwoInitialSecuritiesGenerator().generate(
            company=operator.company)
        sec1.track_numbers = True
        sec1.number_segments = [u"1-10000000"]
        sec1.save()

        cs = CompanyShareholderGenerator().generate(security=sec1,
                                                    company=operator.company)

        logger.info('data preparation done.')

        start = datetime.datetime.now()
        res = cs.owns_segments([u'1-582912'], sec1)
        end = datetime.datetime.now()
        delta = end - start
        self.assertTrue(res[0])
        if delta > datetime.timedelta(seconds=4):
            logger.error(
                'BUILD performance error: test_owns_segments_rma_performance',
                extra={'delta': delta})
        self.assertLess(delta, datetime.timedelta(seconds=7))
示例#6
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])
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
0
    def test_pdf_download_with_number_segments(self):
        """ test download of captable pdf """
        company = CompanyGenerator().generate()
        secs = TwoInitialSecuritiesGenerator().generate(company=company)
        security = secs[1]
        security.track_numbers = True
        security.save()

        # 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_pdf',
                                           kwargs={"company_id": company.id}))

        # assert response code
        self.assertEqual(response.status_code, 200)
        # assert proper csv
        self.assertTrue(response.content.startswith('%PDF-1.4\r\n'))
        self.assertTrue(response.content.endswith('EOF\r\n'))
示例#11
0
    def test_pdf_download_with_number_segments(self):
        """ test download of captable pdf """
        company = CompanyGenerator().generate()
        self.add_subscription(company)
        secs = TwoInitialSecuritiesGenerator().generate(company=company)
        report = ReportGenerator().generate(company=company)
        report.render()
        user = report.user
        OperatorGenerator().generate(user=user, company=company)
        security = secs[1]
        security.track_numbers = True
        security.save()

        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)
        # assert proper xls
        content = get_file_content_as_string(response)
        self.assertTrue(content.startswith('%PDF'))
示例#12
0
    def test_current_options_segments_same_day_single_digit(self):
        """
        very simple scenario with one CS and one shareholder
        """
        company = CompanyGenerator().generate()
        OperatorGenerator().generate(company=company)

        # intial securities
        s1, s2 = TwoInitialSecuritiesGenerator().generate(company=company)
        s1.track_numbers = True
        s1.number_segments = [1, 2, 3, 4]
        s1.save()

        # initial company shareholder
        cs = CompanyShareholderGenerator().generate(company=company,
                                                    security=s1)
        s = ShareholderGenerator().generate(company=company)
        optionplan = OptionPlanGenerator().generate(company=company,
                                                    number_segments=[1, 2],
                                                    security=s1)
        # initial option grant to CompanyShareholder
        OptionTransactionGenerator().generate(company=company,
                                              security=s1,
                                              buyer=cs,
                                              number_segments=[1, 2],
                                              option_plan=optionplan)
        # single shareholder option grant
        OptionTransactionGenerator().generate(company=company,
                                              security=s1,
                                              buyer=s,
                                              seller=cs,
                                              number_segments=[1],
                                              option_plan=optionplan)

        self.assertEqual(s.current_options_segments(s1), [1])

        # test company shareholder
        self.assertEqual(cs.current_options_segments(s1), [2])
示例#13
0
    def test_add_position_with_number_segment_performance(self):
        """
        test that we can add a position with numbered shares
        """

        logger.info('preparing test...')
        operator = OperatorGenerator().generate()
        user = operator.user
        sec1, sec2 = TwoInitialSecuritiesGenerator().generate(
            company=operator.company)
        sec1.track_numbers = True
        sec1.number_segments = [u"1-10000000"]
        sec1.save()

        cs = CompanyShareholderGenerator().generate(security=sec1,
                                                    company=operator.company)
        buyer = ShareholderGenerator().generate(company=operator.company)

        logger.info('data preparation done.')
        logged_in = self.client.login(username=user.username, password='******')
        self.assertTrue(logged_in)

        data = {
            "bought_at": "2016-05-13T23:00:00.000Z",
            "buyer": {
                "pk": buyer.pk,
                "user": {
                    "first_name": buyer.user.first_name,
                    "last_name": buyer.user.last_name,
                    "email": buyer.user.email,
                    "operator_set": [],
                    "userprofile": None,
                },
                "number": "0",
                "company": {
                    "pk":
                    operator.company.pk,
                    "name":
                    operator.company.name,
                    "share_count":
                    operator.company.share_count,
                    "country":
                    "",
                    "url":
                    "http://codingmachine:9000/services/rest/"
                    "company/{}".format(operator.company.pk),
                    "shareholder_count":
                    2
                },
                "share_percent": "99.90",
                "share_count": 100002,
                "share_value": 1000020,
                "validate_gafi": {
                    "is_valid": True,
                    "errors": []
                }
            },
            "security": {
                "pk": sec1.pk,
                "title": sec1.title,
                "count": sec1.count,
                "track_numbers": True,
                "number_segments": sec1.number_segments
            },
            "count": 1000000,
            "value": 0.5,
            "seller": {
                "pk": cs.pk,
                "user": {
                    "first_name": cs.user.first_name,
                    "last_name": cs.user.last_name,
                    "email": cs.user.email,
                    "operator_set": [],
                    "userprofile": None
                },
                "number": "0",
                "company": {
                    "pk": 5,
                    "name": "LieblingzWaldCompany AG",
                    "share_count": 100100,
                    "country": "",
                    "url": "http://codingmachine:9000/services/rest/company/5",
                    "shareholder_count": 2
                },
                "share_percent": "99.90",
                "share_count": 100000,
                "share_value": 1000020,
                "validate_gafi": {
                    "is_valid": True,
                    "errors": []
                }
            },
            "number_segments": "1-1000000",
            "comment": "Large Transaction"
        }

        logger.info('firing api call...')
        t0 = time.clock()
        response = self.client.post(
            u'/services/rest/position', data, **{
                u'HTTP_AUTHORIZATION': u'Token {}'.format(user.auth_token.key),
                u'format': u'json'
            })
        t1 = time.clock()
        delta = t1 - t0

        logger.info('api call done. evaluating result...')

        self.assertEqual(response.status_code, 201)
        self.assertTrue('Large Transaction' in response.content)
        self.assertEqual(response.data['number_segments'], [u'1-1000000'])
        if delta > 4:
            logger.error(
                'BUILD performance error: test_add_position_with_number_segment_performance',
                extra={'delta': delta})
        self.assertLess(delta, 6)

        position = Position.objects.latest('id')
        self.assertEqual(position.count, 1000000)
        self.assertEqual(position.value, 0.5)
        self.assertEqual(position.buyer, buyer)
        self.assertEqual(position.seller, cs)
        self.assertEqual(position.bought_at.isoformat(), '2016-05-13')
        self.assertEqual(position.number_segments, [u'1-1000000'])
示例#14
0
    def test_add_position_with_number_segment(self):
        """
        test that we can add a position with numbered shares
        """

        operator = OperatorGenerator().generate()
        user = operator.user

        buyer = ShareholderGenerator().generate(company=operator.company)
        seller = ShareholderGenerator().generate(company=operator.company)
        securities = TwoInitialSecuritiesGenerator().generate(
            company=operator.company)
        PositionGenerator().generate(number_segments=[u'1-5'],
                                     company=operator.company,
                                     buyer=seller,
                                     count=5,
                                     security=securities[1])

        for s in securities:
            s.track_numbers = True
            s.save()

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

        data = {
            "bought_at": "2016-05-13T23:00:00.000Z",
            "buyer": {
                "pk": buyer.pk,
                "user": {
                    "first_name": buyer.user.first_name,
                    "last_name": buyer.user.last_name,
                    "email": buyer.user.email,
                    "operator_set": [],
                    "userprofile": None,
                },
                "number": "0",
                "company": {
                    "pk":
                    operator.company.pk,
                    "name":
                    operator.company.name,
                    "share_count":
                    operator.company.share_count,
                    "country":
                    "",
                    "url":
                    "http://codingmachine:9000/services/rest/"
                    "company/{}".format(operator.company.pk),
                    "shareholder_count":
                    2
                },
                "share_percent": "99.90",
                "share_count": 100002,
                "share_value": 1000020,
                "validate_gafi": {
                    "is_valid": True,
                    "errors": []
                }
            },
            "security": {
                "pk": securities[1].pk,
                "readable_title": "Preferred Stock",
                "title": "P",
                "count": 3
            },
            "count": 5,
            "value": 1,
            "seller": {
                "pk": seller.pk,
                "user": {
                    "first_name": seller.user.first_name,
                    "last_name": seller.user.last_name,
                    "email": seller.user.email,
                    "operator_set": [],
                    "userprofile": None
                },
                "number": "0",
                "company": {
                    "pk": 5,
                    "name": "LieblingzWaldCompany AG",
                    "share_count": 100100,
                    "country": "",
                    "url": "http://codingmachine:9000/services/rest/company/5",
                    "shareholder_count": 2
                },
                "share_percent": "99.90",
                "share_count": 100002,
                "share_value": 1000020,
                "validate_gafi": {
                    "is_valid": True,
                    "errors": []
                }
            },
            "number_segments": "1,2,3-5",
            "comment": "sdfg"
        }

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

        self.assertEqual(response.status_code, 201)
        self.assertTrue('sdfg' in response.content)
        self.assertEqual(response.data['number_segments'], [u'1-5'])

        position = Position.objects.latest('id')
        self.assertEqual(position.count, 5)
        self.assertEqual(position.value, 1)
        self.assertEqual(position.buyer, buyer)
        self.assertEqual(position.seller, seller)
        self.assertEqual(position.bought_at.isoformat(), '2016-05-13')
        self.assertEqual(position.number_segments, [u'1-5'])