Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

ENT-201 use catalog contains endpoint for varifying the course seats against …#1195

Merged
zubair-arbi merged 1 commit intomasterfrom
zub/ENT-201-use-catalog-contains-endpoint-for-entitlements
Mar 15, 2017
Merged

ENT-201 use catalog contains endpoint for varifying the course seats against …#1195
zubair-arbi merged 1 commit intomasterfrom
zub/ENT-201-use-catalog-contains-endpoint-for-entitlements

Conversation

@zubair-arbi
Copy link
Contributor

…a course catalog range
@saleem-latif @asadiqbal08 @mattdrayer

Previously we were using two API calls for checking if a course run exists for a catalog by first retrieving the catalog and then using the course_runs contains endpoint for the provided course run, from discovery service.

Now we are using the updated catalog contains endpoint which tells us if a course run is available in its query.

Depends on: add support for course run key in catalog contains endpoint

Copy link
Contributor

@saleem-latif saleem-latif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, however, I have added a couple of comments.


return response

def catalog_contains_product(self, product):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best to define a helper method in ecommerce/coupons/utils.py that makes network calls to discovery API, and use that method here. This way will have all procedures that perform API calls in a single place.
Name of the utility function can be something like catalog_contains_course(self, course) or something better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, in my opinion I think it would be more readable if catalog_contains_product here returns a boolean if it is possible. and we changes function signature accordingly. thoughts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saleem-latif @mattdrayer I would recommend a separate story for refactoring/moving the range model API calls to the ecommerce/coupons/utils.py file as we have to update both this method and run_catalog_query method. Also we have to add separate tests for the utils too. The scope of current story already seems a bit extended and its involves working with 3 repos.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with logging (another) follow-up story -- we've put in a fair amount of effort on this job and we have some higher priorities that we'll need to address next.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have logged a ticket ENT-257 to address this feedback.

request = get_current_request()
partner_code = request.site.siteconfiguration.partner.short_code
cache_key = get_cache_key(
site_domain=request.site.domain,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to also add resource key-value pair in cache key to make sure cache key does not collide with any other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

if not response:
course_catalog_api_client = request.site.siteconfiguration.course_catalog_api_client
try:
response = course_catalog_api_client.catalogs(self.course_catalog).contains.get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please add a comment here explaining what would be the final URL for the API call, may be something like

# GET: /api/v1/catalogs/{catalog_id}/contains?course_run_ids={course_run_id}

@zubair-arbi zubair-arbi force-pushed the zub/ENT-201-use-catalog-contains-endpoint-for-entitlements branch from a9834c8 to 3876483 Compare March 9, 2017 10:48
@zubair-arbi
Copy link
Contributor Author

@mattdrayer @mjfrey please review.

except KeyError:
return False

return is_course_in_course_runs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this can be moved to the try block:

try: 
    return response['courses'][course_id]
except KeyError:
    return False

@mattdrayer
Copy link
Contributor

One change, otherwise 👍

@saleem-latif
Copy link
Contributor

@zubair-arbi commits need to be squashed otherwise LGTM 👍

@mattdrayer
Copy link
Contributor

@vkaracic and/or @marjev may want to take a quick look at this one.

Helper function to register course catalog contains API endpoint.
"""
courses = {}
course_run_ids = course_run_ids or []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you set [] as the default value in line 42? That way you won't need this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marjev This would result in pylint error "dangerous-default-value":

pep8 --config=.pep8 ecommerce e2e
pylint --rcfile=pylintrc ecommerce e2e
************* Module ecommerce.courses.tests.mixins
W: 42, 4: Dangerous default value [] as argument (dangerous-default-value)

courses = {}
course_run_ids = course_run_ids or []
for course_run_id in course_run_ids:
courses.update({course_run_id: True})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this during the initialization like this:
courses = {course_run_id: True for course_run_id in course_run_ids}

courses.update({course_run_id: True})

course_discovery_api_response = {
u'courses': courses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can import unicode_literals like this: https://github.com/edx/ecommerce/blob/master/ecommerce/coupons/views.py#L1

Then, you won't need to mark the string as Unicode.

@zubair-arbi
Copy link
Contributor Author

@marjev I have addressed your feedback, please have another look.

Copy link
Contributor

@marjev marjev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zubair-arbi zubair-arbi force-pushed the zub/ENT-201-use-catalog-contains-endpoint-for-entitlements branch from 72dd361 to 4742b07 Compare March 13, 2017 11:35
Copy link
Contributor

@clintonb clintonb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this feature relies on the Catalog Service, please add a feature flag to disable it until the Catalog Service is released.

@zubair-arbi
Copy link
Contributor Author

@clintonb we already have a waffle switch enable_enterprise_on_runtime which enables enterprise functionality in Ecom and we can use this feature flag instead of adding a new one.
@mattdrayer what is your suggestion?

@zubair-arbi zubair-arbi force-pushed the zub/ENT-201-use-catalog-contains-endpoint-for-entitlements branch from 4742b07 to 45b6c1f Compare March 14, 2017 10:42
@mattdrayer
Copy link
Contributor

We're sort of in moot-point territory now because the updated Catalog service has already deployed. However, for this particular PR, I think I would have recommended that we avoid binding the catalog query logic to the enterprise feature flag. That flag is for enterprise features, and while they might use the updated query logic, the actual code was more of a core ecommerce change. So a new feature flag probably should have been introduced if we were expecting to merge both PRs to their respective masters and subsequently manage the releases.

TBH I much prefer simply merging+deploying the updated Catalog service, ensuring no rollback was required, and then merging+deploying the updated Ecommerce service at a later point in time (which is what we're doing now). It's easier to manage and we don't have to worry about juggling feature flags.

@clintonb clintonb dismissed their stale review March 14, 2017 13:35

Feature flag no longer matters.

@zubair-arbi zubair-arbi merged commit 07fc2d6 into master Mar 15, 2017
@zubair-arbi zubair-arbi deleted the zub/ENT-201-use-catalog-contains-endpoint-for-entitlements branch March 15, 2017 07:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants