def test_copy_notes_from_d_to_g(self, mock_sleep, mock_danbooru_auth, mock_gelbooru_auth): mock_danbooru_auth.return_value = DANBOORU_TEST_AUTH mock_gelbooru_auth.return_value = GELBOORU_TEST_AUTH # If a new integration test needs to be recorded, unmock sleep and auth calls danbooru_post = note_copy.DanbooruPost(284392) gelbooru_post = note_copy.GelbooruPost(302738, mode='w') gelbooru_post.copy_notes_from_post(danbooru_post) self.assertEqual(set(danbooru_post.notes), set(gelbooru_post.notes))
def test_source_and_destination(self, mock_copy_notes, mock_instantiate_post): posts = [ note_copy.DanbooruPost(1437880), note_copy.GelbooruPost(1904252), ] mock_instantiate_post.side_effect = posts sys.argv = ['', '--source', 'd1437880', '--destination', 'g1904252'] main() c = mock.call(posts[0]) mock_copy_notes.assert_has_calls([c])
def test_file(self, mock_copy_notes, mock_instantiate_post, mock_open, mock_time): # TODO: Get more interesting post numbers for the second set posts = [ note_copy.DanbooruPost(1437880), note_copy.GelbooruPost(1904252), note_copy.DanbooruPost(12345), note_copy.GelbooruPost(12345), ] mock_instantiate_post.side_effect = posts ids = 'd1437880\t g1904252\n\n\nd12345 g12345 \n' mock_open.return_value = StringIO(ids) sys.argv = ['', '--file', '/tmp/mock_file'] main() copy_notes_calls = [ mock.call(p) for p in posts if type(p) is note_copy.DanbooruPost ] cooldown = note_copy.GelbooruPost.cooldown sleep_calls = [mock.call(cooldown), mock.call(cooldown)] mock_copy_notes.assert_has_calls(copy_notes_calls) mock_time.sleep.assert_has_calls(sleep_calls)
def test_auth_stores_credentials(self, mock_home, mock_yes_no, mock_input, mock_getpass): tmp_dir = mkdtemp() mock_home.return_value = Path(tmp_dir) mock_yes_no.return_value = True mock_input.side_effect = [ 'fake_user_for_note_copy_tests', 'FAKE_API_KEY_FOR_NOTE_COPY_TESTS', 'fake_user_for_note_copy_tests', 'FAKE_API_KEY_FOR_NOTE_COPY_TESTS', ] mock_getpass.return_value = 'fake_password' session = mock.Mock() jar = requests.cookies.RequestsCookieJar() jar.set('user_id', '1648') jar.set('pass_hash', '80c1ed9c72b4d7048851a6a6d629ba4abe5e8c76') session.cookies = jar def mock_login(username, auth_string): return session danbooru_post = note_copy.DanbooruPost(1234) gelbooru_post = note_copy.GelbooruPost(1234) gelbooru_post._login = mock_login danbooru_auth = danbooru_post.auth gelbooru_auth = gelbooru_post.auth self.assertEqual(danbooru_auth, DANBOORU_TEST_AUTH) self.assertEqual(gelbooru_auth, GELBOORU_TEST_AUTH) danbooru_auth_file = Path( tmp_dir) / '.note_copy' / 'danbooru_auth.json' gelbooru_auth_file = Path( tmp_dir) / '.note_copy' / 'gelbooru_auth.json' with danbooru_auth_file.open('r') as f: self.assertEqual(json.load(f), DANBOORU_TEST_AUTH) with gelbooru_auth_file.open('r') as f: self.assertEqual(json.load(f), GELBOORU_TEST_AUTH) shutil.rmtree(tmp_dir)
def test_equality_does_not_match(self): danbooru_post = note_copy.DanbooruPost(1234) gelbooru_post = note_copy.GelbooruPost(1234) self.assertNotEqual(danbooru_post, gelbooru_post)
def test_equality_does_match(self): danbooru_post_1 = note_copy.DanbooruPost(1234) # Simulate note being fetched danbooru_post_1.notes = [note_copy.Note(1, 2, 3, 4, 'test')] danbooru_post_2 = note_copy.DanbooruPost('1234') self.assertEqual(danbooru_post_1, danbooru_post_2)
def test_domain(self): expected_result = note_copy.DanbooruPost(1437880) result = note_copy.instantiate_post(self.valid_classes, 'danbooru.donmai.us1437880') self.assertEqual(expected_result, result)
def test_short_code(self): expected_result = note_copy.DanbooruPost(1437880) result = note_copy.instantiate_post(self.valid_classes, 'd1437880') self.assertEqual(expected_result, result)
def setUp(self): self.post = note_copy.DanbooruPost(1437880)
def test_str(self): danbooru_post = note_copy.DanbooruPost(1234) gelbooru_post = note_copy.GelbooruPost(1234) self.assertEqual(str(danbooru_post), 'Danbooru Post - 1234') self.assertEqual(str(gelbooru_post), 'Gelbooru Post - 1234')