Example #1
0
 def test_site_data(self):
     sd = self.testsite.site_data()
     self.assertEquals(set(sd.keys()),     site_data_keys)
     self.assertEquals(sd["title"],        site_title())
     self.assertEquals(sd["rdfs:label"],   site_title())
     self.assertEquals(sd["collections"].keys(), init_collection_keys)
     self.assertDictionaryMatch(sd["collections"]["coll1"], self.coll1)
     return
Example #2
0
 def test_site_data(self):
     sd = self.testsite.site_data()
     self.assertEquals(set(sd.keys()), site_data_keys)
     self.assertEquals(sd["title"], site_title())
     self.assertEquals(sd["rdfs:label"], site_title())
     self.assertEquals(sd["rdfs:comment"], "Annalist site metadata.")
     self.assertEquals(sd["collections"].keys(),
                       ["coll1", "coll2", "coll3", "testcoll"])
     self.assertDictionaryMatch(sd["collections"]["coll1"], self.coll1)
     return
Example #3
0
 def test_get_no_login(self):
     self.client.logout()
     r = self.client.get(self.uri)
     self.assertFalse(r.context["auth_create"])
     self.assertFalse(r.context["auth_update"])
     self.assertFalse(r.context["auth_delete"])
     colls = r.context['collections']
     self.assertEqual(len(colls), len(init_collection_keys))
     for id in init_collections:
         self.assertEqual(colls[id]["annal:id"],   id)
         self.assertEqual(colls[id]["annal:url"],  init_collections[id]["annal:url"])
         self.assertEqual(colls[id]["rdfs:label"], init_collections[id]["rdfs:label"])
     # Check returned HTML (checks template logic)
     # (Don't need to keep doing this as logic can be tested through context as above)
     # (See: http://stackoverflow.com/questions/2257958/)
     s = BeautifulSoup(r.content, "html.parser")
     self.assertEqual(s.html.title.string, site_title())
     homelink = s.find(class_="title-area").find(class_="name").h1.a
     self.assertEqual(homelink.string,   "Home")
     self.assertEqual(homelink['href'],  self.uri)
     menuitems = s.find(class_="top-bar-section").find(class_="right").find_all("li")
     self.assertEqualIgnoreWS(menuitems[0].a.string,  "Login")
     self.assertEqual(menuitems[0].a['href'],         self.profileuri)
     # Check displayed collections
     trows = s.form.find_all("div", class_="tbody")
     self.assertEqual(len(trows), len(init_collection_keys))
     self.assertEqual(trows[0].div.div('div')[1].a.string,  "_annalist_site")
     self.assertEqual(trows[0].div.div('div')[1].a['href'], collection_view_url("_annalist_site"))
     self.assertEqual(trows[1].div.div('div')[1].a.string,  "coll1")
     self.assertEqual(trows[1].div.div('div')[1].a['href'], collection_view_url("coll1"))
     self.assertEqual(trows[2].div.div('div')[1].a.string,  "coll2")
     self.assertEqual(trows[2].div.div('div')[1].a['href'], collection_view_url("coll2"))
     self.assertEqual(trows[3].div.div('div')[1].a.string,  "coll3")
     self.assertEqual(trows[3].div.div('div')[1].a['href'], collection_view_url("coll3"))
     return
Example #4
0
 def test_get(self):
     # @@TODO: use reference to self.client, per 
     # https://docs.djangoproject.com/en/dev/topics/testing/tools/#default-test-client
     r = self.client.get(self.uri)
     self.assertEqual(r.status_code,   200)
     self.assertEqual(r.reason_phrase, "OK")
     self.assertContains(r, site_title("<title>%s</title>"))
     return
