Completed
Pull Request — master (#1008)
by
unknown
30s
created

gen_context_data_inputs_expected()   B

Complexity

Conditions 1

Size

Total Lines 433

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 433
rs 8.2857
c 2
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
# -*- coding: utf-8 -*-
2
# flake8: noqa
3
"""
4
test_generate_convext_v2
5
------------------------
6
7
Tests associated with processing v2 context syntax in the
8
`cookiecutter.generate` module.
9
"""
10
11
from __future__ import unicode_literals
12
import pytest
13
14
from collections import OrderedDict
15
16
from cookiecutter import generate
17
18
19
def context_data():
20
    context = (
21
        {
22
            'context_file': 'tests/test-generate-context-v2/test.json'
23
        },
24
        {
25
            "test": OrderedDict([
26
                ("name", "cookiecutter-pytest-plugin"),
27
                ("cookiecutter_version", "2.0.0"),
28
                ("variables", [
29
                    OrderedDict([
30
                        ("name", "full_name"),
31
                        ("default", "J. Paul Getty"),
32
                        ("prompt", "What's your full name?"),
33
                        ("description", "Please enter your full name. It will be displayed on the README file and used for the PyPI package definition."),
34
                        ("type", "string")]),
35
                    OrderedDict([
36
                        ("name", "email"),
37
                        ("default", "[email protected]"),
38
                        ("prompt", "What's your email?"),
39
                        ("description", "Please enter an email address for the meta information in setup.py."),
40
                        ("type", "string")]),
41
                ])
42
            ])
43
        }
44
    )
45
46
    context_with_default = (
47
        {
48
            'context_file': 'tests/test-generate-context-v2/test.json',
49
            'default_context': {'full_name': 'James Patrick Morgan', 'this_key_ignored': 'not_in_context'}
50
        },
51
        {
52
            "test": OrderedDict([
53
                ("name", "cookiecutter-pytest-plugin"),
54
                ("cookiecutter_version", "2.0.0"),
55
                ("variables", [
56
                    OrderedDict([
57
                        ("name", "full_name"),
58
                        ("default", "James Patrick Morgan"),
59
                        ("prompt", "What's your full name?"),
60
                        ("description", "Please enter your full name. It will be displayed on the README file and used for the PyPI package definition."),
61
                        ("type", "string")]),
62
                    OrderedDict([
63
                        ("name", "email"),
64
                        ("default", "[email protected]"),
65
                        ("prompt", "What's your email?"),
66
                        ("description", "Please enter an email address for the meta information in setup.py."),
67
                        ("type", "string")]),
68
                ])
69
            ])
70
        }
71
    )
72
73
    context_with_extra = (
74
        {
75
            'context_file': 'tests/test-generate-context-v2/test.json',
76
            'extra_context': {'email': '[email protected]'}
77
        },
78
        {
79
            "test": OrderedDict([
80
                ("name", "cookiecutter-pytest-plugin"),
81
                ("cookiecutter_version", "2.0.0"),
82
                ("variables", [
83
                    OrderedDict([
84
                        ("name", "full_name"),
85
                        ("default", "J. Paul Getty"),
86
                        ("prompt", "What's your full name?"),
87
                        ("description", "Please enter your full name. It will be displayed on the README file and used for the PyPI package definition."),
88
                        ("type", "string")]),
89
                    OrderedDict([
90
                        ("name", "email"),
91
                        ("default", "[email protected]"),
92
                        ("prompt", "What's your email?"),
93
                        ("description", "Please enter an email address for the meta information in setup.py."),
94
                        ("type", "string")]),
95
                ])
96
            ])
97
        }
98
    )
99
100
    context_with_default_and_extra = (
101
        {
102
            'context_file': 'tests/test-generate-context-v2/test.json',
103
            'default_context': {'full_name': 'Alpha Gamma Five'},
104
            'extra_context': {'email': '[email protected]'}
105
        },
106
        {
107
            "test": OrderedDict([
108
                ("name", "cookiecutter-pytest-plugin"),
109
                ("cookiecutter_version", "2.0.0"),
110
                ("variables", [
111
                    OrderedDict([
112
                        ("name", "full_name"),
113
                        ("default", "Alpha Gamma Five"),
114
                        ("prompt", "What's your full name?"),
115
                        ("description", "Please enter your full name. It will be displayed on the README file and used for the PyPI package definition."),
116
                        ("type", "string")]),
117
                    OrderedDict([
118
                        ("name", "email"),
119
                        ("default", "[email protected]"),
120
                        ("prompt", "What's your email?"),
121
                        ("description", "Please enter an email address for the meta information in setup.py."),
122
                        ("type", "string")]),
123
                ])
124
            ])
125
        }
126
    )
127
128
    context_choices_with_default = (
129
        {
130
            'context_file': 'tests/test-generate-context-v2/test_choices.json',
131
            'default_context': {'license': 'Apache2'},
132
        },
133
        {
134
            "test_choices": OrderedDict([
135
                ("name", "cookiecutter-pytest-plugin"),
136
                ("cookiecutter_version", "2.0.0"),
137
                ("variables", [
138
                    OrderedDict([
139
                        ("name", "license"),
140
                        ("default", "Apache2"),
141
                        ("choices", ["Apache2", "MIT", "BSD3", "GNU-GPL3", "Mozilla2"]),
142
                    ])]
143
                 )
144
            ])
145
        }
146
    )
147
148
    context_choices_with_default_not_in_choices = (
149
        {
150
            'context_file': 'tests/test-generate-context-v2/test.json',
151
            'default_context': {'orientation': 'landscape'},
152
        },
153
        {
154
            "test": OrderedDict([
155
                ("name", "cookiecutter-pytest-plugin"),
156
                ("cookiecutter_version", "2.0.0"),
157
                ("variables", [
158
                    OrderedDict([
159
                        ("name", "full_name"),
160
                        ("default", "J. Paul Getty"),
161
                        ("prompt", "What's your full name?"),
162
                        ("description", "Please enter your full name. It will be displayed on the README file and used for the PyPI package definition."),
163
                        ("type", "string")]),
164
                    OrderedDict([
165
                        ("name", "email"),
166
                        ("default", "[email protected]"),
167
                        ("prompt", "What's your email?"),
168
                        ("description", "Please enter an email address for the meta information in setup.py."),
169
                        ("type", "string")]),
170
                ])
171
            ])
172
        }
173
    )
174
    yield context
175
    yield context_with_default
176
    yield context_with_extra
177
    yield context_with_default_and_extra
178
    yield context_choices_with_default
179
    yield context_choices_with_default_not_in_choices
180
181
182
@pytest.mark.usefixtures('clean_system')
183
@pytest.mark.parametrize('input_params, expected_context', context_data())
184
def test_generate_context(input_params, expected_context):
185
    """
186
    Test the generated context for several input parameters against the
187
    according expected context.
188
    """
189
    assert generate.generate_context(**input_params) == expected_context
190
191
192
@pytest.mark.usefixtures('clean_system')
193
def test_generate_context_extra_ctx_invalid():
194
    """
195
    Test error condition when extra context is not a dictionary or a list
196
    of dictionaries.
197
    """
198
199
    with pytest.raises(ValueError) as excinfo:
200
        generate.generate_context(
201
            context_file='tests/test-generate-context-v2/test.json',
202
            default_context=None,
203
            extra_context='should_be_a_list_or_a_dictionary')
204
205
    msg = "Extra context must be a dictionary or a list of dictionaries!"
206
    assert msg in str(excinfo.value)
207
208
209
@pytest.mark.usefixtures('clean_system')
210
def test_generate_context_extra_ctx_list_item_not_dict():
211
    """
212
    Test error condition when extra context is a list, but not a list that
213
    contains a dictionary.
214
    """
215
    xtra_context = [
216
        'a_string', 'here_too'
217
    ]
218
    with pytest.raises(ValueError) as excinfo:
219
        generate.generate_context(
220
            context_file='tests/test-generate-context-v2/test.json',
221
            default_context=None,
222
            extra_context=xtra_context)
223
224
    msg = "Extra context list item 'a_string' is of type str, should be a dictionary."
225
    assert msg in str(excinfo.value)
226
227
228
@pytest.mark.usefixtures('clean_system')
229
def test_generate_context_extra_ctx_list_item_dict_missing_name_field():
230
    """
231
    Test error condition when extra context is a list, but not a list that
232
    contains a dictionary.
233
    """
234
    xtra_context = [
235
        {
236
            "shouldbename": "author_name",
237
            "default": "Robert Lewis",
238
            "prompt": "What's the author's name?",
239
            "description": "Please enter the author's full name.",
240
            "type": "string"
241
        }
242
    ]
243
    with pytest.raises(ValueError) as excinfo:
244
        generate.generate_context(
245
            context_file='tests/test-generate-context-v2/test.json',
246
            default_context=None,
247
            extra_context=xtra_context)
248
249
    msg = "is missing a 'name' key."
250
    assert msg in str(excinfo.value)
251
252
253
@pytest.mark.usefixtures('clean_system')
254
def test_generate_context_extra_ctx_list_item_dict_no_name_field_match():
255
    """
256
    Test error condition when extra context is a list, but not a list that
257
    contains a dictionary.
258
    """
259
    xtra_context = [
260
        {
261
            "name": "author_name",
262
            "default": "Robert Lewis",
263
            "prompt": "What's the author's name?",
264
            "description": "Please enter the author's full name.",
265
            "type": "string"
266
        }
267
    ]
268
    with pytest.raises(ValueError) as excinfo:
269
        generate.generate_context(
270
            context_file='tests/test-generate-context-v2/test.json',
271
            default_context=None,
272
            extra_context=xtra_context)
273
274
    msg = "No variable found in context whose name matches extra context name 'author_name'"
275
    assert msg in str(excinfo.value)
276
277
278
def gen_context_data_inputs_expected():
279
    # Extra field ignored
280
    context_with_valid_extra_0 = (
281
        {
282
            'context_file': 'tests/test-generate-context-v2/test.json',
283
            'extra_context': [
284
                {
285
                    'name': 'email',
286
                    'default': '[email protected]',
287
                    'description': 'Enter jazzy email...',
288
                    'extra_field': 'extra_field_value',
289
                }
290
            ]
291
        },
292
        {
293
            "test": OrderedDict([
294
                ("name", "cookiecutter-pytest-plugin"),
295
                ("cookiecutter_version", "2.0.0"),
296
                ("variables", [
297
                    OrderedDict([
298
                        ("name", "full_name"),
299
                        ("default", "J. Paul Getty"),
300
                        ("prompt", "What's your full name?"),
301
                        ("description", "Please enter your full name. It will be displayed on the README file and used for the PyPI package definition."),
302
                        ("type", "string")]),
303
                    OrderedDict([
304
                        ("name", "email"),
305
                        ("default", "[email protected]"),
306
                        ("prompt", "What's your email?"),
307
                        ("description", "Enter jazzy email..."),
308
                        ("type", "string")]),
309
                ])
310
            ])
311
        }
312
    )
313
    # Empty extra context precipitates no ill effect
314
    context_with_valid_extra_1 = (
315
        {
316
            'context_file': 'tests/test-generate-context-v2/representative.json',
317
            'extra_context': []
318
            # 'extra_context': [
319
            #     {
320
            #         'name': 'email',
321
            #         'default': '[email protected]',
322
            #         'description': 'Enter jazzy email...',
323
            #         'extra_field': 'extra_field_value',
324
            #     }
325
            # ]
326
        },
327
        {
328
            "representative": OrderedDict([
329
                ("name", "cc-representative"),
330
                ("cookiecutter_version", "2.0.0"),
331
                ("variables", [
332
                    OrderedDict([
333
                        ("name", "director_credit"),
334
                        ("default", True),
335
                        ("prompt", "Is there a director credit on this film?"),
336
                        ("description", "Directors take credit for most of their films, usually..."),
337
                        ("type", "boolean")
338
                    ]),
339
                    OrderedDict([
340
                        ("name", "director_name"),
341
                        ("default", "Allan Smithe"),
342
                        ("prompt", "What's the Director's full name?"),
343
                        ("prompt_user", True),
344
                        ("description", "The default director is not proud of their work, we hope you are."),
345
                        ("hide_input", False),
346
                        ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]),
347
                        ("validation", "^[a-z][A-Z]+$"),
348
                        ("validation_flags", ["verbose", "ascii"]),
349
                        ("skip_if", "{{cookiecutter.director_credit == False}}"),
350
                        ("type", "string")
351
                    ])
352
                ])
353
            ])
354
        }
