Пример #1
0
 def setUp(self):
     SimpleTestCase.setUp(self)
     """
     ready up all variables and test class
     """
     print '=' * 100
     print "<%s> currently run: %s" % (self.__class__.__name__, self._testMethodName)
     print '-' * 100 + '\n'
Пример #2
0
    def _teardown_database(self):
        SimpleTestCase._post_teardown(self)

        query = '''
        START n = node(*)
        OPTIONAL MATCH n-[r]-()
        DELETE n, r;
        '''

        self.graph_db.cypher.execute(query)
Пример #3
0
    def _pre_setup(self):
        """ (MongoTestMixin) -> (NoneType)
        create a new mongo connection.

        Note:- It explicitly uses Class name to call methods, since the calling overriden
        _setup_database and _teardown_database is not required behaviour, as it would
        not work with other Test Mixins like Redis or Neo4j, which have their own _setup_database
        and _teardown_database
        """
        SimpleTestCase._pre_setup(self)

        MongoTestMixin._setup_database(self)
Пример #4
0
def check_redirects(response, expected_url):
    test_case = SimpleTestCase()
    test_case.assertRedirects(response, expected_url=expected_url)
    return True
Пример #5
0
 def __init__(self, tester=None, *args, **kwargs):
     self.tester = tester if tester else SimpleTestCase()
Пример #6
0
def check_form_error(response, form_name, field, errors, msg_prefix=''):
    test_case = SimpleTestCase()
    test_case.assertFormError(response, form_name, field, errors, msg_prefix)
    return True
Пример #7
0
 def test_signout(self):
     response = self.client.get(reverse('signout'))
     SimpleTestCase().assertRedirects(response, reverse('signin'))
Пример #8
0
 def tearDown(self):
     """
     remove variables after test
     """
     SimpleTestCase.tearDown(self)
     print '\n' + '=' * 100 + '\n\n'
Пример #9
0
def check_in_html(needle, haystack):
    test_case = SimpleTestCase()
    test_case.assertInHTML(needle, haystack)
    return True
Пример #10
0
def helpers():
    return SimpleTestCase()
Пример #11
0
    def _pre_setup(self):
        SimpleTestCase._pre_setup(self)

        RedisTestMixin._setup_database(self)
Пример #12
0
 def tearDown(self):
     """
     remove variables after test
     """
     SimpleTestCase.tearDown(self)
     print '\n' + '=' * 100 + '\n\n'
Пример #13
0
    def _pre_setup(self):
        SimpleTestCase._pre_setup(self)

        Neo4jTestMixin._setup_database(self)
Пример #14
0
def assert_redirects() -> Callable:
    """Provide redirect assertion."""
    return SimpleTestCase().assertRedirects
Пример #15
0
def test_roster_list_redirect_if_not_logged_in(client):
    """Test roster list view redirects if not logged in."""
    response = client.get(reverse("roster_by_staff"))
    SimpleTestCase().assertRedirects(
        response, "/accounts/login/?next=/rosters/roster_by_staff/"
    )
Пример #16
0
def test_contains_partial():
    c = SimpleTestCase()
    needle = "<span></span>"
    html = "<form>%s</form>"
    c.assertTrue(contains_partial(html % needle, needle))

    needle = "<span></span><b></b>"
    c.assertRaises(NotImplementedError, contains_partial, html % needle,
                   needle)

    needle = "<span>a</span>"
    c.assertRaises(NotImplementedError, contains_partial, html % needle,
                   needle)

    needle = '<span id="e"></span>'
    html = '<form id="tt"><span id="f"></span>%s</form>'
    c.assertTrue(contains_partial(html % needle, needle))

    missing = "<script></script>"
    c.assertFalse(contains_partial(html % missing, needle))

    needle = '<span id="e"></span>'
    html = '<form id="tt"><span id="f"></span>%s</form>'
    missing = '<span id="g"></span>'
    c.assertFalse(contains_partial(html % missing, needle))

    needle = '<div id="r"><span>toto</span></div>'
    html = '<form><div id="r"></div></form>'
    c.assertRaises(NotImplementedError, contains_partial, html, needle)
    # as we do not look at the children, needle is equivalent to <div id="r"></div> which IS in html
    c.assertTrue(contains_partial(html, needle, ignore_needle_children=True))
Пример #17
0
def STC():
    return SimpleTestCase()
Пример #18
0
def check_template_used(response, template_name):
    test_case = SimpleTestCase()
    test_case.assertTemplateUsed(response, template_name=template_name)
    return True
