Beispiel #1
0
    def test_hyperlink_case_insensitive(self):
        settings.auto_cross_reference = True
        # create 1st CE
        ce = models.CultureEvent(title='Example CE1',
                                 description_plain_text='A first CE')
        ce.save()

        # All lower case
        # create 2nd CE with a hyperlink intended
        desc = 'A second CE, that references example ce1'
        ce = models.CultureEvent(title='Example CE2',
                                 description_plain_text=desc)
        ce.save()

        self.assertEqual(desc, ce.description_plain_text)
        self.assertIn('href', ce.description,
                      'All lower case doesn\'t autolink')
        ce = models.CultureEvent.objects.get(pk=2)
        # All upper case
        desc = 'A SECOND CE, THAT REFERENCES EXAMPLE CE1'
        ce.description_plain_text = desc
        ce.save()
        self.assertEqual(desc, ce.description_plain_text)
        self.assertIn('href', ce.description,
                      'All upper case doesn\'t autolink')
        # Mixed case
        desc = 'A second CE, that references Example CE1'
        ce.description_plain_text = desc
        ce.save()
        self.assertEqual(desc, ce.description_plain_text)
        self.assertIn('href', ce.description, 'Mixed case doesn\'t autolink')
Beispiel #2
0
    def test_repeated_title_not_allowed(self):
        # CE titles should be unique
        ce = models.CultureEvent(title='Example CE1',
                                 description_plain_text='A first CE')
        ce.save()
        ce = models.CultureEvent(title='Example CE1',
                                 description_plain_text='A second CE')

        with self.assertRaises(exceptions.ValidationError):
            ce.save()
Beispiel #3
0
    def setUp(self):
        self.client.login(username='******', password='******')
        # have one model previously in .db
        ce = models.CultureEvent(
            title='An Example CE1',
            description_plain_text='A culture event happened',
            differences='Last time it was different')
        ce.save()
        visits = models.Visit(date='2019-08-05',
                              team_present='Steve',
                              nationals_present='Ulumo',
                              ce=ce)
        visits.save()
        questions = models.Question(question='First question',
                                    answer='First answer',
                                    asked_by='Tester',
                                    ce=ce)
        questions.save()
        time.sleep(0.1)
        ce = models.CultureEvent(
            title='Cats like Example CE2',
            description_plain_text='A culture event happened again',
            differences='Last time it was different')
        ce.save()
        questions = models.Question(question='Second question',
                                    asked_by='Tester',
                                    ce=ce)
        questions.save()
        visits = models.Visit(date='2019-08-06',
                              team_present='Rhett',
                              nationals_present='Ulumo',
                              ce=ce)
        visits.save()
        time.sleep(0.1)

        ce = models.CultureEvent(
            title='because I can Example CE3',
            description_plain_text='A culture event happened a third time',
            differences='Last time it was different')
        ce.save()
        questions = models.Question(question='Third question',
                                    asked_by='Tester',
                                    ce=ce)
        questions.save()
        time.sleep(0.1)
        questions = models.Question(question='Fourth question',
                                    asked_by='Tester',
                                    ce=ce)
        questions.save()
        visits = models.Visit(date='2019-08-07',
                              team_present='Philip',
                              nationals_present='Ulumo',
                              ce=ce)
        visits.save()
Beispiel #4
0
    def test_auto_hyperlink_numbers(self):
        settings.auto_cross_reference = True
        ce = models.CultureEvent(title='Reef fishing 2')
        ce.save()

        ce = models.CultureEvent(title='Example CE2',
                                 description_plain_text='reef fishing 2')
        ce.save()

        self.assertIn('href', ce.description, 'No link')
        self.assertIn('<a href="reef-fishing-2">Reef fishing 2</a>',
                      ce.description, 'Link malformed')
