예제 #1
0
    def test_generate_directives_from_xml_sitemap(self):
        from smoketest.directives import (
            CheckDirective,
            FileParser,
        )

        sitemap_file = self._create_file('.xml')
        sitemap_file.write(
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' +
            '<url><loc>https://www.example.com</loc></url></urlset>')
        sitemap_file.close()

        options = Mock()
        options.cachebust = False
        options.level = 'live'
        options.port = None
        options.scheme = None

        file_parser = FileParser(sitemap_file.name, options)
        directives = list(file_parser.generate_directives())
        directive = directives[0]

        self.assertEqual(len(directives), 1)

        self.assertTrue(isinstance(directive, CheckDirective))
        self.assertEqual(directive.follow_redirects, False)
        self.assertEqual(directive.urls, ['https://www.example.com'])
예제 #2
0
 def test_include_directive(self):
     from smoketest.directives import FileParser
     filename = 'static.txt'
     line = '#include %s' % filename
     options = Mock()
     directive = FileParser(filename, options)._get_directive_from_dumb_list_line(line)
     self.assertTrue(directive.filename.endswith(filename))
예제 #3
0
    def test_generate_directives_only_levels(self):
        from smoketest.directives import FileParser

        json_file = self._create_file('.json')
        json_file.write(json.dumps([
            {
                'directive': 'check',
                'url': 'www.mock.com'
            },
            {
                'directive': 'check',
                'url': 'www.mock.com',
                'only_levels': ['live']
            },
            {
                'directive': 'check',
                'url': 'www.mock.com',
                'only_levels': ['stag', 'live']
            },
        ]))
        json_file.close()

        # uat1 level should only pick up the first directive
        options = Mock()
        options.scheme = None
        options.level = 'uat1'
        file_parser = FileParser(json_file.name, options)
        directives = list(file_parser.generate_directives())
        self.assertEquals(len(directives), 1)

        # stag level should pick up the first and third directives
        FileParser._visited_files = set()
        options = Mock()
        options.scheme = None
        options.level = 'stag'
        file_parser = FileParser(json_file.name, options)
        directives = list(file_parser.generate_directives())
        self.assertEquals(len(directives), 2)

        # live level should pick up all three directives
        FileParser._visited_files = set()
        options = Mock()
        options.scheme = None
        options.level = 'live'
        file_parser = FileParser(json_file.name, options)
        directives = list(file_parser.generate_directives())
        self.assertEquals(len(directives), 3)
예제 #4
0
    def test_generate_directives_only_levels_works_with_include(self):
        from smoketest.directives import FileParser

        yaml_file = self._create_file('.yaml')
        yaml_file.write('- https://www.usnews.com')
        yaml_file.close()

        json_file = self._create_file('.json')
        json_file.write(json.dumps([
            {
                'directive': 'include',
                'filename': yaml_file.name,
                'only_levels': ['uat1']
            },
        ]))
        json_file.close()

        # live level should not pick up the directive
        options = Mock()
        options.scheme = None
        options.level = 'live'
        file_parser = FileParser(json_file.name, options)
        directives = list(file_parser.generate_directives())
        self.assertEquals(len(directives), 0)

        # uat1 level should pick up the directive
        FileParser._visited_files = set()
        options = Mock()
        options.scheme = None
        options.level = 'uat1'
        file_parser = FileParser(json_file.name, options)
        directives = list(file_parser.generate_directives())
        self.assertEquals(len(directives), 1)
예제 #5
0
    def test_environment_specific_status_code_not_live(self):
        from smoketest.directives import FileParser
        url = 'http://premium.usnews.com/best-colleges/rankings/national-universities'
        line = '30X_live %s' % url
        options = Mock()
        options.scheme = None
        options.level = 'stag'
        directive = FileParser(None, options)._get_directive_from_dumb_list_line(line)

        # Expect one 200 status test on the directive
        self.assertEqual(len(directive.tests), 1)
        test = directive.tests[0]
        self.assertEqual(test.target_code, '200')
예제 #6
0
    def test_generate_directives_only_levels_is_not_a_list(self):
        from smoketest.directives import FileParser

        json_file = self._create_file('.json')
        json_file.write(json.dumps([
            {
                'directive': 'check',
                'url': 'example.com',
                'only_levels': 'string!'
            },
        ]))
        json_file.close()

        options = Mock()
        options.scheme = None
        options.level = 'uat1'
        fileparser = FileParser(json_file.name, options)
        self.assertRaises(
            Exception,
            next,
            fileparser.generate_directives(),
        )
예제 #7
0
    def test_redirect_with_target(self):
        from smoketest.directives import FileParser
        url = 'http://www.usnews.com/congress/platts-todd'
        redirect_to = 'http://www.usnews.com/topics/people/todd_russell_platts'
        line = '30X %s -> %s' % (url, redirect_to)
        options = Mock()
        options.scheme = None
        options.level = 'stag'
        options.port = None
        options.cachebust = False
        directive = FileParser(None, options)._get_directive_from_dumb_list_line(line)

        # Expect one redirect test to be on the directive. Redirect-to URL
        # should respect level.
        self.assertEqual(len(directive.tests), 1)
        test = directive.tests[0]
        self.assertEqual(test.target_code, '30X')
        self.assertEqual(
            test.target_location,
            redirect_to.replace('www.', 'www-stag.')
        )