Пример #19
0
def test_edit_animal_count(
    client,
    user_base,
    enclosure_factory,
    animal_factory,
    animal_A,
    enclosure_base,
    animal_count_A_BAR_datetime_factory,
):
    client.force_login(user_base)

    yesterday_time = timezone.localtime() - dt.timedelta(days=1)
    yesterday = yesterday_time.date()

    enc_not_permit = enclosure_factory("not_permit", None)

    anim_not_permit = animal_factory(
        name="kermitthefrog",
        identifier="green",
        sex="m",
        accession_number="abc123",
        enclosure=enc_not_permit,
    )

    # not permitted
    resp = client.get(("/edit_animal_count/"
                       f"{anim_not_permit.accession_number}/"
                       f"{yesterday.year}/{yesterday.month}/{yesterday.day}/"))
    assert resp.status_code == 302
    SimpleTestCase().assertRedirects(resp, "/")

    count = animal_count_A_BAR_datetime_factory(yesterday_time)

    # GET
    resp = client.get(("/edit_animal_count/"
                       f"{animal_A.accession_number}/"
                       f"{yesterday.year}/{yesterday.month}/{yesterday.day}/"))
    assert resp.status_code == 200
    assert resp.context["count"] == count
    assert resp.context["animal"] == animal_A
    assert resp.context["enclosure"] == enclosure_base
    assert resp.context["dateday"].year == yesterday.year
    assert resp.context["dateday"].month == yesterday.month
    assert resp.context["dateday"].day == yesterday.day
    # todo: form context

    # POST
    post_data = {
        "condition": "NA",
        "comment": "this is a test count",
        "animal": animal_A.id,
        "enclosure": enclosure_base.id,
    }
    resp = client.post(
        ("/edit_animal_count/"
         f"{animal_A.accession_number}/"
         f"{yesterday.year}/{yesterday.month}/{yesterday.day}/"),
        data=post_data,
        follow=True,
    )
    assert resp.status_code == 200
    assert resp.redirect_chain == [(f"/count/{enclosure_base.slug}/", 302)]

    latest_count = animal_A.conditions.latest("datetimecounted")
    assert latest_count.condition == "NA"
    assert latest_count.comment == "this is a test count"
    assert latest_count.enclosure == enclosure_base
Пример #20
0
def check_contains(response, text):
    test_case = SimpleTestCase()
    test_case.assertContains(response, text=text)
    return True
Пример #21
0
 def test_signin_not_authenticated(self):
     response = self.client.get('/signin/')
     SimpleTestCase().assertEqual(response.status_code, 200)
Пример #22
0
    def _post_teardown(self):
        SimpleTestCase._post_teardown(self)

        MongoTestMixin._teardown_database(self)
Пример #23
0
 def test_battle(self):
     response = self.client.get(reverse('backend:fight'), follow=True)
     SimpleTestCase().assertRedirects(response, expected_url='/login/?next=/battle/', status_code=302,
                                      target_status_code=200)
Пример #24
0
    def test_get_compatible_column_names(self):
        """
        tests getting column types compatible with paracoords library function
        """
        self.assertIsInstance(file_helper.get_compatible_column_types(self.dataframe), dict)

    def test_get_html_friendly_names(self):
        """
        tests removal of illegal characters in the column names (HTML escaping) function
        """
        self.assertIsInstance(file_helper.get_html_friendly_names(self.dataframe.columns), list)


class TestColumnNameFormatting(SimpleTestCase):
    def test_remove_illegal_characters(self):
        """
        tests function to remove illegal characters
        """
        self.assertEqual(file_helper.remove_illegal_characters("str^5"), 'str5')


if __name__ == '__main__':
    # suite1 = SimpleTestCase.TestLoader().loadTestsFromTestCase(TestFileUpload)
    # suite2 = SimpleTestCase.TestLoader().loadTestsFromTestCase(TestDataFrameOperations)
    # suite3 = SimpleTestCase.TestLoader().loadTestsFromTestCase(TestColumnNameFormatting)
    # alltests = SimpleTestCase.TestSuite([suite1, suite2,suite3])
    # SimpleTestCase.TextTestRunner(verbosity=2).run(alltests)
    SimpleTestCase.main()

Пример #25
0
def test_edit_group_count(
    client,
    user_base,
    group_B,
    group_factory,
    enclosure_base,
    enclosure_factory,
    group_B_count_datetime_factory,
):
    client.force_login(user_base)

    yesterday_time = timezone.localtime() - dt.timedelta(days=1)
    yesterday = yesterday_time.date()

    enc_not_permit = enclosure_factory("not_permit", None)
    group_not_permit = group_factory("abc123",
                                     5,
                                     4,
                                     3,
                                     12,
                                     enclosure=enc_not_permit)

    # not permitted
    resp = client.get(("/edit_group_count/"
                       f"{group_not_permit.accession_number}/"
                       f"{yesterday.year}/{yesterday.month}/{yesterday.day}/"))
    assert resp.status_code == 302
    SimpleTestCase().assertRedirects(resp, "/")

    count = group_B_count_datetime_factory(yesterday_time)

    # GET
    resp = client.get(("/edit_group_count/"
                       f"{group_B.accession_number}/"
                       f"{yesterday.year}/{yesterday.month}/{yesterday.day}/"))
    assert resp.status_code == 200
    assert resp.context["count"] == count
    assert resp.context["group"] == group_B
    assert resp.context["enclosure"] == enclosure_base
    assert resp.context["dateday"].year == yesterday.year
    assert resp.context["dateday"].month == yesterday.month
    assert resp.context["dateday"].day == yesterday.day
    # todo: form context

    # POST
    count_bar = randint(1, 400)
    count_seen = count_bar + randint(5, 25)
    count_total = count_bar + count_seen
    post_data = {
        "count_seen": count_seen,
        "enclosure": enclosure_base.id,
        "count_bar": count_bar,
        "comment": "this is a randomly generated count",
        "group": group_B.id,
        "count_total": count_total,
        "needs_attn": False,
    }
    resp = client.post(
        ("/edit_group_count/"
         f"{group_B.accession_number}/"
         f"{yesterday.year}/{yesterday.month}/{yesterday.day}/"),
        data=post_data,
        follow=True,
    )
    assert resp.status_code == 200
    assert resp.redirect_chain == [(f"/count/{enclosure_base.slug}/", 302)]

    latest_count = group_B.counts.latest("datetimecounted")
    assert latest_count.count_seen == post_data["count_seen"]
    assert latest_count.count_bar == post_data["count_bar"]