355
    )
356
357
    # Test the ability to change the variable's name field (since it is used
358
    # to identify the variable to be modifed) with extra context and to remove
359
    # a key from the context via the removal token: '<<ACTION::REMOVE>>'
360
    context_with_valid_extra_2 = (
361
        {
362
            'context_file': 'tests/test-generate-context-v2/representative.json',
363
            'extra_context': [
364
                {
365
                    'name': 'director_credit::producer_credit',
366
                    'prompt': 'Is there a producer credit on this film?',
367
                    'description': 'There are usually a lot of producers...',
368
                },
369
                {
370
                    'name': 'director_name',
371
                    'skip_if': '<<REMOVE::FIELD>>',
372
                },
373
374
            ]
375
        },
376
        {
377
            "representative": OrderedDict([
378
                ("name", "cc-representative"),
379
                ("cookiecutter_version", "2.0.0"),
380
                ("variables", [
381
                    OrderedDict([
382
                        ("name", "producer_credit"),
383
                        ("default", True),
384
                        ("prompt", "Is there a producer credit on this film?"),
385
                        ("description", "There are usually a lot of producers..."),
386
                        ("type", "boolean")
387
                    ]),
388
                    OrderedDict([
389
                        ("name", "director_name"),
390
                        ("default", "Allan Smithe"),
391
                        ("prompt", "What's the Director's full name?"),
392
                        ("prompt_user", True),
393
                        ("description", "The default director is not proud of their work, we hope you are."),
394
                        ("hide_input", False),
395
                        ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]),
396
                        ("validation", "^[a-z][A-Z]+$"),
397
                        ("validation_flags", ["verbose", "ascii"]),
398
                        ("type", "string")
399
                    ])
400
                ])
401
            ])
