def test_monkey_cwd(monkeypatch: monkeypatch):
    """
    Test monkeypatch pluggin.
    Args:
        monkeypatch (monkeypatch): injected monkeypatch
    """
    monkeypatch.setattr(os, "getcwd", lambda: "/")
Example #2
0
def test_monkey_cwd(monkeypatch: monkeypatch):
    """
    Test monkeypatch pluggin.
    Args:
        monkeypatch (monkeypatch): injected monkeypatch
    """
    monkeypatch.setattr(os, "getcwd", lambda: "/")
Example #3
0
	def test_remove_note_failure(self,monkeypatch):
		def mock_create_note_history(self,note_dict):
			pass
		def mock_delete_note(self,note_dict):
			raise
		monkeypatch.setattr(NotesDAO,'create_note_history',mock_create_note_history)
		monkeypatch.setattr(NotesDAO,'delete_note',mock_delete_note)
		result=NotesHandler().remove_note({'note_title':'test title','note_content':'test content','note_id':55})
		assert result=='FAILURE'
Example #4
0
	def test_update_note_success(self,monkeypatch):
		def mock_create_note_history(self,note_dict):
			pass
		def mock_update_note(self,note_dict):
			pass
		monkeypatch.setattr(NotesDAO,'create_note_history',mock_create_note_history)
		monkeypatch.setattr(NotesDAO,'update_note',mock_update_note)
		result=NotesHandler().update_note({'note_title':'test title','note_content':'test content','note_id':55})
		assert result=='SUCCESS'
def test_monkey_cwd_mock(monkeypatch: monkeypatch):
    """
    Test monkeypatch pluggin.
    Args:
        monkeypatch (monkeypatch): injected monkeypatch
    """
#    pdb.set_trace()
    cwd = Mock(return_value="/")
    monkeypatch.setattr(os, 'getcwd', cwd)
    assert os.getcwd() == '/'
Example #6
0
def test_monkey_cwd_mock(monkeypatch: monkeypatch):
    """
    Test monkeypatch pluggin.
    Args:
        monkeypatch (monkeypatch): injected monkeypatch
    """
    #    pdb.set_trace()
    cwd = Mock(return_value="/")
    monkeypatch.setattr(os, 'getcwd', cwd)
    assert os.getcwd() == '/'
def multi_config(monkeypatch):
    description = None
    
    file_1 = ("{\n"
              "    \"section_A\": [\n"
              "       {\n"
              "           \"prop_a\": \"val_a\",\n"
              "           \"prop_b\": \"val_b\"\n"
              "       },\n"
              "       {\n"
              "           \"prop_c\": \"val_c\",\n"
              "           \"prop_d\": \"val_d\"\n"
              "       }\n"
              "    ],\n"

              "    \"section_B\": [\n"
              "       {\n"
              "           \"prop_e\": \"val_e\",\n"
              "           \"prop_f\": \"val_f\"\n"
              "       },\n"
              "       {\n"
              "           \"prop_g\": \"val_g\",\n"
              "           \"prop_h\": \"val_h\"\n"
              "       }\n"
              "    ]\n"
              "}\n"
              )
    file_2 = ("{\n"
              "    \"section_B\": [\n"
              "       {\n"
              "           \"prop_i\": \"val_i\",\n"
              "           \"prop_j\": \"val_j\"\n"
              "       }\n"
              "    ],\n"
              "    \"section_C\": [\n"
              "       {\n"
              "           \"prop_k\": \"val_k\",\n"
              "           \"prop_l\": \"val_l\"\n"
              "       }\n"
              "    ]\n"
              "}\n"
              )

    monkeypatch.setattr(__builtin__, 'open', mock_open(read_data=file_1))
    parser = DescriptionParser()
    description = parser.read("mock_1.json")
    monkeypatch.undo()
        
    monkeypatch.setattr(__builtin__, 'open', mock_open(read_data=file_2))
    parser = DescriptionParser()
    parser.read("mock_2.json", description)
    
    return description
def multi_config(monkeypatch):
    description = None

    file_1 = ("{\n"
              "    \"section_A\": [\n"
              "       {\n"
              "           \"prop_a\": \"val_a\",\n"
              "           \"prop_b\": \"val_b\"\n"
              "       },\n"
              "       {\n"
              "           \"prop_c\": \"val_c\",\n"
              "           \"prop_d\": \"val_d\"\n"
              "       }\n"
              "    ],\n"
              "    \"section_B\": [\n"
              "       {\n"
              "           \"prop_e\": \"val_e\",\n"
              "           \"prop_f\": \"val_f\"\n"
              "       },\n"
              "       {\n"
              "           \"prop_g\": \"val_g\",\n"
              "           \"prop_h\": \"val_h\"\n"
              "       }\n"
              "    ]\n"
              "}\n")
    file_2 = ("{\n"
              "    \"section_B\": [\n"
              "       {\n"
              "           \"prop_i\": \"val_i\",\n"
              "           \"prop_j\": \"val_j\"\n"
              "       }\n"
              "    ],\n"
              "    \"section_C\": [\n"
              "       {\n"
              "           \"prop_k\": \"val_k\",\n"
              "           \"prop_l\": \"val_l\"\n"
              "       }\n"
              "    ]\n"
              "}\n")

    monkeypatch.setattr(__builtin__, 'open', mock_open(read_data=file_1))
    parser = DescriptionParser()
    description = parser.read("mock_1.json")
    monkeypatch.undo()

    monkeypatch.setattr(__builtin__, 'open', mock_open(read_data=file_2))
    parser = DescriptionParser()
    parser.read("mock_2.json", description)

    return description
