def test_missing_pdf(self, pdf_dir, year, date, link):
        """Tests that function returns the list of pdfs that are missing
        from the directory"""
        # input
        missing_links = {year: {date: link}}

        # setup - create all but one pdf
        keep_links = deepcopy(MEETING_LINKS)
        del keep_links[year][date]  # removes one pdf from dict
        del_dir_contents(pdf_dir)
        pdf_files = self._create_pdf_files(pdf_dir, keep_links)
        for file in pdf_files:
            assert file.exists()
        missing_name = date + ".pdf"
        missing_file = pdf_dir / missing_name
        assert missing_file.exists() is False

        # execution
        print("INPUT")
        pprint(MEETING_LINKS)
        missing, extra = check_missing_pdfs(MEETING_LINKS, dir=pdf_dir)
        print("OUTPUT")
        pprint(missing)
        print("EXPECTED")
        pprint(missing_links)

        # validation
        assert missing == missing_links
        assert not extra
    def test_missing_pdf_dir(self, pdf_dir):
        """Tests that pdf the directory is created and the pdf is downloaded
        when the directory for donwloads is missing"""
        # input
        year = "2021"
        date = "2021_01_20"
        url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"

        # setup
        del_dir_contents(pdf_dir)
        pdf_dir.rmdir()
        assert pdf_dir.exists() is False
        pdf_name = date + ".pdf"
        pdf_file = pdf_dir / year / pdf_name

        # execution
        passed, message, file = download_pdf(year, date, url, dir=pdf_dir)
        print("ERROR")
        print(message)

        # validation
        assert passed
        assert file is not None
        assert pdf_file.exists()
        assert pdf_name == "2021_01_20.pdf"
        assert file == pdf_file
    def test_valid_url(self, pdf_dir):
        """Tests the download of a pdf from a meeting link specified
        in the test data
        """
        # input
        year = "2021"
        date = "2021_01_20"
        url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"

        # setup
        del_dir_contents(pdf_dir)
        assert is_empty(pdf_dir)
        pdf_name = date + ".pdf"
        pdf_file = pdf_dir / year / pdf_name

        # execution
        passed, message, file = download_pdf(year, date, url, dir=pdf_dir)
        print("ERROR")
        print(message)

        # validation
        assert passed
        assert file is not None
        assert pdf_name == "2021_01_20.pdf"
        assert pdf_file.exists()
        assert file == pdf_file
    def test_non_pdf_url(self, pdf_dir):
        """Tests that the function returns False when given a url that doesn't
        point to a pdf
        """
        # input
        year = "2021"
        date = "2021_01_20"
        url = "https://www.google.com/"

        # setup
        del_dir_contents(pdf_dir)
        assert is_empty(pdf_dir)
        pdf_name = date + ".pdf"
        pdf_file = pdf_dir / year / pdf_name

        # execution
        passed, message, file = download_pdf(year, date, url, dir=pdf_dir)

        # validation
        assert not passed
        assert file is None
        assert pdf_file.exists() is False
        assert message == f"The content stored at {url} is not a pdf"
    def test_invalid_url(self, pdf_dir, url):
        """Tests that the function returns False when given a url that raises
        an error when being requested
        """
        # input
        year = "2021"
        date = "2021-01-20"

        # setup
        del_dir_contents(pdf_dir)
        assert is_empty(pdf_dir)
        pdf_name = date + ".pdf"
        pdf_file = pdf_dir / year / pdf_name

        # execution
        passed, message, file = download_pdf(year, date, url, dir=pdf_dir)
        print("ERROR")
        print(message)

        # validation
        assert not passed
        assert file is None
        assert pdf_file.exists() is False
        assert message[:28] == "An error occurred requesting"