Beispiel #5
0
 def test_no_auto_cross_reference_if_setting_disabled(self):
     settings.auto_cross_reference = False
     # create 1st CE
     ce = models.CultureEvent(title='Example CE1',
                              description_plain_text='A first CE')
     ce.save()
     # create 2nd CE that shouldn't hyperlink
     ce = models.CultureEvent(
         title='Example CE2',
         description_plain_text='example ce1 should pass silently')
     ce.save()
     self.assertNotIn('href', ce.description,
                      'Html anchor auto added  despite settings')
Beispiel #6
0
    def setUp(self):
        ce = models.CultureEvent(title='Example CE1',
                                 description_plain_text='A first CE')
        ce.save()
        tags = OCM_categories.check_tags_for_OCM('1-1, 1-16, Culture')
        for tag in tags:
            ce.tags.add(tag)

        ce = models.CultureEvent(title='Example CE2',
                                 description_plain_text='A second CE')
        ce.save()
        tags = OCM_categories.check_tags_for_OCM('Culture')
        for tag in tags:
            ce.tags.add(tag)
Beispiel #7
0
 def setUp(self):
     self.total_CEs = 48  # create dummy CEs
     for i in range(50):
         Ces = models.CultureEvent(title=('Example culture event ' +
                                          str(i)),
                                   last_modified_by='Tester')
         Ces.save()
Beispiel #8
0
 def test_repeated_hyperlink(self):
     settings.auto_cross_reference = True
     # create 1st CE
     ce = models.CultureEvent(title='Test CE',
                              description_plain_text='A first CE')
     ce.save()
     ce = models.CultureEvent(
         title='Example CE2',
         description_plain_text=
         'I\'m linking test CE twice by saying test CE again. test CE')
     ce.save()
     self.assertEqual(ce.description.count('href'), 3,
                      'Incorrect number of hyperlinks')
     self.assertEqual(
         ce.description,
         'I\'m linking <a href="test-ce">Test CE</a> twice by saying '
         '<a href="test-ce">Test CE</a> again. <a href="test-ce">Test CE</a>',
         'Repeated hyperlink not displaying correctly')
Beispiel #9
0
 def setUp(self):
     ce = models.CultureEvent(
         title='Example CE1',
         description_plain_text='A culture event happened',
         differences='Last time it was different')
     ce.save()
     text = models.Text(ce=models.CultureEvent.objects.get(pk=3),
                        audio='musicFile.ogg',
                        phonetic_text='foᵘnɛtɪks',
                        orthographic_text='orthographic')
     text.save()
Beispiel #10
0
    def test_hyperlink_accuracy(self):
        # Test to make sure auto hyperlink handles similar CE titles correctly
        ce = models.CultureEvent(title='A CE')
        ce.save()
        ce = models.CultureEvent(title='A CE longer')
        ce.save()
        ce = models.CultureEvent(title='A CE long')
        ce.save()
        ce = models.CultureEvent(title='A CE longer again')
        ce.save()
        desc = 'a ce was before a ce long, but after a ce longer and then a ce longer again happened'
        ce = models.CultureEvent(title='Test', description_plain_text=desc)
        ce.save()
        self.assertIn('href', ce.description, 'no hyperlinks')
        self.assertEqual(ce.description.count('href'), 4,
                         'Incorrect number of hyperlinks')

        # test for each link
        self.assertIn('<a href="a-ce">A CE</a>', ce.description,
                      'shortest link not present')
        self.assertIn('<a href="a-ce-long">A CE long</a>', ce.description,
                      'length 2 link not present')
        self.assertIn('<a href="a-ce-longer">A CE longer</a>', ce.description,
                      'length 3 link not present')
        self.assertIn('<a href="a-ce-longer-again">A CE longer again</a>',
                      ce.description, 'longest link not present')

        # reverse the order stored in the .db
        desc = 'a ce longer again was before a ce longer, but not a long ce and certainly not a ce.'
        ce.description_plain_text = desc
        ce.save()
        # test for each link
        self.assertIn('<a href="a-ce">A CE</a>', ce.description,
                      'shortest link not present')
        self.assertIn('<a href="a-ce-long">A CE long</a>', ce.description,
                      'length 2 link not present')
        self.assertIn('<a href="a-ce-longer">A CE longer</a>', ce.description,
                      'length 3 link not present')
        self.assertIn('<a href="a-ce-longer-again">A CE longer again</a>',
                      ce.description, 'longest link not present')
