Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert sws notice 404 to empty list #3171

Merged
merged 11 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG DJANGO_CONTAINER_VERSION=2.0.3
FROM us-docker.pkg.dev/uwit-mci-axdd/containers/django-container:${DJANGO_CONTAINER_VERSION} as app-prewebpack-container
ARG DJANGO_CONTAINER_VERSION=2.0.5
FROM us-docker.pkg.dev/uwit-mci-axdd/containers/django-container:${DJANGO_CONTAINER_VERSION} AS app-prewebpack-container

USER root
RUN apt-get update && apt-get install -y postgresql-client libpq-dev
Expand Down Expand Up @@ -29,12 +29,12 @@ ARG VUE_DEVTOOLS
ENV VUE_DEVTOOLS=$VUE_DEVTOOLS
RUN npx webpack --mode=production

FROM app-prewebpack-container as app-container
FROM app-prewebpack-container AS app-container

COPY --chown=acait:acait --from=node-bundler /app/myuw/static /app/myuw/static
RUN /app/bin/python manage.py collectstatic --noinput

FROM us-docker.pkg.dev/uwit-mci-axdd/containers/django-test-container:${DJANGO_CONTAINER_VERSION} as app-test-container
FROM us-docker.pkg.dev/uwit-mci-axdd/containers/django-test-container:${DJANGO_CONTAINER_VERSION} AS app-test-container

ENV NODE_PATH=/app/lib/node_modules
COPY --from=app-container /app/ /app/
Expand Down
14 changes: 8 additions & 6 deletions myuw/dao/notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import logging
from django.db import IntegrityError
from restclients_core.exceptions import DataFailureException
from uw_sws.notice import get_notices_by_regid
from myuw.models import UserNotices
from myuw.dao.category_notice import get_category_notices
Expand All @@ -28,13 +29,14 @@ def _get_notices_by_regid(user_regid):
returns SWS notices for a given regid with
myuw specific categories
"""

if user_regid is None:
return None

notices = get_notices_by_regid(user_regid)
try:
notices = get_notices_by_regid(user_regid)
except DataFailureException as ex:
if ex.status == 404: # MUWM-5375
return []
raise
if notices is None:
return None
return []
return categorize_notices(notices)


Expand Down
10 changes: 6 additions & 4 deletions myuw/test/dao/test_notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ def setUp(self):
get_request()

def test_get_notice_by_regid(self):
# no regid
notices = _get_notices_by_regid(None)
self.assertEqual(notices, None)

# bad regid
notices = _get_notices_by_regid("99999678901234567890123456789012")
self.assertEqual(len(notices), 0)

# MUWM-5375
regid = "99999999999999999999999999999999"
notices = _get_notices_by_regid(regid)
self.assertIsNotNone(notices)
self.assertEqual(len(notices), 0)

regid = "9136CCB8F66711D5BE060004AC494FFE"
notices = _get_notices_by_regid(regid)
self.assertIsNotNone(notices)
Expand Down
2 changes: 0 additions & 2 deletions myuw/views/api/notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import json
import logging
import traceback
from datetime import datetime
from restclients_core.exceptions import DataFailureException
from myuw.dao import is_action_disabled
from myuw.dao.notice import (
get_notices_for_current_user, mark_notices_read_for_current_user)
Expand Down
14 changes: 9 additions & 5 deletions myuw_vue/components/home/notice/notices.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<uw-card v-if="!isReady || hasAnyNotices" :loaded="isReady" :errored="isErrored">
<uw-card v-if="showCard" :loaded="isReady" :errored="isErrored">
<template #card-heading>
<h2 class="h4 mb-3 text-dark-beige myuw-font-encode-sans">Notices</h2>
</template>
<template v-if="!isErrored" #card-body>
<p v-if="notices.length == 0">You do not have any notices at this time.</p>
<template v-if="isReady" #card-body>
<p v-if="noDisplayableNotices">You do not have any notices at this time.</p>
<uw-notice-list v-else :notices="sortNotices(notices)" />
</template>
<template v-else #card-body>
Expand Down Expand Up @@ -36,8 +36,8 @@ export default {
...mapState('notices', {
allNotices: (state) => state.value,
}),
hasAnyNotices() {
return this.allNotices.length > 0;
showCard() {
return this.isFetching || this.isReady && this.allNotices;
},
notices() {
return this.allNotices.filter(
Expand All @@ -48,7 +48,11 @@ export default {
notice.location_tags.includes('notice_banner')
);
},
noDisplayableNotices() {
return this.notices && this.notices.length == 0;
},
...mapGetters('notices', {
isFetching: 'isFetching',
isReady: 'isReady',
isErrored: 'isErrored',
}),
Expand Down
1 change: 1 addition & 0 deletions myuw_vue/tests/mock_data/notice/none.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
13 changes: 13 additions & 0 deletions myuw_vue/tests/notices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CollapsedItem from '../components/_common/collapsed-notice.vue';

import javgNotices from './mock_data/notice/javerage.json';
import jnewNotices from './mock_data/notice/jnew.json';
import noNotices from './mock_data/notice/none.json';

const localVue = createLocalVue(Vuex);

Expand Down Expand Up @@ -161,9 +162,21 @@ describe('Notice Card', () => {
axios.get.mockResolvedValue({ data: javgNotices, status: 200 });
const wrapper = mount(NoticeCard, { store, localVue });
await new Promise(setImmediate);
expect(wrapper.vm.showCard).toBeTruthy;
expect(wrapper.vm.notices.length).toBe(9);
expect(wrapper.vm.noDisplayableNotices).toBe(false);
expect(wrapper.findComponent(NoticeCard).exists()).toBe(true);
expect(wrapper.findComponent(NoticeList).exists()).toBe(true);
expect(wrapper.findComponent(CollapsedItem).exists()).toBe(true);
});

it('Check display do not have any notices', async () => {
axios.get.mockResolvedValue({ data: noNotices, status: 200 });
const wrapper = mount(NoticeCard, { store, localVue });
await new Promise(setImmediate);
expect(wrapper.vm.showCard).toBeTruthy;
expect(wrapper.vm.isErrored).toBe(false);
expect(wrapper.vm.noDisplayableNotices).toBe(true);
expect(wrapper.findComponent(NoticeCard).exists()).toBe(true);
});
});