Exemplo n.º 1
0
def test_search_for_screenpy(Perry: AnActor) -> None:
    """GitHub search finds the screenpy repository."""
    given(Perry).was_able_to(Open.their_browser_on(URL))
    when(Perry).attempts_to(SearchGitHub.for_text("perrygoy/screenpy"))
    then(Perry).should_see_that(
        (SearchResultsMessage(), DoesNot(ContainTheText("couldn’t"))),
        (SearchResultsMessage(), ReadsExactly("1 repository result")),
        (NumberOfSearchResults(), IsEqualTo(1)),
    )
Exemplo n.º 2
0
def test_search_for_nonexistent_repo(Perry: AnActor) -> None:
    """GitHub search fails to find a nonexistant repository."""
    nonexistant_repository = "perrygoy/i-never-made-this-repo"

    given(Perry).was_able_to(Open.their_browser_on(URL))
    when(Perry).attempts_to(SearchGitHub.for_text(nonexistant_repository))
    then(Perry).should_see_that(
        (SearchResultsMessage(), ContainsTheText("We couldn’t find any")),
        (SearchResultsMessage(), ContainsTheText(nonexistant_repository)),
        (NumberOfSearchResults(), IsEqualTo(0)),
    )
Exemplo n.º 3
0
def test_is_equal_to_unequal_value(Tester):
    """IsEqual complains if the values are not equal"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    return_value = [1, 2, 3]
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_find_all.return_value = return_value

    with pytest.raises(AssertionError):
        Tester.should_see_the(
            (Number.of(fake_target), IsEqualTo(len(return_value) + 3)))
def test_ask_for_number(Tester):
    """Number uses .to_find_all() and returns an int"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    return_value = [1, 2, 3]
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_find_all.return_value = return_value

    Tester.should_see_the((Number.of(fake_target), IsEqualTo(len(return_value))))

    mocked_btw.to_find_all.assert_called_once_with(fake_target)
Exemplo n.º 5
0
    def test_remove_element(self):
        """User is able to remove an element that was added."""
        Perry = self.actor

        given(Perry).was_able_to(
            Open.their_browser_on(URL),
            Click.on_the(ADD_BUTTON),
            Wait.for_the(ADDED_ELEMENTS),
        )
        when(Perry).attempts_to(Click.on_the(ADDED_ELEMENTS))
        then(Perry).should_see_the((Number.of(ADDED_ELEMENTS), IsEqualTo(0)))
Exemplo n.º 6
0
    def test_add_many_elements(self):
        """
        User is able to add many elements. This test chooses a random
        number of elements to add, just to show off how to do that, if you
        want to do something like that.
        """
        Perry = self.actor
        number_of_times = random.choice(range(2, 10))

        given(Perry).was_able_to(Open.their_browser_on(URL))
        when(Perry).attempts_to(*(Click.on_the(ADD_BUTTON)
                                  for each_time in range(number_of_times)))
        then(Perry).should_see_the(
            (Number.of(ADDED_ELEMENTS), IsEqualTo(number_of_times)))
Exemplo n.º 7
0
    def test_the_test(self):
        """IsEqual tests what it says on the tin"""
        ie = IsEqualTo(1)

        self.assertTrue(ie.matches(1))
        self.assertFalse(ie.matches(2))
Exemplo n.º 8
0
    def test_can_be_instantiated(self):
        """IsEqual can be instantiated"""
        ie = IsEqualTo(1)

        self.assertIsInstance(ie, IsEqualTo)
Exemplo n.º 9
0
    def test_the_test(self):
        """IsEqual tests what it says on the tin"""
        ie = IsEqualTo(1)

        assert ie.matches(1)
        assert not ie.matches(2)