Projet

Général

Profil

0001-datasource-all-agendas-agendas-of-a-category-58884.patch

Lauréline Guérin, 13 janvier 2022 16:28

Télécharger (4,37 ko)

Voir les différences:

Subject: [PATCH] datasource: all agendas & agendas of a category (#58884)

 tests/test_datasource_chrono.py | 36 ++++++++++++++++++++++++++++++++-
 wcs/data_sources.py             | 21 +++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)
tests/test_datasource_chrono.py
54 54
        "id": "events-B",
55 55
        "kind": "events",
56 56
        "text": "Events B",
57
        "category": "category-b",
57 58
    },
58 59
]
59 60

  
......
64 65
        "id": "meetings-A",
65 66
        "kind": "meetings",
66 67
        "text": "Meetings A",
68
        "category": "category-a",
67 69
    },
68 70
    {
69 71
        "api": {
......
72 74
        "id": "virtual-B",
73 75
        "kind": "virtual",
74 76
        "text": "Virtual B",
77
        "category": "category-b",
75 78
    },
76 79
]
77 80

  
......
111 114
    NamedDataSource.wipe()
112 115

  
113 116
    urlopen.side_effect = lambda *args: io.StringIO('{"data": []}')
114
    assert collect_agenda_data(pub) == []
117
    assert collect_agenda_data(pub) == [
118
        {
119
            'slug': 'agenda-all',
120
            'text': 'All agendas',
121
            'url': 'http://chrono.example.net/api/agenda/',
122
        },
123
    ]
115 124
    assert urlopen.call_args_list == [mock.call('http://chrono.example.net/api/agenda/')]
116 125

  
117 126
    urlopen.side_effect = ConnectionError
......
123 132
    urlopen.side_effect = lambda *args: io.StringIO(json.dumps({"data": AGENDA_EVENTS_DATA}))
124 133
    urlopen.reset_mock()
125 134
    assert collect_agenda_data(pub) == [
135
        {
136
            'slug': 'agenda-all',
137
            'text': 'All agendas',
138
            'url': 'http://chrono.example.net/api/agenda/',
139
        },
140
        {
141
            'slug': 'agenda-category-category-b',
142
            'text': 'All agendas of category category-b',
143
            'url': 'http://chrono.example.net/api/agenda/?category=category-b',
144
        },
126 145
        {
127 146
            'slug': 'agenda-events-events-A',
128 147
            'text': 'Events A',
......
144 163
    ]
145 164
    urlopen.reset_mock()
146 165
    assert collect_agenda_data(pub) == [
166
        {
167
            'slug': 'agenda-all',
168
            'text': 'All agendas',
169
            'url': 'http://chrono.example.net/api/agenda/',
170
        },
171
        {
172
            'slug': 'agenda-category-category-a',
173
            'text': 'All agendas of category category-a',
174
            'url': 'http://chrono.example.net/api/agenda/?category=category-a',
175
        },
176
        {
177
            'slug': 'agenda-category-category-b',
178
            'text': 'All agendas of category category-b',
179
            'url': 'http://chrono.example.net/api/agenda/?category=category-b',
180
        },
147 181
        {
148 182
            'slug': 'agenda-meetings-meetings-A-meetingtypes',
149 183
            'text': 'Meetings A - Meeting types',
wcs/data_sources.py
887 887

  
888 888
    # build datasources from chrono
889 889
    agenda_data = []
890
    categories = set()
890 891
    for agenda in result.get('data') or []:
892
        if agenda.get('category'):
893
            categories.add(agenda['category'])
891 894
        if agenda['kind'] == 'events':
892 895
            agenda_data.append(
893 896
                {
......
917 920
                        'url': meetingtype['api']['datetimes_url'],
918 921
                    }
919 922
                )
923

  
924
    agenda_data = [
925
        {
926
            'slug': 'agenda-category-%s' % category,
927
            'text': _('All agendas of category %s' % category),
928
            'url': '%s?category=%s' % (agenda_url, category),
929
        }
930
        for category in sorted(categories)
931
    ] + agenda_data
932

  
933
    agenda_data = [
934
        {
935
            'slug': 'agenda-all',
936
            'text': _('All agendas'),
937
            'url': agenda_url,
938
        }
939
    ] + agenda_data
940

  
920 941
    return agenda_data
921 942

  
922 943

  
923
-