402
        }
403
    )
404
    # Test the ability to change the variable's name field (since it is used
405
    # to identify the variable to be modifed) with extra context and to also
406
    # test that any other references in other variables that might use the
407
    # original variable name get updated as well.
408
    context_with_valid_extra_2_B = (
409
        {
410
            'context_file': 'tests/test-generate-context-v2/representative_2B.json',
411
            'extra_context': [
412
                {
413
                    'name': 'director_credit::producer_credit',
414
                    'prompt': 'Is there a producer credit on this film?',
415
                    'description': 'There are usually a lot of producers...',
416
                },
417
            ]
418
        },
419
        {
420
            "representative_2B": OrderedDict([
421
                ("name", "cc-representative"),
422
                ("cookiecutter_version", "2.0.0"),
423
                ("variables", [
424
                    OrderedDict([
425
                        ("name", "producer_credit"),
426
                        ("default", True),
427
                        ("prompt", "Is there a producer credit on this film?"),
428
                        ("description", "There are usually a lot of producers..."),
429
                        ("type", "boolean")
430
                    ]),
431
                    OrderedDict([
432
                        ("name", "director_name"),
433
                        ("default", "Allan Smithe"),
434
                        ("prompt", "What's the Director's full name?"),
435
                        ("prompt_user", True),
436
                        ("description", "The default director is not proud of their work, we hope you are."),
437
                        ("hide_input", False),
438
                        ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston", "{{cookiecutter.producer_credit}}"]),
439
                        ("validation", "^[a-z][A-Z]+$"),
440
                        ("validation_flags", ["verbose", "ascii"]),
441
                        ("skip_if", "{{cookiecutter.producer_credit == False}}"),
442
                        ("type", "string")
443
                    ])
444
                ])
445
            ])
446
        }
447
    )
