Exemplo n.º 1
0
 def test_parse_command_line(self):
     identifier = self._identifier()
     cmd_args = ["--cutoff-time", "2016-05-01", "--identifier-type", 
                 identifier.type, identifier.identifier]
     parsed = RunCoverageProviderScript.parse_command_line(
         self._db, cmd_args, MockStdin()
     )
     eq_(datetime.datetime(2016, 5, 1), parsed.cutoff_time)
     eq_([identifier], parsed.identifiers)
     eq_(identifier.type, parsed.identifier_type)
Exemplo n.º 2
0
 def test_parse_command_line_no_identifiers(self):
     cmd_args = [
         "--identifier-type", Identifier.OVERDRIVE_ID,
         "--identifier-data-source", DataSource.STANDARD_EBOOKS
     ]
     parsed = IdentifierInputScript.parse_command_line(
         self._db, cmd_args, MockStdin()
     )
     eq_([], parsed.identifiers)
     eq_(Identifier.OVERDRIVE_ID, parsed.identifier_type)
     eq_(DataSource.STANDARD_EBOOKS, parsed.identifier_data_source)
Exemplo n.º 3
0
 def test_parse_command_line(self):
     i1 = self._identifier()
     i2 = self._identifier()
     # We pass in one identifier on the command line...
     cmd_args = ["--identifier-type", i1.type, i1.identifier]
     # ...and another one into standard input.
     stdin = MockStdin(i2.identifier)
     parsed = IdentifierInputScript.parse_command_line(
         self._db, cmd_args, stdin)
     eq_([i1, i2], parsed.identifiers)
     eq_(i1.type, parsed.identifier_type)
Exemplo n.º 4
0
 def test_parse_command_line(self):
     p1 = self._patron()
     p2 = self._patron()
     p1.authorization_identifier = self._str
     p2.authorization_identifier = self._str
     # We pass in one patron identifier on the command line...
     cmd_args = [p1.authorization_identifier]
     # ...and another one into standard input.
     stdin = MockStdin(p2.authorization_identifier)
     parsed = PatronInputScript.parse_command_line(
         self._db, cmd_args, stdin
     )
     eq_([p1, p2], parsed.patrons)
Exemplo n.º 5
0
 def test_do_run(self):
     """Test that PatronInputScript.do_run() calls process_patron()
     for every patron designated by the command-line arguments.
     """
     class MockPatronInputScript(PatronInputScript):
         def process_patron(self, patron):
             patron.processed = True
     p1 = self._patron()
     p2 = self._patron()
     p3 = self._patron()
     p3.processed = False
     p1.authorization_identifier = self._str
     p2.authorization_identifier = self._str
     cmd_args = [p1.authorization_identifier]
     stdin = MockStdin(p2.authorization_identifier)
     script = MockPatronInputScript(self._db)
     script.do_run(cmd_args=cmd_args, stdin=stdin)
     eq_(True, p1.processed)
     eq_(True, p2.processed)
     eq_(False, p3.processed)
Exemplo n.º 6
0
    def test_process_contribution_local(self):
        stdin = MockStdin()
        cmd_args = []

        edition_alice, pool_alice = self._edition(
            data_source_name=DataSource.GUTENBERG,
            identifier_type=Identifier.GUTENBERG_ID,
            identifier_id="1",
            with_open_access_download=True,
            title="Alice Writes Books")

        alice, new = self._contributor(sort_name="Alice Alrighty")
        alice._sort_name = "Alice Alrighty"
        alice.display_name="Alice Alrighty"

        edition_alice.add_contributor(
            alice, [Contributor.PRIMARY_AUTHOR_ROLE]
        )
        edition_alice.sort_author="Alice Rocks"

        # everything is set up as we expect
        eq_("Alice Alrighty", alice.sort_name)
        eq_("Alice Alrighty", alice.display_name)
        eq_("Alice Rocks", edition_alice.sort_author)

        edition_bob, pool_bob = self._edition(
            data_source_name=DataSource.GUTENBERG,
            identifier_type=Identifier.GUTENBERG_ID,
            identifier_id="2",
            with_open_access_download=True,
            title="Bob Writes Books")

        bob, new = self._contributor(sort_name="Bob")
        bob.display_name="Bob Bitshifter"

        edition_bob.add_contributor(
            bob, [Contributor.PRIMARY_AUTHOR_ROLE]
        )
        edition_bob.sort_author="Bob Rocks"

        eq_("Bob", bob.sort_name)
        eq_("Bob Bitshifter", bob.display_name)
        eq_("Bob Rocks", edition_bob.sort_author)

        contributor_fixer = CheckContributorNamesInDB(self._db, cmd_args)
        contributor_fixer.run()

        # Alice got fixed up.
        eq_("Alrighty, Alice", alice.sort_name)
        eq_("Alice Alrighty", alice.display_name)
        eq_("Alrighty, Alice", edition_alice.sort_author)

        # Bob's repairs were too extensive to make.
        eq_("Bob", bob.sort_name)
        eq_("Bob Bitshifter", bob.display_name)
        eq_("Bob Rocks", edition_bob.sort_author)

        # and we lodged a proper complaint
        q = self._db.query(Complaint).filter(Complaint.source==CheckContributorNamesInDB.COMPLAINT_SOURCE)
        q = q.filter(Complaint.type==CheckContributorNamesInDB.COMPLAINT_TYPE).filter(Complaint.license_pool==pool_bob)
        complaints = q.all()
        eq_(1, len(complaints))
        eq_(None, complaints[0].resolved)
Exemplo n.º 7
0
 def test_parse_command_line_no_identifiers(self):
     parsed = PatronInputScript.parse_command_line(
         self._db, [], MockStdin()
     )
     eq_([], parsed.patrons)
Exemplo n.º 8
0
 def test_parse_command_line_no_identifiers(self):
     cmd_args = ["--identifier-type", Identifier.OVERDRIVE_ID]
     parsed = IdentifierInputScript.parse_command_line(
         self._db, cmd_args, MockStdin())
     eq_([], parsed.identifiers)
     eq_(Identifier.OVERDRIVE_ID, parsed.identifier_type)