def test_main(monkeypatch):
    ctx = FakeSetMetadataContext()
    monkeypatch.setattr(touch, '_set_metadata', ctx)
    touch.main([
        'exe', 'bar.example.com',
        '-s', 'borg.something.local',
        '-p', '/fizz/buzz',
        '-P', 'hose-it-up',
        '-T', 'Sporks'
    ])
    assert ctx.args[1] == 'hose-it-up'
    assert ctx.args[2] == 'bar.example.com'
    assert ctx.args[3] == 'Sporks'
    assert ctx.args[4] == '/fizz/buzz'
def test_main(monkeypatch, fake_environ):
    @classmethod
    def fake_inventory(cls, **kwargs):
        cls.inventory_args = kwargs

    monkeypatch.setattr(
        sdc_listmachines_cache_wrapper.SDCListmachinesCacheWrapper,
        'inventory',
        fake_inventory
    )
    monkeypatch.setattr('os.environ', fake_environ)

    sdc_listmachines_cache_wrapper.main([
        'exe',
        '-a', '5000',
        '-e', '/Users/derp/bin/sdc-listmachines',
    ])

    inventory_args = sdc_listmachines_cache_wrapper.\
        SDCListmachinesCacheWrapper.inventory_args

    assert inventory_args['cache_path'] is None
    assert inventory_args['cache_max_age'] == '5000'
    assert inventory_args['exe'] == '/Users/derp/bin/sdc-listmachines'
Example #11
0
def test_returns_correct_string(mock_open, monkeypatch):
    mock_exists = MagicMock(return_value=True)
    monkeypatch.setattr('os.path.exists', mock_exists)
    result = read_from_file('blah')
    mock_open.assert_called_once_with('blah', 'r')
    assert result == 'test line'
Example #12
0
def mock_open(monkeypatch):
    mock_file = MagicMock()
    mock_file.readline = MagicMock(return_value='test line')
    mock_open = MagicMock(return_value=mock_file)
    monkeypatch.setattr('builtins.open', mock_open)
    return mock_open
Example #13
0
 def test_method_wiki_is_ok(self, monkeypatch):  #  Utiliser le mock
     '''tester si google api return la bonne reponse  '''
     question_test = change_question(questions['response'])
     question_test['texte'] = question_test['texte'].replace('\n', '')
     monkeypatch.setattr('requests.get', response_wiki)
     assert question_test['texte'] == response_wiki['texte']
Example #14
0
 def test_method_google_is_ok(self, monkeypatch):  #  Utiliser le mock
     '''tester si google api return la bonne reponse  '''
     question_test = change_question(questions['response'])
     monkeypatch.setattr('requests.get', response_google)
     assert question_test[
         'adresse'] == '7 Cité Paradis, 75010 Paris, France'
Example #15
0
 def test_method_question_is_ok(self, monkeypatch):
     '''tester le mot cle dans la question '''
     question_test = Processing(questions['response'])
     question_test.question_process()
     monkeypatch.setattr('requests.get', response_google)
     assert question_test.key_word == 'Openclassrooms'
Example #16
0
	def test_get_active_notes_success(self,monkeypatch):
		def mock_fetch_active_notes(self):
			return [{'note_id':5,'note_title':'test','note_content':'test content','status':1,'created_datetime':'2017-05-05','modified_datetime':'2017-05-05'}]
		monkeypatch.setattr(NotesDAO,'fetch_active_notes',mock_fetch_active_notes)
		result=NotesHandler().get_active_notes()
		assert result['notes'][0]['note_id']==5	
Example #17
0
	def test_get_active_notes_failure(self,monkeypatch):
		def mock_fetch_active_notes_exception(self):
			raise
		monkeypatch.setattr(NotesDAO,'fetch_active_notes',mock_fetch_active_notes_exception)
		with pytest.raises(Exception) as exception:
			result=NotesHandler().get_active_notes()
def test_uses_fresh_cache(wrapper, monkeypatch, sampledata):
    monkeypatch.setattr(wrapper, '_is_cache_valid', lambda self: True)
    monkeypatch.setattr(wrapper, 'inventory',
                        sampledata['joyent']['sdc_listmachines'])
Example #19
0
def test_throws_exceptions_with_bad_file(mock_open, monkeypatch):
    mock_exists = MagicMock(return_value=False)
    monkeypatch.setattr('os.path.exists', mock_exists)
    with raises(Exception):
        result = read_from_file('blah')
Example #20
0
	def test_get_history_failure(self,monkeypatch):
		def mock_fetch_history(self,note_dict):
			raise
		monkeypatch.setattr(NotesDAO,'fetch_history',mock_fetch_history)
		result=NotesHandler().get_history(note_id=55)
		assert result=='FAILURE'
Example #21
0
	def test_get_history_success(self,monkeypatch):
		def mock_fetch_history(self,note_dict):
			return [{'note_id':5,'note_title':'test','note_content':'test content','status':1,'created_datetime':datetime.datetime.now(),'modified_datetime':datetime.datetime.now()}]
		monkeypatch.setattr(NotesDAO,'fetch_history',mock_fetch_history)
		result=NotesHandler().get_history(note_id=55)
		assert result[0]['note_id']==5
Example #22
0
	def test_get_new_note_id_success(self,monkeypatch):
		def mock_get_new_note_id(self,note_dict):
			return 6
		monkeypatch.setattr(NotesDAO,'insert_note',mock_get_new_note_id)
		result=NotesHandler().get_new_note_id()
		assert result['note_id']==6
Example #23
0
	def test_get_new_note_id_failure(self,monkeypatch):
		def mock_get_new_note_id_exception(self,note_dict):
			raise
		monkeypatch.setattr(NotesDAO,'insert_note',mock_get_new_note_id_exception)
		with pytest.raises(Exception) as exception:
			result=NotesHandler().get_new_note_id()