448
449
    # Test changing variable's name field value, default field, prompt field,
450
    # and changing the type
451
    context_with_valid_extra_3 = (
452
        {
453
            'context_file': 'tests/test-generate-context-v2/representative.json',
454
            'extra_context': [
455
                {
456
                    'name': 'director_credit::producer_credits',
457
                    'default': 2,
458
                    'prompt': 'How many producers does this film have?',
459
                    'description': 'There are usually a lot of producers...',
460
                    'type': "int",
461
                }
462
            ]
463
        },
464
        {
465
            "representative": OrderedDict([
466
                ("name", "cc-representative"),
467
                ("cookiecutter_version", "2.0.0"),
468
                ("variables", [
469
                    OrderedDict([
470
                        ("name", "producer_credits"),
471
                        ("default", 2),
472
                        ("prompt", "How many producers does this film have?"),
473
                        ("description", "There are usually a lot of producers..."),
474
                        ("type", "int")
475
                    ]),
476
                    OrderedDict([
477
                        ("name", "director_name"),
478
                        ("default", "Allan Smithe"),
479
                        ("prompt", "What's the Director's full name?"),
480
                        ("prompt_user", True),
481
                        ("description", "The default director is not proud of their work, we hope you are."),
482
                        ("hide_input", False),
483
                        ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]),
484
                        ("validation", "^[a-z][A-Z]+$"),
485
                        ("validation_flags", ["verbose", "ascii"]),
486
                        ("skip_if", "{{cookiecutter.producer_credits == False}}"),
487
                        ("type", "string")
488
                    ])
489
                ])
490
            ])
