from raven.conf import load
from unittest2 import TestCase


class LoadTest(TestCase):
    def test_basic(self):
        dsn = 'https://foo:bar@sentry.local/1'
        res = {}
        load(dsn, res)
        self.assertEquals(res, {
            'SENTRY_PROJECT': '1',
            'SENTRY_SERVERS': ['https://sentry.local/api/store/'],
            'SENTRY_PUBLIC_KEY': 'foo',
            'SENTRY_SECRET_KEY': 'bar',
        })

    def test_path(self):
        dsn = 'https://foo:bar@sentry.local/app/1'
        res = {}
        load(dsn, res)
        self.assertEquals(res, {
            'SENTRY_PROJECT': '1',
            'SENTRY_SERVERS': ['https://sentry.local/app/api/store/'],
            'SENTRY_PUBLIC_KEY': 'foo',
            'SENTRY_SECRET_KEY': 'bar',
        })

import logging
import mock
from raven.conf import load, setup_logging
from unittest2 import TestCase


class LoadTest(TestCase):
    def test_basic(self):
        dsn = 'https://foo:bar@sentry.local/1'
        res = {}
        load(dsn, res)
        self.assertEquals(res, {
            'SENTRY_PROJECT': '1',
            'SENTRY_SERVERS': ['https://sentry.local/api/store/'],
            'SENTRY_PUBLIC_KEY': 'foo',
            'SENTRY_SECRET_KEY': 'bar',
        })

    def test_path(self):
        dsn = 'https://foo:bar@sentry.local/app/1'
        res = {}
        load(dsn, res)
        self.assertEquals(res, {
            'SENTRY_PROJECT': '1',
            'SENTRY_SERVERS': ['https://sentry.local/app/api/store/'],
            'SENTRY_PUBLIC_KEY': 'foo',
            'SENTRY_SECRET_KEY': 'bar',
        })


class SetupLoggingTest(TestCase):
    def test_basic_not_configured(self):
        with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
            logger = getLogger()
            logger.handlers = []
            handler = mock.Mock()
            result = setup_logging(handler)
            self.assertTrue(result)

    def test_basic_already_configured(self):
        with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
            handler = mock.Mock()
            logger = getLogger()
            logger.handlers = [handler]
            result = setup_logging(handler)
            self.assertFalse(result)

Add basic coverage for the setup_logging method
Add basic coverage for the setup_logging method

+ import logging
+ import mock
- from raven.conf import load
+ from raven.conf import load, setup_logging
  from unittest2 import TestCase
  
  
  class LoadTest(TestCase):
      def test_basic(self):
          dsn = 'https://foo:bar@sentry.local/1'
          res = {}
          load(dsn, res)
          self.assertEquals(res, {
              'SENTRY_PROJECT': '1',
              'SENTRY_SERVERS': ['https://sentry.local/api/store/'],
              'SENTRY_PUBLIC_KEY': 'foo',
              'SENTRY_SECRET_KEY': 'bar',
          })
  
      def test_path(self):
          dsn = 'https://foo:bar@sentry.local/app/1'
          res = {}
          load(dsn, res)
          self.assertEquals(res, {
              'SENTRY_PROJECT': '1',
              'SENTRY_SERVERS': ['https://sentry.local/app/api/store/'],
              'SENTRY_PUBLIC_KEY': 'foo',
              'SENTRY_SECRET_KEY': 'bar',
          })
  
+ 
+ class SetupLoggingTest(TestCase):
+     def test_basic_not_configured(self):
+         with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
+             logger = getLogger()
+             logger.handlers = []
+             handler = mock.Mock()
+             result = setup_logging(handler)
+             self.assertTrue(result)
+ 
+     def test_basic_already_configured(self):
+         with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
+             handler = mock.Mock()
+             logger = getLogger()
+             logger.handlers = [handler]
+             result = setup_logging(handler)
+             self.assertFalse(result)
+ 
Add basic coverage for the setup_logging method
## Code Before:
from raven.conf import load
from unittest2 import TestCase


class LoadTest(TestCase):
    def test_basic(self):
        dsn = 'https://foo:bar@sentry.local/1'
        res = {}
        load(dsn, res)
        self.assertEquals(res, {
            'SENTRY_PROJECT': '1',
            'SENTRY_SERVERS': ['https://sentry.local/api/store/'],
            'SENTRY_PUBLIC_KEY': 'foo',
            'SENTRY_SECRET_KEY': 'bar',
        })

    def test_path(self):
        dsn = 'https://foo:bar@sentry.local/app/1'
        res = {}
        load(dsn, res)
        self.assertEquals(res, {
            'SENTRY_PROJECT': '1',
            'SENTRY_SERVERS': ['https://sentry.local/app/api/store/'],
            'SENTRY_PUBLIC_KEY': 'foo',
            'SENTRY_SECRET_KEY': 'bar',
        })

## Instruction:
Add basic coverage for the setup_logging method
## Code After:
import logging
import mock
from raven.conf import load, setup_logging
from unittest2 import TestCase


class LoadTest(TestCase):
    def test_basic(self):
        dsn = 'https://foo:bar@sentry.local/1'
        res = {}
        load(dsn, res)
        self.assertEquals(res, {
            'SENTRY_PROJECT': '1',
            'SENTRY_SERVERS': ['https://sentry.local/api/store/'],
            'SENTRY_PUBLIC_KEY': 'foo',
            'SENTRY_SECRET_KEY': 'bar',
        })

    def test_path(self):
        dsn = 'https://foo:bar@sentry.local/app/1'
        res = {}
        load(dsn, res)
        self.assertEquals(res, {
            'SENTRY_PROJECT': '1',
            'SENTRY_SERVERS': ['https://sentry.local/app/api/store/'],
            'SENTRY_PUBLIC_KEY': 'foo',
            'SENTRY_SECRET_KEY': 'bar',
        })


class SetupLoggingTest(TestCase):
    def test_basic_not_configured(self):
        with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
            logger = getLogger()
            logger.handlers = []
            handler = mock.Mock()
            result = setup_logging(handler)
            self.assertTrue(result)

    def test_basic_already_configured(self):
        with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
            handler = mock.Mock()
            logger = getLogger()
            logger.handlers = [handler]
            result = setup_logging(handler)
            self.assertFalse(result)
