def test_update_capitalcall_no_id(self):
     """Ensure error is thrown if an id is not provided."""
     UTILS.add_capitalcall('investment_1', 100)
     with self.client as client:
         response = client.put(
             '/capitalcalls/blah',
             data=json.dumps({'name': 'investment_2'}),
             content_type='application/json',
         )
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 404)
         self.assertIn(UTILS.NOT_EXISTS(TYPE, 'blah'), data['message'])
         self.assertIn('fail', data['status'])
         self.assertFalse(data['data'])
 def test_all_capitalcalls(self):
     """Ensure get all capitalcalls behaves correctly."""
     call1 = UTILS.add_capitalcall('invest1', 1000)
     call2 = UTILS.add_capitalcall('invest2', 2000)
     with self.client as client:
         response = client.get('/capitalcalls')
         data = json.loads(response.data.decode())
         calls = data['data']['capitalcalls']
         self.assertEqual(response.status_code, 200)
         self.assertEqual(len(calls), 2)
         self.assertEqual(call1.name, calls[0]['name'])
         self.assertEqual(call2.name, calls[1]['name'])
         self.assertEqual([], calls[0]['investments'])
         self.assertEqual([], calls[1]['investments'])
         self.assertIn('success', data['status'])
 def test_update_capitalcall_duplicate_name(self):
     """Ensure error is thrown if the updated capitalcall already exists."""
     capitalcall_1 = UTILS.add_capitalcall('investment_1', 100)
     capitalcall_2 = UTILS.add_capitalcall('investment_2', 100)
     with self.client as client:
         response = client.put(
             f'/capitalcalls/{capitalcall_2.id}',
             data=json.dumps({'name': 'investment_1'}),
             content_type='application/json',
         )
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 400)
         self.assertIn(UTILS.EXISTS(TYPE, 'investment_1'), data['message'])
         self.assertIn('fail', data['status'])
         self.assertEqual(capitalcall_1.id, data["data"]["id"])
