예제 #1
0
    def test_import_with_invalid_url(self):
        # conditions
        get = Mock()

        # execution
        cmd = 'hello_world'
        rtn = import_character(cmd, self.db, get)

        # expected
        self.assertEqual(rtn, 'hello_world is not a valid URL')
예제 #2
0
    def test_valid_import(self):
        # conditions
        response = Mock()
        response.status_code = 200
        response.json = Mock(return_value=CHARACTER_JSON)
        get = Mock(return_value=response)

        # execution
        cmd = 'http://example.com/my/character'
        rtn = import_character(cmd, self.db, get)

        # expected
        self.db.save_character_info.assert_called_with('123456',
                                                       CHARACTER_JSON)
        self.assertEqual(rtn, 'Character "John Wick" imported successfully!')
예제 #3
0
    def test_import_with_request_error(self):
        # conditions
        response = Mock()
        response.status_code = 500
        get = Mock(return_value=response)

        # execution
        cmd = 'http://example.com/my/character'
        rtn = import_character(cmd, self.db, get)

        # expected
        self.assertEqual(
            rtn,
            'Error fetching http://example.com/my/character (status_code: 500)'
        )