Repository: saleor/saleor

Issue:
Voucher type should return countries: [VoucherCountries!]!
### What I'm trying to achieve
To get list of countries to which voucher applies.

### Steps to reproduce the problem
1. Exec query
```language=graphql
{
  voucher {
    id
    countries
  }
}
```
2. Get an error: `Expected a value of type \"VoucherCountries\" but received: []`

### What I expected to happen
To properly return list of countries.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/discount/types.py b/saleor/graphql/discount/types.py
--- a/saleor/graphql/discount/types.py
+++ b/saleor/graphql/discount/types.py
@@ -1,11 +1,13 @@
 from textwrap import dedent
 
+import graphene
 import graphene_django_optimizer as gql_optimizer
 from graphene import relay
 
 from ...discount import models
 from ..core.connection import CountableDjangoObjectType
 from ..core.fields import PrefetchingConnectionField
+from ..core.types import CountryDisplay
 from ..product.types import Category, Collection, Product
 
 
@@ -59,6 +61,9 @@ class Voucher(CountableDjangoObjectType):
             Product,
             description='List of products this voucher applies to.'),
         model_field='products')
+    countries = graphene.List(
+        CountryDisplay,
+        description='List of countries available for the shipping voucher.')
 
     class Meta:
         description = dedent("""
@@ -76,3 +81,8 @@ def resolve_collections(self, info, **kwargs):
 
     def resolve_products(self, info, **kwargs):
         return self.products.visible_to_user(info.context.user)
+
+    def resolve_countries(self, info, **kwargs):
+        return [
+            CountryDisplay(code=country.code, country=country.name)
+            for country in self.countries]


Test patch:
diff --git a/tests/api/test_discount.py b/tests/api/test_discount.py
--- a/tests/api/test_discount.py
+++ b/tests/api/test_discount.py
@@ -1,5 +1,6 @@
 import graphene
 import pytest
+from django_countries import countries
 
 from saleor.discount import DiscountValueType, VoucherType
 from saleor.graphql.discount.enums import (
@@ -7,7 +8,15 @@
 from tests.api.utils import get_graphql_content
 
 
-def test_voucher_query(staff_api_client, voucher, permission_manage_discounts):
+@pytest.fixture
+def voucher_countries(voucher):
+    voucher.countries = countries
+    voucher.save(update_fields=['countries'])
+    return voucher
+
+
+def test_voucher_query(
+        staff_api_client, voucher_countries, permission_manage_discounts):
     query = """
     query vouchers {
         vouchers(first: 1) {
@@ -21,6 +30,10 @@ def test_voucher_query(staff_api_client, voucher, permission_manage_discounts):
                     startDate
                     discountValueType
                     discountValue
+                    countries {
+                        code
+                        country
+                    }
                 }
             }
         }
@@ -30,14 +43,19 @@ def test_voucher_query(staff_api_client, voucher, permission_manage_discounts):
         query, permissions=[permission_manage_discounts])
     content = get_graphql_content(response)
     data = content['data']['vouchers']['edges'][0]['node']
-    assert data['type'] == voucher.type.upper()
-    assert data['name'] == voucher.name
-    assert data['code'] == voucher.code
-    assert data['usageLimit'] == voucher.usage_limit
-    assert data['used'] == voucher.used
-    assert data['startDate'] == voucher.start_date.isoformat()
-    assert data['discountValueType'] == voucher.discount_value_type.upper()
-    assert data['discountValue'] == voucher.discount_value
+
+    assert data['type'] == voucher_countries.type.upper()
+    assert data['name'] == voucher_countries.name
+    assert data['code'] == voucher_countries.code
+    assert data['usageLimit'] == voucher_countries.usage_limit
+    assert data['used'] == voucher_countries.used
+    assert data['startDate'] == voucher_countries.start_date.isoformat()
+    assert data[
+        'discountValueType'] == voucher_countries.discount_value_type.upper()
+    assert data['discountValue'] == voucher_countries.discount_value
+    assert data['countries'] == [{
+        'country': country.name,
+        'code': country.code} for country in voucher_countries.countries]
 
 
 def test_sale_query(staff_api_client, sale, permission_manage_discounts):
@@ -257,8 +275,13 @@ def test_sale_delete_mutation(
         sale.refresh_from_db()
 
 
+@pytest.mark.parametrize('voucher_type,field_name', (
+    (VoucherTypeEnum.CATEGORY, 'categories'),
+    (VoucherTypeEnum.PRODUCT, 'products'),
+    (VoucherTypeEnum.COLLECTION, 'collections')))
 def test_validate_voucher(
-        voucher, staff_api_client, permission_manage_discounts):
+        voucher_type, field_name, voucher,
+        staff_api_client, permission_manage_discounts):
     query = """
     mutation  voucherUpdate(
         $id: ID!, $type: VoucherTypeEnum) {
@@ -271,19 +294,12 @@ def test_validate_voucher(
             }
         }
     """
-    # apparently can't do so via pytest parametrize
-    # as it parses VoucherTypeEnum into str format
-    fields = (
-        (VoucherTypeEnum.CATEGORY, 'categories'),
-        (VoucherTypeEnum.PRODUCT, 'products'),
-        (VoucherTypeEnum.COLLECTION, 'collections'))
     staff_api_client.user.user_permissions.add(permission_manage_discounts)
-    for voucher_type, field_name in fields:
-        variables = {
-            'type': voucher_type.name,
-            'id': graphene.Node.to_global_id('Voucher', voucher.id)}
-        response = staff_api_client.post_graphql(query, variables)
-        content = get_graphql_content(response)
-        data = content['data']['voucherUpdate']['errors'][0]
-        assert data['field'] == field_name
-        assert data['message'] == 'This field is required.'
+    response = staff_api_client.post_graphql(query, {
+        'type': voucher_type.name,
+        'id': graphene.Node.to_global_id('Voucher', voucher.id)})
+
+    content = get_graphql_content(response)
+    data = content['data']['voucherUpdate']['errors'][0]
+    assert data['field'] == field_name
+    assert data['message'] == 'This field is required.'