def test_handle_creates_the_expense(self, message, state):
        action = self.build_action(message, state)
        count = Expense.count()

        action.handle()

        assert Expense.count() == count + 1
Ejemplo n.º 2
0
    def handle(self):
        expense = Expense(category=self._expense_category())
        expense.save()

        new_state = self._compose_new_state(expense)
        self.state_manager.set(new_state)

        self.telegram.reply(self.message, self.TELEGRAM_REPLY)
    def test_handle_publishes_the_expense(self, state, message, sns_client):
        expected_expense = Expense(id='abcdef', category='Some category', amount=42.24, notes='description of the expense')
        expected_expense.save()
        action = self.build_action(message, state)
        action._expense = expected_expense

        action.handle()

        sns_client.money_spent.assert_called_once_with(expected_expense)
    def test_handle_sends_a_telegram_response(self, state, message, sns_client):
        Expense(id='abcdef', category='random category').save()
        action = self.build_action(message, state)

        action.handle()

        action.telegram.reply.assert_called_once()
    def test_handle_sets_the_next_state(self, state, message, sns_client):
        Expense(id='abcdef', category='random category').save()
        action = self.build_action(message, state)

        action.handle()

        action.state_manager.set.assert_called_once_with('initial')
def test_to_dict_with_incomplete_expense():
    amount = 12
    category = 'Eating out'

    expense = Expense(amount=amount, category=category)
    serialized = ExpenseSerializer(expense).to_dict()

    assert serialized['amount'] == amount
    assert serialized['category'] == category
    assert 'notes' not in serialized
    assert serialized['id'] == expense.id
def test_to_dict():
    amount = 12
    category = 'Eating out'
    notes = 'Data of the expense'

    expense = Expense(amount=amount, notes=notes, category=category)
    serialized = ExpenseSerializer(expense).to_dict()

    assert serialized['amount'] == amount
    assert serialized['category'] == category
    assert serialized['notes'] == notes
    assert serialized['id'] == expense.id
    def test_handle_updates_the_expense(self, state, message, sns_client):
        expense = Expense(id='abcdef', category='random category')
        expense.save()
        action = self.build_action(message, state)

        assert not expense.notes

        action.handle()

        expense.refresh()
        assert expense.notes == 'Description of the expense'
    def test_handle_updates_the_expense(self, state, message):
        expense = Expense(id='abcdef', category='random category')
        expense.save()
        action = self.build_action(message, state)

        assert not expense.amount

        action.handle()

        expense.refresh()
        assert expense.amount == 12.40
Ejemplo n.º 10
0
def mock_dynamodb(aws_credentials):
    with moto.mock_dynamodb2() as dynamodb:
        Expense.create_table()
        yield
    def test_matches_if_text_is_an_amount_and_state_is_expense_amount(self, message, state):
        Expense(id='abcdef', category='random category').save()
        action = self.build_action(message, state)

        assert action.matches()
Ejemplo n.º 12
0
def test_expense_is_created():
    assert Expense.count() == 0
    Expense(id='test_id', amount=42, category='coca cola',
            notes='Test notes').save()
    assert Expense.count() == 1
Ejemplo n.º 13
0
def test_notes_is_not_mandatory():
    assert Expense.count() == 0
    Expense(category='coca cola', amount=42).save()
    assert Expense.count() == 1
Ejemplo n.º 14
0
def test_amount_is_not_mandatory():
    assert Expense.count() == 0
    Expense(category='coca cola', notes='test notes').save()
    assert Expense.count() == 1
Ejemplo n.º 15
0
def test_category_is_mandatory():
    with pytest.raises(ValueError):
        Expense(amount=42, notes='test notes').save()
Ejemplo n.º 16
0
def test_expense_is_set_automatically():
    expense = Expense(amount=42, category='coca cola', notes='test notes')
    assert expense.id is not None
Ejemplo n.º 17
0
    def expense(self):
        if not self._expense:
            self._expense = Expense.get(self._expense_id())

        return self._expense
    def test_does_not_match_if_text_is_not_expense_description(self, message, state):
        Expense(id='abcdef', category='random category').save()
        action = self.build_action(message, state)

        assert not action.matches()