class TestUnlockMultipleImage(unittest.TestCase):
    def setUp(self):
        self._driver = ImageMonkeyChromeWebDriver()
        self._client = ImageMonkeyWebClient(self._driver)

    @classmethod
    def setUpClass(cls):
        helper.initialize_with_moderator()

    def tearDown(self):
        self._driver.quit()

    def test_unlock_image_should_succeed(self):
        path = os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                               "apples")
        ctr = 0
        for img in os.listdir(path):
            p = path + os.path.sep + img
            print("Donate image %s" % (p, ))
            self._client.donate(p, True)
            ctr += 1

            if ctr == 2:
                break

        self._client.login("moderator", "moderator", True)
        self._client.unlock_multiple_images()
class TestDonateImage(unittest.TestCase):
    def setUp(self):
        helper.initialize_with_moderator()
        self._driver = ImageMonkeyChromeWebDriver()
        self._client = ImageMonkeyWebClient(self._driver)

    def test_donate_image_should_succeed(self):
        self._client.donate(
            os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                            "apples" + os.path.sep + "apple2.jpeg"), True)

    def test_donate_image_ref_image_collection_should_succeed(self):
        self._client.login("moderator", "moderator", True)
        self._client.create_image_collection("mycollection")
        self._client.donate(
            os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                            "apples" + os.path.sep + "apple2.jpeg"),
            True,
            image_collection="mycollection")

    def test_donate_image_with_labels_should_succeed(self):
        self._client.donate(
            os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                            "apples" + os.path.sep + "apple2.jpeg"),
            True,
            labels=["apple"])

    def test_donate_image_should_fail(self):
        try:
            self._client.donate(
                os.path.abspath(".." + os.path.sep + "files" + os.path.sep +
                                "simple-textfile.txt"), False)
        except Exception as e:
            if "the server responded with a status of 422" not in str(e):
                raise e
Esempio n. 3
0
class TestUnlockImage(unittest.TestCase):
    def setUp(self):
        self._driver = ImageMonkeyChromeWebDriver()
        self._client = ImageMonkeyWebClient(self._driver)

    @classmethod
    def setUpClass(cls):
        helper.initialize_with_moderator()

    def tearDown(self):
        self._driver.quit()

    def test_unlock_image_should_succeed(self):
        self._client.donate(
            os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                            "apples" + os.path.sep + "apple2.jpeg"), True)
        self._client.login("moderator", "moderator", True)
        self._client.unlock_image()
class TestDonateImage(unittest.TestCase):
	def setUp(self):
		self._driver = ImageMonkeyChromeWebDriver()
		self._client = ImageMonkeyWebClient(self._driver)

	@classmethod
	def setUpClass(cls):
		helper.clear_database()

	def test_donate_image_should_succeed(self):
		self._client.donate(os.path.abspath(".." + os.path.sep + "images" + os.path.sep + "apples" + os.path.sep + "apple2.jpeg"), "apple", True)

	def test_donate_image_should_fail(self):
		try:
			self._client.donate(os.path.abspath(".." + os.path.sep + "files" + os.path.sep + "simple-textfile.txt"), "apple", False)
		except Exception as e:
			if "the server responded with a status of 422" not in str(e):
				raise e
class TestLabelImage(unittest.TestCase):
    def setUp(self):
        self._driver = ImageMonkeyChromeWebDriver()
        self._client = ImageMonkeyWebClient(self._driver)

    @classmethod
    def setUpClass(cls):
        helper.initialize_with_moderator()

    def tearDown(self):
        self._driver.quit()

    def test_label_image_should_succeed(self):
        self._client.donate(
            os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                            "apples" + os.path.sep + "apple2.jpeg"), True)
        self._client.login("moderator", "moderator", True)
        self._client.unlock_image()
        self._client.label_image(["floor", "wall"])
        image_labels = self._client.image_labels()
        self.assertListEqual(sorted(image_labels), sorted(["wall", "floor"]))
class TestAllPages(unittest.TestCase):
    def setUp(self):
        helper.initialize_with_moderator()
        self._driver = ImageMonkeyChromeWebDriver()
        self._client = ImageMonkeyWebClient(self._driver)

    def test_open_all_pages_once(self):
        self._client.donate(
            os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                            "apples" + os.path.sep + "apple2.jpeg"), True)
        self._client.login("moderator", "moderator", True)
        self._client.unlock_image()
        self._client.label_image(["floor", "wall"])

        endpoints = [
            "donate", "explore", "label?mode=default", "label?mode=browse",
            "label?type=image&mode=default", "label?type=image&mode=browse",
            "annotate?mode=default", "annotate?mode=browse",
            "annotate?mode=default&view=unified",
            "annotate?mode=browse&view=unified", "verify?mode=default",
            "verify?mode=browse", "verify_annotation", "refine?mode=browse",
            "statistics", "libraries", "models", "apps", "blog", "playground",
            "privacy"
        ]  #graph

        #check endpoints twice; once logged in and once logged out
        for i in range(2):
            if i == 1:
                self._client.logout()
                print("\n\nRun again logged out\n\n")
            for endpoint in endpoints:
                print("Testing endpoint %s" % endpoint, flush=True)

                try:
                    self._client.navigate_to(endpoint)
                except Exception as e:
                    # no auto annotations available, so the error is normal
                    if "annotate?add_auto_annotations=true - Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)":
                        continue
                    raise e
