예제 #1
0
 def test_get_metadata_keys(self):
     """Get the metadata keys associated with this crowdsoucre's data"""
     crowdsource = CrowdsourceFactory()
     eq_(crowdsource.get_metadata_keys(), [])
     data = CrowdsourceDataFactory(crowdsource=crowdsource)
     eq_(crowdsource.get_metadata_keys(), [])
     data.metadata = {"foo": "bar", "muck": "rock"}
     data.save()
     eq_(set(crowdsource.get_metadata_keys()), {"foo", "muck"})
예제 #2
0
 def test_get_metadata_keys(self):
     """Get the metadata keys associated with this crowdsoucre's data"""
     crowdsource = CrowdsourceFactory()
     eq_(crowdsource.get_metadata_keys(), [])
     data = CrowdsourceDataFactory(crowdsource=crowdsource)
     eq_(crowdsource.get_metadata_keys(), [])
     data.metadata = {'foo': 'bar', 'muck': 'rock'}
     data.save()
     eq_(set(crowdsource.get_metadata_keys()), {'foo', 'muck'})
예제 #3
0
 def test_get_header_values(self):
     """Get the header values for CSV export"""
     crowdsource = CrowdsourceFactory()
     CrowdsourceTextFieldFactory(
         crowdsource=crowdsource,
         label='Text Field',
         help_text='Help',
         order=0,
     )
     CrowdsourceSelectFieldFactory(
         crowdsource=crowdsource,
         label='Select Field',
         order=1,
     )
     eq_(
         crowdsource.get_header_values(['meta']),
         [
             'user',
             'datetime',
             'skip',
             'flag',
             'gallery',
             'tags',
             'Text Field',
             'Select Field',
         ],
     )
     crowdsource.multiple_per_page = True
     eq_(
         crowdsource.get_header_values(['meta']),
         [
             'user',
             'datetime',
             'skip',
             'flag',
             'gallery',
             'tags',
             'number',
             'Text Field',
             'Select Field',
         ],
     )
     CrowdsourceDataFactory(crowdsource=crowdsource)
     eq_(
         crowdsource.get_header_values(['meta']),
         [
             'user',
             'datetime',
             'skip',
             'flag',
             'gallery',
             'tags',
             'number',
             'datum',
             'meta',
             'Text Field',
             'Select Field',
         ],
     )
예제 #4
0
 def test_get_data_to_show(self):
     """Get data to show should pick the correct data"""
     crowdsource = CrowdsourceFactory()
     ip_address = None
     assert_is_none(
         crowdsource.get_data_to_show(crowdsource.user, ip_address))
     data = CrowdsourceDataFactory(crowdsource=crowdsource)
     eq_(data, crowdsource.get_data_to_show(crowdsource.user, ip_address))
예제 #5
0
파일: tests.py 프로젝트: clytwynec/muckrock
    def test_get_choices(self):
        """Test the get choices queryset method"""
        crowdsource = CrowdsourceFactory()
        data = CrowdsourceDataFactory.create_batch(
            3,
            crowdsource=crowdsource,
        )
        user = crowdsource.user
        limit = 2

        # all data should be valid choices
        eq_(
            set(crowdsource.data.get_choices(limit, user)),
            set(data),
        )
        # if I respond to one, it is no longer a choice for me
        CrowdsourceResponseFactory(
            crowdsource=crowdsource,
            user=crowdsource.user,
            data=data[0],
        )
        eq_(
            set(crowdsource.data.get_choices(limit, user)),
            set(data[1:]),
        )
        # if one has at least `limit` responses, it is no longer a valid choice
        CrowdsourceResponseFactory.create_batch(
            2,
            crowdsource=crowdsource,
            data=data[1],
        )
        eq_(
            set(crowdsource.data.get_choices(limit, user)),
            set(data[2:]),
        )
        # multiple responses from the same user only count once
        new_user = UserFactory()
        CrowdsourceResponseFactory.create_batch(
            2,
            crowdsource=crowdsource,
            data=data[2],
            user=new_user,
        )
        eq_(
            set(crowdsource.data.get_choices(limit, user)),
            set(data[2:]),
        )
예제 #6
0
    def test_get_choices(self):
        """Test the get choices queryset method"""
        crowdsource = CrowdsourceFactory()
        data = CrowdsourceDataFactory.create_batch(4, crowdsource=crowdsource)
        user = crowdsource.user
        ip_address = "127.0.0.1"
        limit = 2

        # all data should be valid choices
        eq_(set(crowdsource.data.get_choices(limit, user, None)), set(data))
        # if I respond to one, it is no longer a choice for me
        CrowdsourceResponseFactory(crowdsource=crowdsource,
                                   user=crowdsource.user,
                                   data=data[0])
        eq_(set(crowdsource.data.get_choices(limit, user, None)),
            set(data[1:]))
        # if one has at least `limit` responses, it is no longer a valid choice
        CrowdsourceResponseFactory.create_batch(2,
                                                crowdsource=crowdsource,
                                                data=data[1])
        eq_(set(crowdsource.data.get_choices(limit, user, None)),
            set(data[2:]))
        # multiple responses from the same user only count once
        new_user = UserFactory()
        CrowdsourceResponseFactory(crowdsource=crowdsource,
                                   user=new_user,
                                   data=data[2],
                                   number=1)
        CrowdsourceResponseFactory(crowdsource=crowdsource,
                                   user=new_user,
                                   data=data[2],
                                   number=2)
        eq_(set(crowdsource.data.get_choices(limit, user, None)),
            set(data[2:]))
        # if I anonymously to one, it is no longer a choice for me
        CrowdsourceResponseFactory(crowdsource=crowdsource,
                                   ip_address=ip_address,
                                   data=data[3])
        eq_(
            set(crowdsource.data.get_choices(limit, None, ip_address)),
            set([data[0], data[2]]),
        )
예제 #7
0
 def test_get_header_values(self):
     """Get the header values for CSV export"""
     crowdsource = CrowdsourceFactory()
     CrowdsourceTextFieldFactory(crowdsource=crowdsource,
                                 label="Text Field",
                                 help_text="Help",
                                 order=0)
     CrowdsourceHeaderFieldFactory(crowdsource=crowdsource,
                                   label="Header",
                                   order=1)
     CrowdsourceSelectFieldFactory(crowdsource=crowdsource,
                                   label="Select Field",
                                   order=2)
     eq_(
         crowdsource.get_header_values(["meta"]),
         [
             "user",
             "public",
             "datetime",
             "skip",
             "flag",
             "gallery",
             "tags",
             "Text Field",
             "Select Field",
         ],
     )
     crowdsource.multiple_per_page = True
     eq_(
         crowdsource.get_header_values(["meta"]),
         [
             "user",
             "public",
             "datetime",
             "skip",
             "flag",
             "gallery",
             "tags",
             "number",
             "Text Field",
             "Select Field",
         ],
     )
     CrowdsourceDataFactory(crowdsource=crowdsource)
     eq_(
         crowdsource.get_header_values(["meta"]),
         [
             "user",
             "public",
             "datetime",
             "skip",
             "flag",
             "gallery",
             "tags",
             "number",
             "datum",
             "meta",
             "Text Field",
             "Select Field",
         ],
     )