Ejemplo n.º 1
0
def test_get_information_ioerror():

    app = TindevQA()
    filename = "configuration.json"
    when(builtins.open(filename)).read().thenRaise(IOError)
    actual_result = app.get_information_from_file(filename)

    assert actual_result == "ERROR"
Ejemplo n.º 2
0
def test_get_information_valueerror():
    app = TindevQA()
    filename = "configuration.json"
    when(json).loads(...).thenRaise(ValueError)

    actual_result = app.get_information_from_file(filename)

    assert actual_result == "ERROR"
Ejemplo n.º 3
0
def test_send_sms_get_timeout():
    app = TindevQA()
    user = '******'
    text = 'Quieres enredarte entre mis pelos?'
    when(requests).post(...).thenRaise(Timeout)

    response = app.send_sms(user, text)
    assert response == "ERROR"
Ejemplo n.º 4
0
def test_person2_dislikes_person1_parameters(mock_let_down):

    app = TindevQA()
    person1 = 'Luke'
    person2 = {'name': 'Leia', 'likes': ['Han Solo'], 'dislikes': ['Luke']}

    app.evaluate(person1, person2)

    mock_let_down.assert_called_once_with(person1)
Ejemplo n.º 5
0
def test_person2_dislikes_person1(mock_let_down):

    app = TindevQA()
    person1 = 'Luke'
    person2 = {'name': 'Leia', 'likes': ['Han Solo'], 'dislikes': ['Luke']}

    app.evaluate(person1, person2)

    assert mock_let_down.call_count == 1
def test_get_information_ioerror(mock_open):
    app = TindevQA()
    filename = "configuration.json"

    mock_open.side_effect = IOError

    actual_result = app.get_information_from_file(filename)

    assert actual_result == "ERROR"
Ejemplo n.º 7
0
def test_send_sms_with_mockito():
    app = TindevQA()
    user = '******'
    text = 'Quieres enredarte entre mis pelos?'
    response_mock = mock({'status_code': 200, 'text': 'Ok'})
    when(requests).post(...).thenReturn(response_mock)

    response = app.send_sms(user, text)
    assert response.status_code == 200
Ejemplo n.º 8
0
def test_send_sms_get_500_error():
    app = TindevQA()
    user = '******'
    text = 'Quieres enredarte entre mis pelos?'
    response_mock = mock({'status_code': 501})
    when(requests).post(...).thenReturn(response_mock)

    response = app.send_sms(user, text)
    assert response.status_code == 501
Ejemplo n.º 9
0
def test_person2_dislikes_person1():

    app = TindevQA()
    person1 = 'Luke'
    person2 = {'name': 'Leia', 'likes': ['Han Solo'], 'dislikes': ['Luke']}
    when(app).let_down_gently(...)
    app.evaluate(person1, person2)

    verify(app, times=1).let_down_gently(...)
Ejemplo n.º 10
0
def test_get_valid_json():
    app = TindevQA()
    filename = "configuration.json"
    expected_result = {'name': 'Leia', 'likes': ['Han Solo'], 'dislikes': ['Luke']}

    mock_file = mock()
    when(mock_file).read().thenReturn('{"name": "Leia", "likes": ["Han Solo"], "dislikes": ["Luke"]}')
    when(builtins).open(filename).thenReturn(mock_file)
    actual_result = app.get_information_from_file(filename)
    assert expected_result == actual_result
Ejemplo n.º 11
0
def test_new_person():
    # Arrange
    app = TindevQA()
    user = {'people_seen': []}
    expected_person = 'Alexandra'

    # Action
    actual_person = app.get_next_person(user)

    # Assert
    assert actual_person == expected_person
Ejemplo n.º 12
0
def test_send_sms_with_error():
    app = TindevQA()
    user = '******'
    text = 'Quieres enredarte entre mis pelos?'
    data = {'status_code': 500, 'message': 'Servidor Caido'}

    r = requests.post('http://localhost:8080/set_response', json=data)

    response = app.send_sms(user, text)
    assert response.status_code == 500
    assert response.text == 'Servidor Caido'
Ejemplo n.º 13
0
def test_person2_dislikes_person1_multiple_mocks(mock_let_down, mock_send_mail,
                                                 mock_give_it_time):

    app = TindevQA()
    person1 = 'Luke'
    person2 = {'name': 'Leia', 'likes': ['Han Solo'], 'dislikes': ['Luke']}

    app.evaluate(person1, person2)

    mock_let_down.assert_called_once_with(person1)
    assert mock_send_mail.call_count == 0
    assert mock_give_it_time.call_count == 0
Ejemplo n.º 14
0
def test_new_person_several_times(mock_get_random_user):

    app = TindevQA()
    user = {'people_seen': ['Sara', 'Alexandra']}
    expected_person = 'Leia'
    mock_get_random_user.side_effect = ['Alexandra', 'Sara', 'Leia']

    # Action
    actual_person = app.get_next_person(user)

    # Assert
    assert actual_person == expected_person
