예제 #1
0
    def test_get_story_stats_raises_value_error_if_type_param_not_valid(self):

        sg = StatGrabberBase('foo', 'bar', self.valid_start, self.valid_stop)

        with self.assertRaises(ValueError):
            sg.get_story_stats("foobar", 'invalid')
            sg.get_story_stats("foobar", 123)
            sg.get_story_stats("foobar", True)
            sg.get_story_stats("foobar", 'views_read')
예제 #2
0
    def test_get_article_ids_stashes_articles_list_to_attr(self):

        sg = StatGrabberBase('foo', 'bar', self.valid_start, self.valid_stop)
        json_input = [{
            "postId": "a1",
            "slug": "test-story"
        }, {
            "postId": "a2",
            "slug": "another-test"
        }, {
            "postId": "a3",
            "slug": "last-one"
        }]
        articles = sg.get_article_ids(json_input)
        expected = ["a1", "a2", "a3"]

        self.assertEqual(articles, expected)
예제 #3
0
    def test_init_session_attr_has_headers_content_type_and_accept_values_json(
            self):

        sg = StatGrabberBase('sid', 'uid', self.valid_start, self.valid_stop)

        expected = 'application/json'
        self.assertIn(expected, sg.session.headers['content-type'])
        self.assertIn(expected, sg.session.headers['accept'])
예제 #4
0
    def test_init_session_attr_has_cookies_sid_and_uid(self):

        sg = StatGrabberBase('foo', 'bar', self.valid_start, self.valid_stop)

        self.assertEqual('foo', sg.session.cookies.get('sid'))
        self.assertEqual('bar', sg.session.cookies.get('uid'))
예제 #5
0
    def test_init_session_attr_has_headers_content_type_and_accept(self):

        sg = StatGrabberBase('sid', 'uid', self.valid_start, self.valid_stop)

        self.assertIn('content-type', sg.session.headers.keys())
        self.assertIn('accept', sg.session.headers.keys())
예제 #6
0
    def test_init_session_attr_is_request_Sessions_object(self):

        sg = StatGrabberBase('sid', 'uid', self.valid_start, self.valid_stop)
        self.assertIsInstance(sg.session, requests.Session)
예제 #7
0
    def test_init_cookies_attr_contains_sid_and_uid_values(self):

        sg = StatGrabberBase('foo', 'bar', self.valid_start, self.valid_stop)
        self.assertEqual(sg.cookies.get('sid'), 'foo')
        self.assertEqual(sg.cookies.get('uid'), 'bar')
예제 #8
0
    def test_init_cookies_attr_contains_sid_and_uid_keys(self):

        sg = StatGrabberBase('sid', 'uid', self.valid_start, self.valid_stop)
        self.assertIn('sid', sg.cookies.keys())
        self.assertIn('uid', sg.cookies.keys())