491
        }
492
    )
493
    # Test changing choices field without changing the default, but default
494
    # does not change because the first position in choices matches default
495
    context_with_valid_extra_4 = (
496
        {
497
            'context_file': 'tests/test-generate-context-v2/representative.json',
498
            'extra_context': [
499
                {
500
                    'name': 'director_name',
501
                    'choices': ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston',
502
                                'John Ford', 'Billy Wilder'],
503
                }
504
            ]
505
        },
506
        {
507
            "representative": OrderedDict([
508
                ("name", "cc-representative"),
509
                ("cookiecutter_version", "2.0.0"),
510
                ("variables", [
511
                    OrderedDict([
512
                        ("name", "director_credit"),
513
                        ("default", True),
514
                        ("prompt", "Is there a director credit on this film?"),
515
                        ("description", "Directors take credit for most of their films, usually..."),
516
                        ("type", "boolean")
517
                    ]),
518
                    OrderedDict([
519
                        ("name", "director_name"),
520
                        ("default", "Allan Smithe"),
521
                        ("prompt", "What's the Director's full name?"),
522
                        ("prompt_user", True),
523
                        ("description", "The default director is not proud of their work, we hope you are."),
524
                        ("hide_input", False),
525
                        ("choices", ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'John Ford', 'Billy Wilder']),
526
                        ("validation", "^[a-z][A-Z]+$"),
527
                        ("validation_flags", ["verbose", "ascii"]),
528
                        ("skip_if", "{{cookiecutter.director_credit == False}}"),
529
                        ("type", "string")
530
                    ])
531
                ])
532
            ])
533
        }
534
    )
535
    # Test changing choices field and changing the default
536
    context_with_valid_extra_5 = (
537
        {
538
            'context_file': 'tests/test-generate-context-v2/representative.json',
539
            'extra_context': [
540
                {
541
                    'name': 'director_name',
542
                    'default': 'John Ford',
543
                    'choices': ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston',
544
                                'John Ford', 'Billy Wilder'],
545
                }
546
            ]
547
        },
548
        {
549
            "representative": OrderedDict([
550
                ("name", "cc-representative"),
551
                ("cookiecutter_version", "2.0.0"),
552
                ("variables", [
553
                    OrderedDict([
554
                        ("name", "director_credit"),
555
                        ("default", True),
556
                        ("prompt", "Is there a director credit on this film?"),
557
                        ("description", "Directors take credit for most of their films, usually..."),
558
                        ("type", "boolean")
559
                    ]),
560
                    OrderedDict([
561
                        ("name", "director_name"),
562
                        ("default", "John Ford"),
563
                        ("prompt", "What's the Director's full name?"),
564
                        ("prompt_user", True),
565
                        ("description", "The default director is not proud of their work, we hope you are."),
566
                        ("hide_input", False),
567
                        ("choices", ['John Ford', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'Billy Wilder']),
568
                        ("validation", "^[a-z][A-Z]+$"),
569
                        ("validation_flags", ["verbose", "ascii"]),
570
                        ("skip_if", "{{cookiecutter.director_credit == False}}"),
571
                        ("type", "string")
572
                    ])
573
                ])
574
            ])
575
        }
576
    )
577
    # Test changing the default, but not the choices field, yet seeing choices field re-ordered
578
    # to put default value in first location
