Exemplo n.º 1
0
    def test_create_account(self):
        """ Create a new Account """
        account = AccountFactory()
        resp = self.app.post(
            "/accounts", 
            json=account.serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
        
        # Make sure location header is set
        location = resp.headers.get("Location", None)
        self.assertIsNotNone(location)
        
        # Check the data is correct
        new_account = resp.get_json()
        self.assertEqual(new_account["name"], account.name, "Names does not match")
        self.assertEqual(new_account["addresses"], account.addresses, "Address does not match")
        self.assertEqual(new_account["email"], account.email, "Email does not match")
        self.assertEqual(new_account["phone_number"], account.phone_number, "Phone does not match")
        self.assertEqual(new_account["date_joined"], str(account.date_joined), "Date Joined does not match")

        # Check that the location header was correct by getting it
        resp = self.app.get(location, content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        new_account = resp.get_json()
        self.assertEqual(new_account["name"], account.name, "Names does not match")
        self.assertEqual(new_account["addresses"], account.addresses, "Address does not match")
        self.assertEqual(new_account["email"], account.email, "Email does not match")
        self.assertEqual(new_account["phone_number"], account.phone_number, "Phone does not match")
        self.assertEqual(new_account["date_joined"], str(account.date_joined), "Date Joined does not match")
Exemplo n.º 2
0
 def test_unsupported_media_type(self):
     """ Send wrong media type """
     account = AccountFactory()
     resp = self.app.post(
         "/accounts", 
         json=account.serialize(), 
         content_type="test/html"
     )
     self.assertEqual(resp.status_code, status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
Exemplo n.º 3
0
    def test_payment_is_not_created_with_zero_amount(self):
        account1 = AccountFactory(currency=self.currency, balance=10)
        account2 = AccountFactory(currency=self.currency, balance=0)

        response = self.client.post(self.url,
                                    data={
                                        'from_account': account1.name,
                                        'to_account': account2.name,
                                        'amount': 0,
                                    })

        self.assertContains(response,
                            'amount must be positive',
                            status_code=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 4
0
    def test_payment_is_not_created_with_currency_mismatch_for_sender(self):
        account1 = AccountFactory(currency=CurrencyFactory(), balance=10)
        account2 = AccountFactory(currency=self.currency, balance=10)

        response = self.client.post(self.url,
                                    data={
                                        'from_account': account1.name,
                                        'to_account': account2.name,
                                        'amount': 1,
                                    })

        self.assertContains(response,
                            'currency mismatch',
                            status_code=status.HTTP_400_BAD_REQUEST)
        self.assertEquals(0, Payment.objects.count())
Exemplo n.º 5
0
    def test_payment_is_not_created_with_unsufficient_funds(self):
        account1 = AccountFactory(currency=self.currency, balance=0)
        account2 = AccountFactory(currency=self.currency, balance=0)

        response = self.client.post(self.url,
                                    data={
                                        'from_account': account1.name,
                                        'to_account': account2.name,
                                        'amount': 1,
                                    })

        self.assertContains(response,
                            'unsufficient funds',
                            status_code=status.HTTP_400_BAD_REQUEST)
        self.assertEquals(0, Payment.objects.count())
Exemplo n.º 6
0
 def _create_accounts(self, count):
     """ Factory method to create accounts in bulk """
     accounts = []
     for _ in range(count):
         account = AccountFactory()
         resp = self.app.post(
             "/accounts", json=account.serialize(), content_type="application/json"
         )
         self.assertEqual(
             resp.status_code, status.HTTP_201_CREATED, "Could not create test Account"
         )
         new_account = resp.get_json()
         account.id = new_account["id"]
         accounts.append(account)
     return accounts
 def setUp(self):
     self.client = APIClient()
     self.user_payload = {
         "email": "*****@*****.**",
         "password": "******"
     }
     self.user = AccountFactory()
Exemplo n.º 8
0
 def test_bad_request(self):
     """ Send wrong media type """
     account = AccountFactory()
     resp = self.app.post(
         "/accounts", 
         json={"name": "not enough data"}, 
         content_type="application/json"
     )
     self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 9
0
 def test_non_empty_list(self):
     account = AccountFactory(balance=42)
     expected_dict = {
         'name': account.name,
         'balance': '42.00',
         'currency': account.currency.code,
     }
     resp = self.client.get(self.url)
     self.assertEqual([expected_dict], resp.data)
Exemplo n.º 10
0
 def _create_account(self, addresses=[]):
     """ Creates an account from a Factory """
     fake_account = AccountFactory()
     account = Account(name=fake_account.name,
                       email=fake_account.email,
                       phone_number=fake_account.phone_number,
                       date_joined=fake_account.date_joined,
                       addresses=addresses)
     self.assertTrue(account != None)
     self.assertEqual(account.id, None)
     return account
Exemplo n.º 11
0
    def test_update_account(self):
        """ Update an existing Account """
        # create an Account to update
        test_account = AccountFactory()
        resp = self.app.post(
            "/accounts", 
            json=test_account.serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        # update the pet
        new_account = resp.get_json()
        new_account["name"] = "Happy-Happy Joy-Joy"
        resp = self.app.put(
            "/accounts/{}".format(new_account["id"]),
            json=new_account,
            content_type="application/json",
        )
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        updated_account = resp.get_json()
        self.assertEqual(updated_account["name"], "Happy-Happy Joy-Joy")
Exemplo n.º 12
0
 def test_create_an_account(self):
     """ Create a Account and assert that it exists """
     fake_account = AccountFactory()
     account = Account(name=fake_account.name,
                       email=fake_account.email,
                       phone_number=fake_account.phone_number,
                       date_joined=fake_account.date_joined)
     self.assertTrue(account != None)
     self.assertEqual(account.id, None)
     self.assertEqual(account.name, fake_account.name)
     self.assertEqual(account.email, fake_account.email)
     self.assertEqual(account.phone_number, fake_account.phone_number)
     self.assertEqual(account.date_joined, fake_account.date_joined)
Exemplo n.º 13
0
    def test_payment_is_created_with_normal_conditions(self):
        account1 = AccountFactory(currency=self.currency, balance=10)
        account2 = AccountFactory(currency=self.currency, balance=0)

        response = self.client.post(self.url,
                                    data={
                                        'from_account': account1.name,
                                        'to_account': account2.name,
                                        'amount': 1,
                                    })

        self.assertEquals(status.HTTP_201_CREATED, response.status_code)
        account1.refresh_from_db()
        self.assertEquals(9, account1.balance)
        account2.refresh_from_db()
        self.assertEquals(1, account2.balance)
        self.assertEquals(1, Payment.objects.count())
Exemplo n.º 14
0
 def create_factories(self):
     super().create_factories()
     self.team_account = AccountFactory.create(type='ASSET',
                                               name='Team Network')
     self.team_account.patterns = [
         AccountPattern(pattern=r"2[0-9]{3}-N\d\d")
     ]
     self.bank_account = BankAccountFactory.create()
     self.activity, *rest = (BankAccountActivityFactory.create(
         bank_account=self.bank_account,
         reference=reference) for reference in [
             'Erstattung 2020-N15 (Pizza)',
             'Erstattung 2020-NN',
             'Other reference, which should not match our regex',
         ])
Exemplo n.º 15
0
    def create_account(self, balance='100.00', transactions=None, **kwargs):
        """
        Creates a test account with some basic data
        :param balance:
        :param transactions:
        :param kwargs:
        :return: Account object
        """
        if not transactions:
            transactions = []

        account = AccountFactory(
            balance=Decimal(balance),
            transactions=transactions,
            **kwargs
        )
        db.session.add(account)
        db.session.commit()
        return account
Exemplo n.º 16
0
def liability_account(module_session):
    return AccountFactory(type='LIABILITY')
Exemplo n.º 17
0
def revenue_account(module_session):
    return AccountFactory(type='REVENUE')
Exemplo n.º 18
0
def asset_account(module_session):
    return AccountFactory(type='ASSET')
Exemplo n.º 19
0
 def test_should_not_delete_related_goal(self):
     account = AccountFactory.create()
     GoalFactory(accounts=[account], user=account.user)
     account.delete()
     self.assertEqual(Goal.query.count(), 1)
     self.assertEqual(Account.query.count(), 0)
Exemplo n.º 20
0
 def test_should_delete_accounts_belonging_to_it(self):
     institution = AccountFactory.create().institution
     institution.delete()
     self.assertEqual(Institution.query.count(), 0)
     self.assertEqual(Account.query.count(), 0)
Exemplo n.º 21
0
 def test_should_delete_accounts(self):
     user = AccountFactory.create().user
     user.delete()
     self.assertEqual(User.query.count(), 0)
     self.assertEqual(Account.query.count(), 0)
 def test_create_account_twice(self):
     AccountFactory(**self.user_payload)
     res = self.client.post(CREATE_ACCOUNT_ROUTE, self.user_payload)
     self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertEqual(res.data['email'][0], 'already exists')
Exemplo n.º 23
0
 def setUp(self):
     self.user = AccountFactory()
     self.client = APIClient()
     self.client.force_authenticate(user=self.user)
Exemplo n.º 24
0
 def test_update_balance(self):
     account = AccountFactory(balance=10)
     account.update_balance(42)
     account.refresh_from_db()
     self.assertEquals(account.balance, 52)
Exemplo n.º 25
0
 def setUp(self):
     self.user = AccountFactory()
     self.client = APIClient()
     self.client.force_authenticate(user=self.user)
     self.meet_up = MeetUpFactory()
     self.question = QuestionFactory()
Exemplo n.º 26
0
def account_factory(db_client_or_tx: DBAnyConn) -> AccountFactory:
    """Create Account in the database."""
    return AccountFactory(db_client_or_tx)