Skip to content

Commit

Permalink
refactor(json_export): make get_chips() take course as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Jun 25, 2021
1 parent a92b8f6 commit 5d1fba0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_options_challenge(phrase, _):
}]


def get_chips(phrase):
def get_chips(phrase, course):
return list(map(clean_word, phrase.split()))


Expand Down Expand Up @@ -88,8 +88,8 @@ def get_chips_challenge(phrase, course):
"type": "chips",
"translatesToSourceLanguage": reverse,
"phrase": _define_words_in_sentence(course, get_phrase_text(phrase), reverse),
"chips": get_chips(get_input_text(phrase)),
"solutions": [get_chips(x) for x in get_input_texts(phrase)],
"chips": get_chips(get_input_text(phrase), course),
"solutions": [get_chips(x, course) for x in get_input_texts(phrase)],
"formattedSolution": get_input_text(phrase),
"id": get_dumb_opaque_id("Chips", phrase, "reverse chips" if reverse else "chips"),
"priority": 2,
Expand Down
12 changes: 6 additions & 6 deletions apps/librelingo_json_export/tests/test_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,28 +264,28 @@ def test_returns_correct_value2(self, get_chips):
@patch('librelingo_json_export.challenge_types.get_chips')
def test_calls_get_chips_with_correct_value(self, get_chips):
get_chips_challenge(fakes.phrase1, fakes.course1)
get_chips.assert_called_with(fakes.phrase1.in_target_language[0])
get_chips.assert_called_with(fakes.phrase1.in_target_language[0], fakes.course1)


class GetChipsTest(TestCase):
def test_empty_string(self):
assert get_chips('') == []
assert get_chips('', fakes.course1) == []

@patch('librelingo_json_export.challenge_types.clean_word')
def test_empty_string_doesnt_call_clean_word(self, clean_word):
get_chips('')
get_chips('', fakes.course1)
assert not clean_word.called

@patch('librelingo_json_export.challenge_types.clean_word')
def test_calls_clean_word_with_correct_argument(self, clean_word):
get_chips('foo')
get_chips('foo', fakes.course2)
clean_word.assert_called_with('foo')

@patch('librelingo_json_export.challenge_types.clean_word')
def test_returns_correct_value(self, clean_word):
clean_word.return_value = fakes.fake_value()
assert get_chips('foo') == [clean_word.return_value]
assert get_chips('foo', fakes.course1) == [clean_word.return_value]

@patch('librelingo_json_export.challenge_types.clean_word')
def test_returns_correct_number_of_words(self, clean_word):
assert len(get_chips('foo bar')) == 2
assert len(get_chips('foo bar', fakes.course1)) == 2

0 comments on commit 5d1fba0

Please sign in to comment.