579
    context_with_valid_extra_6 = (
580
        {
581
            'context_file': 'tests/test-generate-context-v2/representative.json',
582
            'extra_context': [
583
                {
584
                    'name': 'director_name',
585
                    'default': 'John Ford',
586
                }
587
            ]
588
        },
589
        {
590
            "representative": OrderedDict([
591
                ("name", "cc-representative"),
592
                ("cookiecutter_version", "2.0.0"),
593
                ("variables", [
594
                    OrderedDict([
595
                        ("name", "director_credit"),
596
                        ("default", True),
597
                        ("prompt", "Is there a director credit on this film?"),
598
                        ("description", "Directors take credit for most of their films, usually..."),
599
                        ("type", "boolean")
600
                    ]),
601
                    OrderedDict([
602
                        ("name", "director_name"),
603
                        ("default", "John Ford"),
604
                        ("prompt", "What's the Director's full name?"),
605
                        ("prompt_user", True),
606
                        ("description", "The default director is not proud of their work, we hope you are."),
607
                        ("hide_input", False),
608
                        ("choices", ['John Ford', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston']),
609
                        ("validation", "^[a-z][A-Z]+$"),
610
                        ("validation_flags", ["verbose", "ascii"]),
611
                        ("skip_if", "{{cookiecutter.director_credit == False}}"),
612
                        ("type", "string")
613
                    ])
614
                ])
615
            ])
616
        }
617
    )
618
    # Test changing choices field without changing the default, but default
619
    # does get changee because the first position in choices field chagned
620
    context_with_valid_extra_7 = (
621
        {
622
            'context_file': 'tests/test-generate-context-v2/representative.json',
623
            'extra_context': [
624
                {
625
                    'name': 'director_name',
626
                    'choices': ['Billy Wilder', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston',
627
                                'John Ford'],
628
                }
629
            ]
630
        },
631
        {
632
            "representative": OrderedDict([
633
                ("name", "cc-representative"),
634
                ("cookiecutter_version", "2.0.0"),
635
                ("variables", [
636
                    OrderedDict([
637
                        ("name", "director_credit"),
638
                        ("default", True),
639
                        ("prompt", "Is there a director credit on this film?"),
640
                        ("description", "Directors take credit for most of their films, usually..."),
641
                        ("type", "boolean")
642
                    ]),
643
                    OrderedDict([
644
                        ("name", "director_name"),
645
                        ("default", "Billy Wilder"),
646
                        ("prompt", "What's the Director's full name?"),
647
                        ("prompt_user", True),
648
                        ("description", "The default director is not proud of their work, we hope you are."),
649
                        ("hide_input", False),
650
                        ("choices", ['Billy Wilder', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'John Ford']),
651
                        ("validation", "^[a-z][A-Z]+$"),
652
                        ("validation_flags", ["verbose", "ascii"]),
653
                        ("skip_if", "{{cookiecutter.director_credit == False}}"),
654
                        ("type", "string")
655
                    ])
656
                ])
657
            ])
658
        }
659
    )
660
    # Test changing the default value with a value that is not in choices,
661
    # we should see the choice first position get updated.
662
    context_with_valid_extra_8 = (
663
        {
664
            'context_file': 'tests/test-generate-context-v2/representative.json',
665
            'extra_context': [
666
                {
667
                    'name': 'director_name',
668
                    'default': 'Peter Sellers',
669
                }
670
            ]
671
        },
672
        {
673
            "representative": OrderedDict([
674
                ("name", "cc-representative"),
675
                ("cookiecutter_version", "2.0.0"),
676
                ("variables", [
677
                    OrderedDict([
678
                        ("name", "director_credit"),
679
                        ("default", True),
680
                        ("prompt", "Is there a director credit on this film?"),
681
                        ("description", "Directors take credit for most of their films, usually..."),
682
                        ("type", "boolean")
683
                    ]),
684
                    OrderedDict([
685
                        ("name", "director_name"),
686
                        ("default", "Peter Sellers"),
687
                        ("prompt", "What's the Director's full name?"),
688
                        ("prompt_user", True),
689
                        ("description", "The default director is not proud of their work, we hope you are."),
690
                        ("hide_input", False),
691
                        ("choices", ["Peter Sellers", "Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]),
692
                        ("validation", "^[a-z][A-Z]+$"),
693
                        ("validation_flags", ["verbose", "ascii"]),
694
                        ("skip_if", "{{cookiecutter.director_credit == False}}"),
695
                        ("type", "string")
696
                    ])
697
                ])
698
            ])
699
        }
700
    )
701
    yield context_with_valid_extra_0
702
    yield context_with_valid_extra_1
703
    yield context_with_valid_extra_2
704
    yield context_with_valid_extra_2_B
705
    yield context_with_valid_extra_3
706
    yield context_with_valid_extra_4
707
    yield context_with_valid_extra_5
708
    yield context_with_valid_extra_6
709
    yield context_with_valid_extra_7
710
    yield context_with_valid_extra_8
711
712
713
@pytest.mark.usefixtures('clean_system')
714
@pytest.mark.parametrize('input_params, expected_context',
715
                         gen_context_data_inputs_expected())
716
def test_generate_context_with_extra_context_dictionary(
717
        input_params, expected_context, monkeypatch):
718
    """
719
    Test the generated context with extra content overwrite to multiple fields,
720
    with creation of new fields NOT allowed.
721
    """
722
    assert generate.generate_context(**input_params) == expected_context
723