from nose.tools import *  # PEP8 asserts
from mock import patch
from tests.base import OsfTestCase

from website.search import share_search


class TestShareSearch(OsfTestCase):

    @patch.object(share_search.share_es, 'search')
    def test_share_search(self, mock_search):
        mock_search.return_value = {
            'hits': {
                'hits': {},
                'total': 0
            }
        }
        self.app.get('/api/v1/share/', params={
            'q': '*',
            'from': '1',
            'size:': '20',
            'sort': 'date'
        })
        assert_is(mock_search.called, True)

    @patch.object(share_search.share_es, 'count')
    def test_share_count(self, mock_count):
        mock_count.return_value = {'count': 0}
        self.app.get('/api/v1/share/', params={
            'q': '*',
            'from': '1',
            'size:': '20',
            'sort': 'date',
            'count': True
        })
        assert_is(mock_count.called, True)


    @patch.object(share_search.share_es, 'search')
    def test_share_providers(self, mock_search):
        mock_search.return_value = {
            'hits': {
                'hits': {},
                'total': 0
            }
        }
        self.app.get('/api/v1/share/providers/')
        assert_is(mock_search.called, True)

    @patch.object(share_search.share_es, 'search')
    def test_share_stats(self, mock_search):
        mock_search.return_value = {
            'hits': {
                'hits': {},
                'total': 0
            },
            'aggregations': {
                'date_chunks': {
                    'buckets': [{
                        'articles_over_time': {
                            'buckets': []
                        },
                        'key': 'test',
                        'doc_count': 0
                    }]
                },
                'sources': {
                    'buckets': [{
                        'key': 'test',
                        'doc_count': 0
                    }]
                },
                'earlier_documents': {
                    'sources': {
                        'buckets': [{
                            'key': 'test',
                            'doc_count': 0
                        }]
                    }
                }
            }
        }
        self.app.get('/api/v1/share/stats/')
        assert_is(mock_search.called, True)

@@ -91,16 +91,27 @@
 TestCase
+%0Aimport xml
 %0A%0Afrom w
@@ -995,17 +995,16 @@
  True)%0A%0A
-%0A
     @pat
@@ -2397,24 +2397,24 @@
 re/stats/')%0A
-
         asse
@@ -2425,28 +2425,755 @@
 s(mock_search.called, True)%0A
+%0A%0Aclass TestShareAtom(OsfTestCase):%0A%0A    def test_atom_returns_200(self):%0A        response = self.app.get('/share/atom/')%0A        assert_equal(response.status, '200 OK')%0A%0A    def test_atom_renders_xml(self):%0A        response = self.app.get('/share/atom/')%0A        xml_content = response.xml%0A        assert isinstance(xml_content, xml.etree.ElementTree.Element)%0A%0A    def test_atom_head_tag(self):%0A        response = self.app.get('/share/atom/')%0A        xml_content = response.xml%0A        assert_equal(xml_content.tag, '%7Bhttp://www.w3.org/2005/Atom%7Dfeed')%0A%0A    # def test_page_one_rel_next_link(self):%0A    #     response = self.app.get('/share/atom/')%0A    #     xml_content = response.xml%0A    #     import ipdb; ipdb.set_trace()%0A

Add 3 tests for atom feed