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_post_info_property_write(self, mock_auth): mock_auth.return_value = GELBOORU_TEST_AUTH post = note_copy.GelbooruPost(1904252, mode='w') result = post.post_info # Testing the full result would be cumbersome, so spot check a few key attributes self.assertEqual( '7a80127b5b02efa74c37332351d88ebe309f57afee6deebf4745e9d44545fd05', result['csrf-token'], ) self.assertEqual('pbdnlog5di3ki2mr9b1odombh0', result['PHPSESSID'])
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_dimensions_write(self, mock_auth): mock_auth.return_value = GELBOORU_TEST_AUTH post = note_copy.GelbooruPost(1904252, mode='w') expected_result = (1192, 1064) result = post.dimensions self.assertEqual(expected_result, result)
def test_post_info_invalid_mode(self): post = note_copy.GelbooruPost(1904252, mode='rw') with self.assertRaises(ValueError): post.post_info
def setUp(self): self.post = note_copy.GelbooruPost(1904252)
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')