Exemple #1
0
class TestTransactionViews(TestCase):
    """Test transaction views."""

    def setUp(self):
        """Create instances for testing."""
        self.user = UserFactory()
        self.user.set_password('password')
        self.user.save()
        self.budget = BudgetFactory(user=self.user)
        self.c = Client()
        self.transaction = TransactionFactory(budget=self.budget)

    def test_deny_access_if_not_authenticated(self):
        """Test the redirect if the user is not logged in."""
        res = self.c.get('/budgets/transactions/1', follow=True)
        self.assertEqual(res.status_code, 200)
        self.assertIn(b'class="login-form container"', res.content)

    def test_transaction_view(self):
        """Test that transactions will be available when logged in."""
        self.c.login(
            username=self.user.username,
            password='******'
        )

        res = self.c.get('/budgets/transactions/' + str(self.transaction.id))
        self.assertIn(self.transaction.amount.encode(), res.content)
        self.assertIn(self.transaction.description.encode(), res.content)
Exemple #2
0
class TestBudgetViews(TestCase):
    """Test the budget views."""

    def setUp(self):
        """Create instances for testing."""
        self.user = UserFactory()
        self.user.set_password('password')
        self.user.save()
        self.c = Client()

    def test_home_route(self):
        """Test the home route."""
        response = self.c.get('')
        assert b'Welcome' in response.content

    def test_access_denied(self):
        """Test that the user must be logged in to see the list view."""
        res = self.c.get('/budgets/budget', follow=True)
        self.assertEqual(res.status_code, 200)
        self.assertIn(b'class="login-form container"', res.content)

    def test_login_view(self):
        """Test the list route when logged in."""
        self.c.login(
            username=self.user.username,
            password='******'
        )

        budget = BudgetFactory(user=self.user)
        res = self.c.get('/budgets/budget')

        self.assertIn(budget.name.encode(), res.content)

    def test_list_correct_information(self):
        """Test to ensure that the logged  in user only sees their personal information."""
        self.c.login(
            username=self.user.username,
            password='******'
        )

        own_budget = BudgetFactory(user=self.user)
        other_budget = BudgetFactory()

        res = self.c.get('/budgets/budget')

        self.assertIn(own_budget.name.encode(), res.content)
        self.assertNotIn(other_budget.name.encode(), res.content)

    def test_transactions_listed_in_view(self):
        """Test that the budget view also lists the appropriate transactions."""
        self.c.login(
            username=self.user.username,
            password='******'
        )
        budget = BudgetFactory(user=self.user)
        transaction = TransactionFactory(budget=budget)
        res = self.c.get('/budgets/budget')

        self.assertIn(transaction.description.encode(), res.content)
Exemple #3
0
 def setUp(self):
     """Create instances for testing."""
     self.user = UserFactory()
     self.user.set_password('secret')
     self.user.save()
     self.budget = BudgetFactory(user=self.user)
     self.c = Client()
     self.transaction = TransactionFactory(budget=self.budget)
Exemple #4
0
    def setUp(self):
        self.user = UserFactory()
        self.user.set_password('secret')
        self.user.save()

        self.budget = BudgetFactory(user=self.user)

        self.c = Client()
