Example #1
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)
Example #2
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'])
Example #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)
Example #4
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(),
        )