Example #5
0
    def test_get(self):
        # @@TODO: use reference to self.client, per
        # https://docs.djangoproject.com/en/dev/topics/testing/tools/#default-test-client
        loggedin = self.client.login(username="******",
                                     password="******")
        self.assertTrue(loggedin)
        u = reverse("AnnalistProfileView")
        r = self.client.get(u)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.reason_phrase, "OK")
        row1 = """
            <div class="row view-value-row">
              <div class="view-label small-12 medium-2 columns">
                <span>User</span>
              </div>
              <div class="view-value small-12 medium-10 columns">
                <span>testuser</span>
              </div>
            </div>
            """
        row2 = """
            <div class="row view-value-row">
              <div class="view-label small-12 medium-2 columns">
                <span>Name</span>
              </div>
              <div class="view-value small-12 medium-10 columns">
                <span>Test User</span>
              </div>
            </div>
            """
        row3 = """
            <div class="row view-value-row">
              <div class="view-label small-12 medium-2 columns">
                <span>Email</span>
              </div>
              <div class="view-value small-12 medium-10 columns">
                <span><a href="mailto:[email protected]">[email protected]</a></span>
              </div>
            </div>
            """

        # log.info(r.content)
        self.assertContains(r, site_title("<title>%s</title>"))
        self.assertContains(r, row1, html=True)
        self.assertContains(r, row2, html=True)
        self.assertContains(r, row3, html=True)
        return
Example #6
0
    def test_get(self):
        # @@TODO: use reference to self.client, per 
        # https://docs.djangoproject.com/en/dev/topics/testing/tools/#default-test-client
        loggedin = self.client.login(username="******", password="******")
        self.assertTrue(loggedin)
        u = reverse("AnnalistProfileView")
        r = self.client.get(u)
        self.assertEqual(r.status_code,   200)
        self.assertEqual(r.reason_phrase, "OK")
        row1 = """
            <div class="row view-value-row">
              <div class="view-label small-12 medium-2 columns">
                <span>User</span>
              </div>
              <div class="view-value small-12 medium-10 columns">
                <span>testuser</span>
              </div>
            </div>
            """
        row2 = """
            <div class="row view-value-row">
              <div class="view-label small-12 medium-2 columns">
                <span>Name</span>
              </div>
              <div class="view-value small-12 medium-10 columns">
                <span>Test User</span>
              </div>
            </div>
            """
        row3 = """
            <div class="row view-value-row">
              <div class="view-label small-12 medium-2 columns">
                <span>Email</span>
              </div>
              <div class="view-value small-12 medium-10 columns">
                <span><a href="mailto:[email protected]">[email protected]</a></span>
              </div>
            </div>
            """

        # log.info(r.content)
        self.assertContains(r, site_title("<title>%s</title>"))
        self.assertContains(r, row1, html=True)
        self.assertContains(r, row2, html=True)
        self.assertContains(r, row3, html=True)
        return
def entitydata_default_view_context_data(entity_id=None,
                                         orig_id=None,
                                         type_id="testtype",
                                         type_ids=[],
                                         action=None,
                                         update="Entity"):
    context_dict = ({
        'title':
        site_title(),
        'coll_id':
        'testcoll',
        'type_id':
        'testtype',
        'orig_id':
        'orig_entity_id',
        'fields': [
            {
                'field_label': 'Id',
                'field_name': 'entity_id',
                'field_placement':
                get_placement_classes('small:0,12;medium:0,6'),
                'field_id': 'Entity_id',
                'field_value_type': 'annal:Slug'
                # , 'field_value':      (Supplied separately)
                ,
                'options': []
            },
            {
                'field_label': 'Type',
                'field_name': 'entity_type',
                'field_placement':
                get_placement_classes('small:0,12;medium:6,6'),
                'field_id': 'Entity_type',
                'field_value_type': 'annal:Text'
                # , 'field_value':      (Supplied separately)
                ,
                'options': []
            },
            {
                'field_label': 'Label',
                'field_name': 'Entity_label',
                'field_placement': get_placement_classes('small:0,12'),
                'field_id': 'Entity_label',
                'field_value_type': 'annal:Text',
                'field_value': '%s data ... (testcoll/testtype)' % (update),
                'options': []
            },
            {
                'field_label': 'Comment',
                'field_name': 'Entity_comment',
                'field_placement': get_placement_classes('small:0,12'),
                'field_id': 'Entity_comment',
                'field_value_type': 'annal:Longtext',
                'field_value':
                '%s description ... (testcoll/testtype)' % (update),
                'options': []
            }
        ],
        'continuation_url':
        entitydata_list_type_url("testcoll", type_id)
    })
    if entity_id:
        context_dict['fields'][0]['field_value'] = entity_id
        context_dict['fields'][2][
            'field_value'] = '%s testcoll/testtype/%s' % (update, entity_id)
        context_dict['fields'][3][
            'field_value'] = '%s coll testcoll, type testtype, entity %s' % (
                update, entity_id)
        context_dict['orig_id'] = entity_id
    if type_id:
        context_dict['fields'][1]['field_value'] = type_id
    if orig_id:
        context_dict['orig_id'] = orig_id
    if action:
        context_dict['action'] = action
    return context_dict