Beispiel #11
0
 def test_ocm_tags_changed(self):
     # create a test CE
     ce = models.CultureEvent(title='Example CE1',
                              description_plain_text='A first CE')
     ce.save()
     # call the custom tag parser to check it handles OCM tags, and leaves other things alone
     tags = OCM_categories.check_tags_for_OCM('What a tag, 1-1, 1-16')
     for tag in tags:
         ce.tags.add(tag)
     results = ce.tags.all().values()
     self.assertIn('What a tag', str(results))
     self.assertIn('1-16', str(results))
     self.assertIn('1-1 Geography & Weather', str(results))
Beispiel #12
0
    def test_auto_hyperlink(self):
        settings.auto_cross_reference = True
        # create 1st CE
        ce = models.CultureEvent(title='Example',
                                 description_plain_text='A first CE')
        ce.save()
        # create 2nd CE with a hyperlink intended
        description_two = 'A second CE, that references example'
        ce = models.CultureEvent(title='Example CE2',
                                 description_plain_text=description_two)
        ce.save()
        self.assertEqual(description_two, ce.description_plain_text)
        self.assertIn('href', ce.description, 'no href in autolink')
        self.assertIn('<a href="example">Example</a>', ce.description,
                      'Anchor malformed')

        # create 3rd CE with no hyperlinks intended
        description_three = 'A second CE, that references no other CEs'
        ce = models.CultureEvent(title='Example CE2',
                                 description_plain_text=description_three)
        self.assertEqual(description_three, ce.description_plain_text)
        self.assertNotIn('href', ce.description)
Beispiel #13
0
    def test_manual_hyperlink(self):
        settings.auto_cross_reference = False
        # create 1st CE
        ce = models.CultureEvent(title='Example CE1',
                                 description_plain_text='A first CE')
        ce.save()
        # create 2nd CE with a hyperlink intended
        description_two = 'A second CE, that references {example ce1}'
        ce = models.CultureEvent(title='Example CE2',
                                 description_plain_text=description_two)
        ce.save()
        self.assertEqual(description_two, ce.description_plain_text)
        self.assertIn('href', ce.description)

        # create 3rd CE with no hyperlinks intended
        description_three = 'A second CE, that doesn\'t {reference} example ce1'
        ce = models.CultureEvent(title='Example CE2',
                                 description_plain_text=description_three)
        self.assertEqual(description_three, ce.description_plain_text)
        self.assertNotIn('href', ce.description)

        # test invalid tags not shown
        self.assertIn('{reference}', ce.description_plain_text)
        self.assertNotIn('{reference}', ce.description)
Beispiel #14
0
    def test_invalid_HTML_removed(self):
        settings.auto_cross_reference = True
        # create 1st CE
        ce = models.CultureEvent(
            title='First CE',
            description_plain_text='<strong>Some text</strong>'
            '<a href="Dodgywebsite.come">Click here</a>'
            '<script>Nasty JS</script>')
        ce.save()
        # <script> removed
        self.assertIn('<script>', ce.description_plain_text)
        self.assertNotIn('<script>', ce.description,
                         '<scripts> were not removed')

        # <strong> allowed
        settings.bleach_allowed = ['strong']
        self.assertIn('<strong>', ce.description_plain_text)
        self.assertIn('<strong>', ce.description, 'Allowable HTML was removed')