Ejemplo n.º 15
0
def test_new_person_decorator(mock_get_random_user):
    # Arrange
    app = TindevQA()
    user = {'people_seen': []}
    expected_person = 'Alexandra'
    mock_get_random_user.return_value = 'Alexandra'

    # Action
    actual_person = app.get_next_person(user)

    # Assert
    assert actual_person == expected_person
Ejemplo n.º 16
0
def test_new_person_decorator():
    # Arrange
    app = TindevQA()
    user = {'people_seen': []}
    expected_person = 'Alexandra'
    when(app).get_random_user().thenReturn('Alexandra')

    # Action
    actual_person = app.get_next_person(user)

    # Assert
    assert actual_person == expected_person
Ejemplo n.º 17
0
def test_person2_likes_person1(mock_send_mail):

    app = TindevQA()
    person1 = 'Han Solo'
    person2 = {'name': 'Leia', 'likes': ['Han Solo'], 'dislikes': ['Luke']}

    app.evaluate(person1, person2)

    person1_mail_received = mock_send_mail.call_args_list[0]
    person2_mail_received = mock_send_mail.call_args_list[1]
    assert person1_mail_received == call(person1)
    assert person2_mail_received == call(person2)
def test_get_information_valueerror(mock_open, mock_loads):
    app = TindevQA()
    filename = "configuration.json"

    mock_file = Mock()
    mock_file.read.return_value = '{"name": "Leia", "likes": ["Han Solo"], "dislikes": ["Luke"]}'
    mock_open.return_value = mock_file
    mock_loads.side_effect = ValueError

    actual_result = app.get_information_from_file(filename)

    assert actual_result == "ERROR"
Ejemplo n.º 19
0
def test_new_person_several_times():

    app = TindevQA()
    user = {'people_seen': ['Sara', 'Alexandra']}
    expected_person = 'Leia'
    when(app).get_random_user().thenReturn('Alexandra', 'Sara', 'Leia')

    # Action
    actual_person = app.get_next_person(user)

    # Assert
    assert actual_person == expected_person
Ejemplo n.º 20
0
def test_new_person_context_manager():
    with patch.object(TindevQA, "get_random_user") as mock_get_random_user:
        # Arrange
        app = TindevQA()
        user = {'people_seen': []}
        expected_person = 'Alexandra'
        mock_get_random_user.return_value = 'Alexandra'

        # Action
        actual_person = app.get_next_person(user)

        # Assert
        assert actual_person == expected_person
Ejemplo n.º 21
0
def test_person2_likes_person1():

    app = TindevQA()
    person1 = 'Han Solo'
    person2 = {'name': 'Leia', 'likes': ['Han Solo'], 'dislikes': ['Luke']}

    when(app).send_email(...)

    app.evaluate(person1, person2)

    verify(app, times=2).send_email(...)
    verify(app, times=1).send_email(person1)
    verify(app, times=1).send_email(person2)
Ejemplo n.º 22
0
def test_send_sms():

    app = TindevQA()
    user = '******'
    text = 'Quieres enredarte entre mis pelos?'
    response = app.send_sms(user, text)

    r = requests.get('http://localhost:8080/stats')
    body = r.json()

    assert body['requests'][0]['from'] == 'Chewaka'
    assert body['requests'][0]['to'] == '34677722314'
    assert body['requests'][0]['text'] == 'Quieres enredarte entre mis pelos?'
Ejemplo n.º 23
0
def test_person2_dislikes_person1_multiple_mocks():

    app = TindevQA()
    person1 = 'Luke'
    person2 = {'name': 'Leia', 'likes': ['Han Solo'], 'dislikes': ['Luke']}

    when(app).let_down_gently(person1)
    when(app).send_email(...)
    when(app).give_it_time(...)

    app.evaluate(person1, person2)
    verify(app, times=1).let_down_gently(person1)
    verify(app, times=0).send_email(...)
    verify(app, times=0).give_it_time(...)
def test_get_valid_json(mock_open):
    app = TindevQA()
    filename = "configuration.json"
    expected_result = {
        'name': 'Leia',
        'likes': ['Han Solo'],
        'dislikes': ['Luke']
    }

    mock_file = Mock()
    mock_file.read.return_value = '{"name": "Leia", "likes": ["Han Solo"], "dislikes": ["Luke"]}'
    mock_open.return_value = mock_file

    actual_result = app.get_information_from_file(filename)

    assert actual_result == expected_result
Ejemplo n.º 25
0
def test_send_sms():
    app = TindevQA()
    user = '******'
    text = 'Quieres enredarte entre mis pelos?'
    response = app.send_sms(user, text)
    assert response.ok == True