def test_should_not_delete_related_transactions_or_user(self): user = UserFactory.create() goal = GoalFactory(user=user, transactions=[TransactionFactory.create(user=user)]) goal.delete() self.assertEqual(Goal.query.count(), 0) self.assertEqual(Transaction.query.count(), 1) self.assertEqual(User.query.count(), 1)
def test_should_delete_users_goals_and_transactions(self): for i in range(2): user = UserFactory.create() GoalFactory.create(user=user, transactions=[TransactionFactory.create(user=user)]) User.query.first().delete() self.assertEqual(User.query.count(), 1) self.assertEqual(Goal.query.count(), 1) self.assertEqual(Transaction.query.count(), 1)
def run(self): """Runs this command.""" if User.query.filter_by(email='*****@*****.**').first(): print('Example user and data already exists.') return user = UserFactory.instance.create(first_name='John', last_name='Smith', email='*****@*****.**', password=('matcha')) user.save() print('Created user `[email protected]` with password `matcha`') amex = AccessTokenFactory.create(user=user, institution__name='amex').institution bofa = AccessTokenFactory.create(user=user, institution__name='bofa').institution print('Created example institutions: amex, boa') fake = Faker() goal = GoalFactory.create(user=user, name='Roth IRA', amount=5500) for i in range(51): TransactionFactory.create(goals=[goal], institution=amex, name=fake.bs(), amount=fake.pydecimal(left_digits=3, right_digits=2), post_date=fake.date_time_this_year()) goal.save() print('Created goal `{}` with `{}` Transactions'.format(goal.name, 50)) goal = GoalFactory.create(user=user, name='Spend less on food', amount=1000) for j in range(51): TransactionFactory.create(goals=[goal], institution=bofa, name=fake.bs(), amount=fake.pydecimal(left_digits=3, right_digits=2), post_date=fake.date_time_this_month()) goal.save() print('Created goal `{}` with `{}` Transactions'.format(goal.name, 30))
def setUp(self): super().setUp() self.access_token = AccessTokenFactory.create() self.user = self.access_token.user self.token = generate_token_for_user(self.user) self.institution = self.access_token.institution self.transaction = TransactionFactory.create( user=self.user, institution=self.institution) self.deleted_user = UserFactory.create() self.nonexistent_token = generate_token_for_user(self.deleted_user) self.deleted_user.delete()
def test_get_transactions_with_no_institution_should_succeed(self): other_transaction = TransactionFactory.create(user=self.user) url = url_for('transactions_api.get_transactions') headers = self.create_headers(user=self.user) response = self.request_endpoint('GET', url, headers, status.HTTP_200_OK) self.assertListEqual( json.loads(response.data.decode('utf-8'))['transactions'], list( map(snake_to_camel_case_dict, [ self.transaction.serialize(), other_transaction.serialize() ])))
def test_should_delete_transactions_belonging_to_it(self): institution = TransactionFactory.create().institution institution.delete() self.assertEqual(Institution.query.count(), 0) self.assertEqual(Transaction.query.count(), 0)