Skip to content

Commit

Permalink
test(validation): test the validation and normalization of the USStat…
Browse files Browse the repository at this point in the history
…eField for a non US country
  • Loading branch information
soehlert committed Oct 25, 2023
1 parent a4d66bb commit e3022a5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
17 changes: 12 additions & 5 deletions concerts/tests/features/api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Feature: API Endpoints
When I request the <entity> list
Then I should receive a list of entities

Examples:
| entity |
| artist |
| venue |
| concert |
Examples:
| entity |
| artist |
| venue |
| concert |

@api
Scenario: Retrieve a user's concert reviews list
Expand All @@ -26,6 +26,13 @@ Feature: API Endpoints
When Alice requests the list of concert reviews for Sam
Then the response should contain an empty list of reviews

Scenario: Create international venue through API
Given I have a registered user Bob
And I am a token authenticated user Bob
When I create a new venue with {"name": "International Venue", "city": "Paris", "country": "FR"}
Then the response status code should be 201
And the state of the created venue should be None

@api
Scenario: Update a user's own concert review
Given I have a registered user Sam
Expand Down
11 changes: 10 additions & 1 deletion concerts/tests/features/steps/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from behave import given, then
from behave import given, step, then
from django.contrib.auth import get_user_model
from django.urls import reverse
from rest_framework.authtoken.models import Token
Expand Down Expand Up @@ -82,6 +82,15 @@ def step_impl(context, status_code):
), f"Expected {status_code} but got {context.response.status_code}"


@step("the state of the created venue should be None")
def step_impl(context):
# Get the latest venue created
venue = Venue.objects.order_by("-created_at").first()

# Check if the state is None
assert venue.state is None, f"Expected venue.state to be None, but got {venue.state}"


def after_scenario(context, _):
User = get_user_model()
User.objects.exclude(username="testuser").delete()
Expand Down
7 changes: 7 additions & 0 deletions concerts/tests/features/steps/webviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ def step_impl(context, entity_type, invalid_data):
@then("I should see form errors in the response")
def step_impl(context):
assert "This field is required." in context.response.content.decode(), "Expected form errors, but none were found."


@when("I create an international venue with valid data")
def step_impl(context):
data = {"name": "Test International Venue", "city": "Test City", "country": "FR"}
url = reverse("concerts:venue-create")
context.response = context.client.post(url, data=data)
56 changes: 32 additions & 24 deletions concerts/tests/features/webviews.feature
Original file line number Diff line number Diff line change
@@ -1,70 +1,78 @@
Feature: List Views

Scenario Outline: Authenticated user can view a list of entities
Scenario Outline: Authenticated user can view a list of entities
Given I have a registered user "testuser"
And "testuser" is logged in
And there is a <entity_type> in the system
When I request the list of <entity_type>
Then the response status code should be 200

Examples:
| entity_type |
| concert |
| artist |
| venue |
| entity_type |
| concert |
| artist |
| venue |

Scenario Outline: Authenticated user can create entities
Scenario Outline: Authenticated user can create entities
Given I have a registered user "testuser"
And "testuser" is logged in
When I make a new <entity_type> with valid data
Then the response status code should be 302

Examples:
| entity_type |
| concert |
| artist |
| venue |
| review |
| entity_type |
| concert |
| artist |
| venue |
| review |

Scenario Outline: Authenticated user can view details of entities
Scenario: Authenticated user can create an international venue
Given I have a registered user "testuser"
And "testuser" is logged in
When I create an international venue with valid data
Then the response status code should be 302
And the state of the created venue should be None


Scenario Outline: Authenticated user can view details of entities
Given I have a registered user "testuser"
And "testuser" is logged in
And there is a <entity_type> in the system
When I request details for that <entity_type>
Then the response status code should be 200

Examples:
| entity_type |
| concert |
| artist |
| venue |
| review |
| entity_type |
| concert |
| artist |
| venue |
| review |

Scenario: Authenticated user can attend a concert
Scenario: Authenticated user can attend a concert
Given I have a registered user "testuser"
And "testuser" is logged in
And there is a concert in the system
When I attend the concert
Then the response status code should be 302

Scenario: Authenticated user can unattend a concert
Scenario: Authenticated user can unattend a concert
Given I have a registered user "testuser"
And "testuser" is logged in
And there is a concert in the system
And I have attended the concert
When I unattend the concert
Then the response status code should be 302

Scenario Outline: Authenticated user cannot create entities with invalid data
Scenario Outline: Authenticated user cannot create entities with invalid data
Given I have a registered user "testuser"
And "testuser" is logged in
When I attempt to make a new <entity_type> with data <invalid_data>
Then the response status code should be 200
Then I should see form errors in the response

Examples:
| entity_type | invalid_data |
| concert | { "artist": "", "venue": "" } |
| artist | { "name": "" } |
| venue | { "name": "", "city": "", "state": "", "country": ""}|
| entity_type | invalid_data |
| concert | { "artist": "", "venue": "" } |
| artist | { "name": "" } |
| venue | { "name": "", "city": "", "state": "", "country": ""} |

0 comments on commit e3022a5

Please sign in to comment.