Exemple #5
0
class TestBudgetViews(TestCase):
    """Test the budget views."""
    def setUp(self):
        """Create instances for testing."""
        self.user = UserFactory()
        self.user.set_password('secret')
        self.user.save()
        self.c = Client()

    def test_home_route(self):
        """Test the home route."""
        response = self.c.get('')
        assert b'what up' in response.content

    def test_denied_if_no_login(self):
        """Test that login is required for the budget routes."""
        res = self.c.get('/budgets/budget', follow=True)
        self.assertEqual(res.status_code, 200)
        self.assertIn(b'class="login-form container"', res.content)

    def test_view_list_when_logged_in(self):
        """Test the view list route when logged in."""
        self.c.login(username=self.user.username, password='******')

        budget = BudgetFactory(user=self.user)
        res = self.c.get('/budgets/budget')

        self.assertIn(budget.name.encode(), res.content)

    def test_lists_only_owned_budgets(self):
        """Test that a user only sees their own budgets."""
        self.c.login(username=self.user.username, password='******')

        own_budget = BudgetFactory(user=self.user)
        other_budget = BudgetFactory()

        res = self.c.get('/budgets/budget')

        self.assertIn(own_budget.name.encode(), res.content)
        self.assertNotIn(other_budget.name.encode(), res.content)

    def test_transactions_listed_in_view(self):
        """Test that budget view also lists transactions."""
        self.c.login(username=self.user.username, password='******')
        budget = BudgetFactory(user=self.user)
        transaction = TransactionFactory(budget=budget)
        res = self.c.get('/budgets/budget')

        self.assertIn(transaction.description.encode(), res.content)
Exemple #6
0
class TestBudgetCreateViews(TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.user.set_password('secret')
        self.user.save()
        self.c = Client()

    def test_create_view_adds_new_budget(self):
        self.c.login(username=self.user.username, password='******')

        form_data = {'name': 'new budget', 'total_budget': '100.0'}

        res = self.c.post('/budgets/budget/add', form_data, follow=True)

        # Confirms the record was retrieved from the database and presented in the view
        self.assertIn(b'new budget', res.content)
Exemple #7
0
class TestBudgetAPI(TestCase):
    """Tests for the RESTful User API"""

    def setUp(self):
        """Create instances for testing."""
        self.user = UserFactory()
        self.user.set_password('secret')
        self.user.save()

    def test_registration(self):
        user = {
            'id': '1',
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'first name': 'fred',
            'last_name': 'smith',
        }

        response = self.client.post('/api/v1/register', user)
        self.assertEqual(response.status_code, 201)
Exemple #8
0
class TestTransactionCreateViews(TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.user.set_password('secret')
        self.user.save()

        self.budget = BudgetFactory(user=self.user)

        self.c = Client()

    def test_create_view_adds_new_transaction(self):
        self.c.login(username=self.user.username, password='******')

        form_data = {
            'assigned_user': self.user,
            'type': 'WITHDRAWAL',
            'description': 'burgers',
            'amount': '20.0',
            'budget': self.budget.id
        }

        res = self.c.post('/budgets/transactions/add/', form_data, follow=True)
        self.assertIn(b'burgers', res.content)
Exemple #9
0
    def test_budget_api(self):
        budget = {
            'id': '1',
            'user': '******',
            'owner': 'user',
            'name': 'budget',
            'total_budget': '100.0',
        }

        user = UserFactory()
        url = reverse('budget-list-api')
        response = self.client.post(url, budget, format='json')
        force_authenticate(response, user=user, token=user.auth_token)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemple #10
0
class TestTransactionViews(TestCase):
    """Test transaction views."""
    def setUp(self):
        """Create instances for testing."""
        self.user = UserFactory()
        self.user.set_password('secret')
        self.user.save()
        self.budget = BudgetFactory(user=self.user)
        self.c = Client()
        self.transaction = TransactionFactory(budget=self.budget)

    def test_denied_if_no_login(self):
        """Test bounce if user isn't logged in."""
        res = self.c.get('/budgets/transactions/1', follow=True)
        self.assertEqual(res.status_code, 200)
        self.assertIn(b'class="login-form container"', res.content)

    def test_view_transaction_when_logged_in(self):
        """Test that transactions are viewable when logged in."""
        self.c.login(username=self.user.username, password='******')

        res = self.c.get('/budgets/transactions/' + str(self.transaction.id))
        self.assertIn(self.transaction.amount.encode(), res.content)
        self.assertIn(self.transaction.description.encode(), res.content)
Exemple #11
0
 def setUp(self):
     """Create instances for testing."""
     self.user = UserFactory()
     self.user.set_password('secret')
     self.user.save()
     self.c = Client()