Beispiel #15
0
 def setUp(self):
     ce = models.CultureEvent(title='Example CE1',
                              description_plain_text='A first CE')
     ce.save()
     self.text1 = models.Text(text_title='Text 1',
                              last_modified_by='Tester',
                              phonetic_standard='1',
                              discourse_type='1',
                              orthographic_text='Ortho1',
                              ce=ce)
     self.text1.save()
     self.text2 = models.Text(text_title='Text 2',
                              last_modified_by='Tester',
                              phonetic_standard='2',
                              discourse_type='2',
                              orthographic_text='Ortho2',
                              ce=ce)
     self.text2.save()
Beispiel #16
0
 def test_string_method(self):
     ce = models.CultureEvent(title='Example CE1')
     self.assertEqual(str(ce), 'Example CE1')
Beispiel #17
0
 def test_string_method(self):
     ce = models.CultureEvent(title='Example CE1')
     text = models.Text(ce=ce,
                        phonetic_text='djaŋɡo',
                        text_title='example text')
     self.assertEqual(str(text), 'example text')
Beispiel #18
0
def insert_example_CEs(apps, schema_editor):
    example_ce_1 = models.CultureEvent(
        title="Example CE",
        last_modified_by='CLAHubDev',
        description_plain_text=
        '''We arranged with a family beforehand that we'd come with the and see how laundry is done.
The family was waiting for us when we arrived, they had remembered we were coming.
The children were sent by some ladies to get some buckets and 2 girls went to get water from the public well.
We went to an area that had a big piece of hard plastic that lying on a big tractor tire. 
One girl first made all the clothes wet in one bucket and transferred them to another bucket. Another girl put soap in this bucket and made the water soapy. Then she took out the clothes one by one, laid them on the plastic and brushed them with a brush. Clothes with stains were treated with bleach and put aside to soak for a couple of minutes. Fragile clothes were kneaded together with soap and not brushed. 
In between someone had gotten 2 more buckets of water.
One was to rinse off the soap. Then the second one to rinse again.
The wet clothes were put in another bucket again and hung up at the washing line.''',
        interpretation=
        '''There were no men present at all suggesting that laundry is women's work.''',
        differences='I\'ve seen people washing at a nearby stream too')
    example_ce_1.save()
    with open(os.path.join(example_data_folder, 'example_audio1.mp3'),
              'rb') as file:
        file = file.read()
        audio = SimpleUploadedFile(name='example_audio1.mp3',
                                   content=file,
                                   content_type='audio')

        example_text_1 = models.Text(
            ce=example_ce_1,
            text_title='Maryanne talking about doing laundry',
            phonetic_text=
            '''oke fəst mipla ɡo pulapim wara kam kapsaⁱtim insaⁱt lo bakɛt sɛrim wara biloŋ 
            raᵘsim dəti lo rins na mipla fəst mipla wasim dəti bihaⁱn mipla putim ɡo lo sop wara mipla 
            brasim ol klots pinis sampla blo blits ja mipla blitsim ol pinis mipla putim go lo rins wara 
            mipla rinsim rinsim sop raᵘsim mipla ɡo lo klin wara mipla rinsim naᵘ mipla ɡo haŋgamapim lo 
            laⁱn ɛm tʃol''',
            phonetic_standard='1',
            discourse_type='3',
            last_modified_by='CLAHubDev',
            orthographic_text='''Orthographic text goes here :)''',
            audio=audio)
        example_text_1.save()
        example_ce_1.tags.add('Example')

    for i in range(1, 5):
        with open(
                os.path.join(example_data_folder,
                             'example_CE_pic%s.jpg' % str(i)), 'rb') as file:
            file = file.read()
            picture = SimpleUploadedFile(name='example_CE_pic%s.jpg' % str(i),
                                         content=file,
                                         content_type='image')
            example_pic = models.Picture(picture=picture, ce=example_ce_1)
            example_pic.save()

    visit = models.Visit(ce=example_ce_1,
                         team_present='Gerdine, Becky',
                         nationals_present='Maryanne and family',
                         date='2016-02-06')
    visit.save()
    question1 = models.Question(
        ce=example_ce_1,
        asked_by='CLAHubDev',
        last_modified_by='CLAHubDev',
        question=
        'Do some families struggle to afford soap, or does everyone have it?')
    question1.save()
    question2 = models.Question(
        ce=example_ce_1,
        asked_by='CLAHubDev',
        last_modified_by='CLAHubDev',
        question='How dirty do people let their clothes get before washing?',
        answer=
        'Pretty dirty :), but they do take more care to not get them so dirty in the first place compared to us.'
    )
    question2.save()

    example_ce_2 = models.CultureEvent(
        title='Explanation of CLAHub features',
        last_modified_by='CLAHubDev',
        description_plain_text=
        '''This area is for describing the Culture Event (CE) in general. The
         description field should contain objective information (no interpretation, guesses,
          musings or language learner POV) about the CE.Your
        team should work together to build a complete page for each CE. The intention of CLAHub is that
        pages become a snapshot of the team's best information on any given CE. That means there will
        be a single \'Harvesting Sago\' CE that team members add information to over time. There
        shouldn\'t be \'Team member A goes fishing\' and \'Team member B goes fishing\' CEs, but
        rather if team member A creates a Fishing CE, team member B should build on it.
         
         Language learning will require that both team member A and team member B both have personalised
         notes elsewhere. For instance team member A might be working on learning basic vocabulary,
          but Team member B is further along and is working on learning something else. CLAHub isn\'t 
          designed to file those notes and they should be kept separately by each language learner so
          they can learn as productively as possible
          
          The description field is unique in CLAHub in that it will automatically create cross
          references between CEs by simply reading the text. All you need to do to create a link
          to anther CE is to type it's title. example ce for example.''',
        interpretation=
        '''Typically a CE has much more going on than what can be documented on
        a surface level. This field is a place where you can write up implicit information about a 
        CE. As a language learner you're likely to guess wrong at times and interpret CEs incorrectly,
        this is why the deescription is to remain objective. This field allows the team to dig deeper,
        while keeping objective facts separate from the team's understanding of a culture's worldview''',
        differences=
        'Multiple team members will be contributing to each CE and team members will'
        'participate in CEs multiple times. The description field allows the team to write'
        'a generalized description of the CE, while the variations field allows team members'
        'to include information about times the CE deviated from the regular pattern, or to'
        'add specific information from their participation')
    example_ce_2.save()
    def setUp(self):
        # the prexisiting model objects variable is used to exclude example data
        self.prexisiting_model_objects = {
            'CE': len(models.CultureEvent.objects.all()),
            'Text': len(models.Text.objects.all()),
            'Visit': len(models.Visit.objects.all()),
            'Question': len(models.Question.objects.all()),
        }
        self.test_data = {
            'username': '******',
            'title': 'Test CE1',
            'description_plain_text': 'A culture event happened',
            'differences': 'Last time it was different',
            'interpretation': 'It probably has meaning',
            'nationals_present': 'Initial data',
            'team_present': 'Steve',
            'date': '2019-02-20',
            'phonetic_text': 'foᵘnɛtɪks',
            'orthographic_text': 'orthographic',
            'tags': 'taggie',
            'question': 'Does this test work?',
            'answer': 'Yes, it does!'}

        self.client.login(username='******', password='******')
        ce = models.CultureEvent(title=self.test_data['title'],
                                 description_plain_text=self.test_data['description_plain_text'],
                                 differences=self.test_data['differences'],
                                 interpretation=self.test_data['interpretation'], )
        ce.save()
        ce2 = models.CultureEvent(title='TestCE2')
        ce2.save()
        ce.tags.add(self.test_data['tags'])
        visit = models.Visit(nationals_present=self.test_data['nationals_present'],
                             team_present=self.test_data['team_present'],
                             date=self.test_data['date'],
                             ce=ce)
        visit.save()
        text = models.Text(ce=ce,
                           phonetic_text=self.test_data['phonetic_text'],
                           orthographic_text=self.test_data['orthographic_text'])
        text.save()
        text2 = models.Text(ce=ce,
                            phonetic_text='phonetic_text2',
                            orthographic_text=self.test_data['orthographic_text'])
        text2.save()
        q = models.Question(ce=ce,
                            question=self.test_data['question'],
                            answer=self.test_data['answer'])
        q.save()

        self.test_ce1_pk = str(self.prexisiting_model_objects['CE'] + 1)
        self.test_ce2_pk = str(self.prexisiting_model_objects['CE'] + 2)
        self.test_text1_pk = str(self.prexisiting_model_objects['Text'] + 1)
        self.test_text2_pk = str(self.prexisiting_model_objects['Text'] + 2)
        self.test_visit_pk = str(self.prexisiting_model_objects['Visit'] + 1)
        self.test_question_pk = str(self.prexisiting_model_objects['Question'] + 1)
        self.new_ce_pk = str(self.prexisiting_model_objects['CE'] + 3)
        self.test_ce1_upload_path = os.path.join(base_settings.MEDIA_ROOT, 'CultureEventFiles', str(self.test_ce1_pk))
        self.test_files_path = os.path.join(base_settings.BASE_DIR, 'CLAHub', 'assets', 'test_data')
        self.test_pic1_path = os.path.join(self.test_files_path, 'test_pic1.jpg')
        self.test_audio1_path = os.path.join(self.test_files_path, 'test_audio1.mp3')
        self.test_audio2_path = os.path.join(self.test_files_path, 'test_audio2.mp3')
        self.upload_folder = os.path.join(base_settings.MEDIA_ROOT, 'CultureEventFiles')

        # formset IDs are and CEs are picked up through the view normally, but need to be supplied for tests
        # text-0-ce refers is the CE.pk used as foreign key
        # text-0-id refers to the text.pk
        self.standard_post = {'text-TOTAL_FORMS': 2,
                              'text-INITIAL_FORMS': 2,
                              'question-TOTAL_FORMS': 1,
                              'question-INITIAL_FORMS': 1,
                              'visit-TOTAL_FORMS': 1,
                              'visit-INITIAL_FORMS': 1,
                              'title': self.test_data['title'],
                              'description_plain_text': self.test_data['description_plain_text'],
                              'tags': self.test_data['tags'],
                              'differences': self.test_data['differences'],
                              'interpretation': self.test_data['interpretation'],
                              'text-0-phonetic_text': self.test_data['phonetic_text'],
                              'text-0-orthographic_text': self.test_data['orthographic_text'],
                              'text-0-ce': self.test_ce1_pk,
                              'text-0-id': 1,
                              'text-1-phonetic_text': self.test_data['phonetic_text'],
                              'text-1-orthographic_text': self.test_data['orthographic_text'],
                              'text-1-ce': self.test_ce1_pk,
                              'text-1-id': '2',
                              'visit-0-ce': self.test_ce1_pk,
                              'visit-0-id': 1,
                              'visit-0-team_present': self.test_data['team_present'],
                              'visit-0-nationals_present': 'Posted_data',
                              'visit-0-date': self.test_data['date'],
                              'question-0-ce': self.test_ce1_pk,
                              'question-0-id': 3,
                              'question-0-question': self.test_data['question'],
                              'question-0-answer': self.test_data['answer']
                              }

        self.new_post = {'title': 'Test CE',
                         'description_plain_text': self.test_data['description_plain_text'],
                         'visit-0-date': self.test_data['date'],
                         'visit-0-nationals_present': self.test_data['nationals_present'],
                         'visit-0-team_present': self.test_data['team_present'],
                         'text-TOTAL_FORMS': 0,
                         'text-INITIAL_FORMS': 0,
                         'question-TOTAL_FORMS': 0,
                         'question-INITIAL_FORMS': 0,
                         'visit-TOTAL_FORMS': 1,
                         'visit-INITIAL_FORMS': 0
                         }