class TestAnnotateImage(unittest.TestCase):
    def setUp(self):
        self._driver = ImageMonkeyChromeWebDriver()
        self._client = ImageMonkeyWebClient(self._driver)

    @classmethod
    def setUpClass(cls):
        helper.initialize_with_moderator()

    def tearDown(self):
        self._driver.quit()

    def test_annotate_image_should_succeed(self):
        path = os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                               "apples" + os.path.sep + "apple1.jpeg")
        self._client.donate(path, True)

        self._client.login("moderator", "moderator", True)
        self._client.unlock_multiple_images()

        self._client.label_image(["apple"])

        self._client.browse_annotate()
Esempio n. 8
0
class TestUnifiedMode(unittest.TestCase):
    def setUp(self):
        helper.initialize_with_moderator()
        self._driver = ImageMonkeyChromeWebDriver()
        self._client = ImageMonkeyWebClient(self._driver)

    def tearDown(self):
        self._driver.quit()

    def _prepare_for_test(self):
        path = os.path.abspath(".." + os.path.sep + "images" + os.path.sep +
                               "apples" + os.path.sep + "apple1.jpeg")
        self._client.donate(path, True)

        self._client.login("moderator", "moderator", True)
        self._client.unlock_multiple_images()

    def test_query_images_should_succeed(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)

    def test_annotate_should_succeed(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.annotate(RectAnnotationAction(-10, -15))

    def test_query_annotation_rework_should_succeed(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.annotate(RectAnnotationAction(-10, -15))

        unified_mode_view.query("apple", 1, mode="rework")

    def test_annotate_rework_should_succeed(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.annotate(RectAnnotationAction(-10, -15))

        unified_mode_view.query("apple", 1, mode="rework")
        unified_mode_view.select_image(0)
        unified_mode_view.annotate(RectAnnotationAction(-15, -15))

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1, mode="rework")
        unified_mode_view.select_image(0)
        unified_mode_view.check_revisions(2)

    def test_query_images_non_productive_labels_should_succeed(self):
        self._prepare_for_test()

        self._client.label_image(["notexisting"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("notexisting", 1)

    def test_annotate_non_productive_label_should_succeed(self):
        self._prepare_for_test()

        self._client.label_image(["notexisting"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("notexisting", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.annotate(RectAnnotationAction(-10, -15))

    def test_query_annotation_rework_non_productive_labels_should_succeed(
            self):
        self._prepare_for_test()

        self._client.label_image(["notexisting"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("notexisting", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.annotate(RectAnnotationAction(-10, -15))

        unified_mode_view.query("notexisting", 1, mode="rework")

    def test_annotate_rework_non_productive_label_should_succeed(self):
        self._prepare_for_test()

        self._client.label_image(["notexisting"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("notexisting", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.annotate(RectAnnotationAction(-10, -15))

        unified_mode_view.query("notexisting", 1, mode="rework")
        unified_mode_view.select_image(0)
        unified_mode_view.annotate(RectAnnotationAction(-15, -15))

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("notexisting", 1, mode="rework")
        unified_mode_view.select_image(0)
        unified_mode_view.check_revisions(2)

    def test_add_label_in_unified_mode_should_succeed(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.label("test")

    def test_add_label_in_unified_mode_should_fail_due_to_not_authenticated(
            self):
        self._prepare_for_test()

        self._client.label_image(["apple"])
        self._client.logout()

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.label("test", False)

    def test_add_already_existing_productive_label_in_unified_mode(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.label("apple", False)

    def test_add_already_existing_productive_label_in_unified_mode(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.label("test")

        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.label("test", False)

    def test_blacklist_in_unified_mode_fails_due_to_not_authenticated(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])
        self._client.logout()

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.blacklist_annotation(False)

    def test_blacklist_in_unified_mode_succeeds(self):
        self._prepare_for_test()

        self._client.label_image(["apple"])

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 1)
        unified_mode_view.select_image(0)
        unified_mode_view.blacklist_annotation(True)

        unified_mode_view = self._client.unified_mode()
        unified_mode_view.query("apple", 0)