Example #8
0
 def test_get_with_login(self):
     r = self.client.get(self.uri)
     # Preferred way to test main view logic
     self.assertTrue(r.context["auth_create"])
     self.assertTrue(r.context["auth_update"])
     self.assertTrue(r.context["auth_delete"])
     self.assertTrue(r.context["auth_create_coll"])
     self.assertTrue(r.context["auth_delete_coll"])
     colls = r.context['collections']
     self.assertEqual(len(colls), len(init_collection_keys))
     for id in init_collections:
         # First two here added in models.site.site_data()
         self.assertEqual(colls[id]["id"],         id)
         self.assertEqual(colls[id]["url"],        init_collections[id]["annal:url"])
         self.assertEqual(colls[id]["annal:id"],   id)
         self.assertEqual(colls[id]["annal:url"],  init_collections[id]["annal:url"])
         self.assertEqual(colls[id]["rdfs:label"], init_collections[id]["rdfs:label"])
     # Check returned HTML (checks template logic)
     # (Don't need to keep doing this as logic can be tested through context as above)
     # (See: http://stackoverflow.com/questions/2257958/)
     s = BeautifulSoup(r.content, "html.parser")
     # title and top menu
     self.assertEqual(s.html.title.string, site_title())
     homelink = s.find(class_="title-area").find(class_="name").h1.a
     self.assertEqual(homelink.string,   "Home")
     self.assertEqual(homelink['href'],  self.uri)
     menuitems = s.find(class_="top-bar-section").find(class_="right").find_all("li")
     self.assertEqualIgnoreWS(menuitems[0].a.string, "User testuser")
     self.assertEqual(menuitems[0].a['href'],        TestBasePath+"/profile/")
     self.assertEqualIgnoreWS(menuitems[1].a.string, "Logout")
     self.assertEqual(menuitems[1].a['href'],        TestBasePath+"/logout/")
     # Displayed colllections and check-buttons
     # trows = s.form.find_all("div", class_="tbody")
     trows = s.select("form > div > div > div")
     self.assertEqual(len(trows), len(init_collection_keys)+4)
     site_data = (
         [ (1, "checkbox", "select", "_annalist_site")
         , (2, "checkbox", "select", "coll1")
         , (3, "checkbox", "select", "coll2")
         , (4, "checkbox", "select", "coll3")
         ])
     for i, itype, iname, ivalue in site_data:
         # tcols = trows[i].find_all("div", class_="view-value")
         tcols = trows[i].select("div > div > div")
         self.assertEqual(tcols[0].input['type'],   itype)
         self.assertEqual(tcols[0].input['name'],   iname)
         self.assertEqual(tcols[0].input['value'],  ivalue)
         self.assertEqual(tcols[1].a.string,        ivalue)
         self.assertEqual(tcols[1].a['href'],       collection_view_url(ivalue))
     # buttons to view/edit/remove selected
     btn_view = trows[5].select("div > input")[0]
     self.assertEqual(btn_view["type"],  "submit")
     self.assertEqual(btn_view["name"],  "view")
     btn_edit = trows[5].select("div > input")[1]
     self.assertEqual(btn_edit["type"],  "submit")
     self.assertEqual(btn_edit["name"],  "edit")
     btn_remove = trows[5].select("div > input")[2]
     self.assertEqual(btn_remove["type"],  "submit")
     self.assertEqual(btn_remove["name"],  "remove")
     # Input fields for new collection
     add_fields = trows[6].select("div > div > div")
     field_id    = add_fields[1].input
     field_label = add_fields[2].input
     self.assertEqual(field_id["type"],    "text")
     self.assertEqual(field_id["name"],    "new_id")
     self.assertEqual(field_label["type"], "text")
     self.assertEqual(field_label["name"], "new_label")
     # Button for new collection
     btn_new = trows[7].select("div > input")[0]
     self.assertEqual(btn_new["type"],     "submit")
     self.assertEqual(btn_new["name"],     "new")
     return