Exemple #4
0
 def post(self):
     post_data = request.get_json()
     if not post_data:
         return UTILS.api_response(msg=UTILS.INVALID_PAYLD,
                                   code=400,
                                   data=self.__name__)
     name = post_data.get('name')
     capital = post_data.get('capital')
     date_str = post_data.get('date')
     date = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%f%z')
     try:
         call = CapitalCall.query \
             .filter_by(name=name) \
             .first()
         if not call:
             call_i = UTILS.add_capitalcall(name, capital, date=date)
             return UTILS.api_response(msg=UTILS.ADDED(TYPE, name),
                                       code=201,
                                       data=call_i.to_json())
         else:
             return UTILS.api_response(msg=UTILS.EXISTS(TYPE, name),
                                       code=400,
                                       data=call.to_json())
     except exc.IntegrityError as e:
         db.session.rollback()
         return UTILS.api_response(
             msg=f'{UTILS.INTEGRITY_ERR} {self.__name__}',
             code=400,
             data=f'{str(e)}')
 def test_single_capitalcall(self):
     """Ensure get single capitalcall behaves correctly."""
     capitalcall = UTILS.add_capitalcall('investment_1', 1000)
     with self.client as client:
         response = client.get(f'/capitalcalls/{capitalcall.id}')
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 200)
         self.assertIn('investment_1', data['data']['name'])
         self.assertIn('success', data['status'])
 def test_delete_capitalcall(self):
     """Ensure capitalcall is deleted"""
     capitalcall = UTILS.add_capitalcall('investment_1', 1000)
     with self.client as client:
         res = client.delete(f'/capitalcalls/{capitalcall.id}')
         data = json.loads(res.data.decode())
         self.assertEqual(res.status_code, 200)
         self.assertIn('success', data['status'])
         self.assertIn(UTILS.DELETED(TYPE, capitalcall.id), data['message'])
 def test_update_capitalcall_invalid_json(self):
     """Ensure error is thrown if the JSON object is empty."""
     capitalcall = UTILS.add_capitalcall('investment_1', 100)
     with self.client as client:
         response = client.put(f'/capitalcalls/{capitalcall.id}',
                               data=json.dumps({}),
                               content_type='application/json')
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 400)
         self.assertIn(UTILS.INVALID_PAYLD, data['message'])
         self.assertIn('fail', data['status'])
         self.assertFalse(data['data'])
 def setUp(self):
     super().setUp()
     self.fund_1 = UTILS.add_fund('fund_1')
     self.fund_2 = UTILS.add_fund('fund_2')
     self.fund_3 = UTILS.add_fund('fund_3')
     self.fund_4 = UTILS.add_fund('fund_4')
     self.fund_5 = UTILS.add_fund('fund_5')
     self.committment_1 = UTILS.add_committment(
         1, 1000, datetime.strptime('31/12/2017', '%d/%m/%Y'))
     self.committment_2 = UTILS.add_committment(
         2, 1500, datetime.strptime('31/03/2018', '%d/%m/%Y'))
     self.committment_3 = UTILS.add_committment(
         3, 1000, datetime.strptime('30/06/2018', '%d/%m/%Y'))
     self.committment_4 = UTILS.add_committment(
         4, 1500, datetime.strptime('30/09/2018', '%d/%m/%Y'))
     self.committment_5 = UTILS.add_committment(
         1, 1000, datetime.strptime('31/12/2018', '%d/%m/%Y'))
     self.capitalcall_1 = UTILS.add_capitalcall(
         'investment_1', 950, datetime.strptime('31/01/2018', '%d/%m/%Y'))
     self.capitalcall_2 = UTILS.add_capitalcall(
         'investment_2', 2000, datetime.strptime('30/04/2018', '%d/%m/%Y'))
 def test_update_capitalcall(self):
     """Ensure a capitalcall name can be updated in the database."""
     capitalcall = UTILS.add_capitalcall('investment_!', 1000)
     with self.client as client:
         response = client.put(f'/capitalcalls/{capitalcall.id}',
                               data=json.dumps({'name': 'investment_1'}),
                               content_type='application/json')
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 200)
         self.assertIn(UTILS.UPDATED(TYPE, 'investment_1'), data['message'])
         self.assertIn('success', data['status'])
         self.assertEqual(capitalcall.id, data["data"]["id"])
         self.assertEqual('investment_1', data["data"]["name"])
 def test_update_capitalcall_no_change(self):
     """
     Ensure correct response recieved for no change to updated capitalcall
     """
     capitalcall = UTILS.add_capitalcall('investment_1', 1000)
     with self.client as client:
         response = client.put(
             f'/capitalcalls/{capitalcall.id}',
             data=json.dumps({'capital': 1000}),
             content_type='application/json',
         )
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 400)
         self.assertIn(UTILS.NO_CHANGE(TYPE, 'investment_1'),
                       data['message'])
Exemple #11
0
def seed_db():
    """Seeds the database."""
    db.session.add(User(username='******', email="*****@*****.**"))
    db.session.add(User(username='******', email="*****@*****.**"))
    db.session.commit()
    UTILS.add_fund('fund_1')
    UTILS.add_fund('fund_2')
    UTILS.add_fund('fund_3')
    UTILS.add_fund('fund_4')
    UTILS.add_fund('fund_5')
    committment_1 = UTILS.add_committment(
        1, 10000000, datetime.strptime('31/12/2017', '%d/%m/%Y')
    )
    committment_2 = UTILS.add_committment(
        2, 15000000, datetime.strptime('31/03/2018', '%d/%m/%Y')
    )
    UTILS.add_committment(
        3, 10000000, datetime.strptime('30/06/2018', '%d/%m/%Y')
    )
    UTILS.add_committment(
        4, 15000000, datetime.strptime('30/09/2018', '%d/%m/%Y')
    )
    UTILS.add_committment(
        1, 10000000, datetime.strptime('31/12/2018', '%d/%m/%Y')
    )

    capitalcall_1 = UTILS.add_capitalcall(
        'investment_1', 9500000, datetime.strptime('31/01/2018', '%d/%m/%Y')
    )
    capitalcall_2 = UTILS.add_capitalcall(
        'investment_2', 10000000, datetime.strptime('30/04/2018', '%d/%m/%Y')
    )

    UTILS.add_fundinvestment(9500000, committment_1, capitalcall_1)
    UTILS.add_fundinvestment(500000, committment_1, capitalcall_2)
    UTILS.add_fundinvestment(9500000, committment_2, capitalcall_2)