Example #9
0
 def test_get_with_login(self):
     r = self.client.get(self.uri)
     # Preferred way to test main view logic
     self.assertTrue(r.context["auth_create"])
     self.assertTrue(r.context["auth_update"])
     self.assertTrue(r.context["auth_delete"])
     self.assertTrue(r.context["auth_create_coll"])
     self.assertTrue(r.context["auth_delete_coll"])
     colls = r.context['collections']
     self.assertEqual(len(colls), 4)
     for id in init_collections:
         # First two here added in models.site.site_data()
         self.assertEqual(colls[id]["id"], id)
         self.assertEqual(colls[id]["url"],
                          init_collections[id]["annal:url"])
         self.assertEqual(colls[id]["annal:id"], id)
         self.assertEqual(colls[id]["annal:url"],
                          init_collections[id]["annal:url"])
         self.assertEqual(colls[id]["rdfs:label"],
                          init_collections[id]["rdfs:label"])
     # Check returned HTML (checks template logic)
     # (Don't need to keep doing this as logic can be tested through context as above)
     # (See: http://stackoverflow.com/questions/2257958/)
     s = BeautifulSoup(r.content)
     # title and top menu
     self.assertEqual(s.html.title.string, site_title())
     homelink = s.find(class_="title-area").find(class_="name").h1.a
     self.assertEqual(homelink.string, "Home")
     self.assertEqual(homelink['href'], self.uri)
     menuitems = s.find(class_="top-bar-section").find(
         class_="right").find_all("li")
     self.assertEqual(menuitems[0].a.string, "User testuser")
     self.assertEqual(menuitems[0].a['href'], TestBasePath + "/profile/")
     self.assertEqual(menuitems[1].a.string, "Logout")
     self.assertEqual(menuitems[1].a['href'], TestBasePath + "/logout/")
     # Displayed colllections and check-buttons
     trows = s.form.find_all("div", class_="row")
     self.assertEqual(len(trows), 7)
     tcols1 = trows[1].find_all("div")
     self.assertEqual(tcols1[0].a.string, "coll1")
     self.assertEqual(tcols1[0].a['href'], collection_view_url("coll1"))
     self.assertEqual(tcols1[2].input['type'], "checkbox")
     self.assertEqual(tcols1[2].input['name'], "select")
     self.assertEqual(tcols1[2].input['value'], "coll1")
     tcols2 = trows[2].find_all("div")
     self.assertEqual(tcols2[0].a.string, "coll2")
     self.assertEqual(tcols2[0].a['href'], collection_view_url("coll2"))
     self.assertEqual(tcols2[2].input['type'], "checkbox")
     self.assertEqual(tcols2[2].input['name'], "select")
     self.assertEqual(tcols2[2].input['value'], "coll2")
     tcols3 = trows[3].find_all("div")
     self.assertEqual(tcols3[0].a.string, "coll3")
     self.assertEqual(tcols3[0].a['href'], collection_view_url("coll3"))
     self.assertEqual(tcols3[2].input['type'], "checkbox")
     self.assertEqual(tcols3[2].input['name'], "select")
     self.assertEqual(tcols3[2].input['value'], "coll3")
     tcols4 = trows[4].find_all("div")
     self.assertEqual(tcols4[0].a.string, "testcoll")
     self.assertEqual(tcols4[0].a['href'], collection_view_url("testcoll"))
     self.assertEqual(tcols4[2].input['type'], "checkbox")
     self.assertEqual(tcols4[2].input['name'], "select")
     self.assertEqual(tcols4[2].input['value'], "testcoll")
     # Remove/new collection buttons
     btn_remove = trows[5].find("div", class_="right")
     self.assertEqual(btn_remove.input["type"], "submit")
     self.assertEqual(btn_remove.input["name"], "remove")
     # Input fields and button for new collection
     field_id = trows[6].find_all("div")[0]
     self.assertEqual(field_id.input["type"], "text")
     self.assertEqual(field_id.input["name"], "new_id")
     field_id = trows[6].find_all("div")[1]
     self.assertEqual(field_id.input["type"], "text")
     self.assertEqual(field_id.input["name"], "new_label")
     btn_new = trows[6].find_all("div")[2]
     self.assertEqual(btn_new.input["type"], "submit")
     self.assertEqual(btn_new.input["name"], "new")
     return