Commit 164f2ef7 authored by okhin's avatar okhin 🚴

Simplification of some tests

parent 02fe58d8
Pipeline #2634 failed with stages
in 28 seconds
......@@ -239,15 +239,15 @@ class TestArticleApi(TestCase):
codename='can_edit'))
self.client.force_login(user=self.user)
a = self.articles[0]
a.title = 'Zog Zog'
a.screenshot = "test.png"
r = self.client.put('/api/articles/{}/'.format(a.pk),
a.__dict__)
pk = self.articles[0].pk
article = {'title': 'Zog Zog',
'url': 'https://article.org/Zog+Zog'}
r = self.client.put('/api/articles/{}/'.format(pk),
article,
format='json')
assert r.status_code == 200
a.refresh_from_db()
assert a.title == 'Zog Zog'
assert Article.objects.get(pk=pk).title == 'Zog Zog'
def test_api_edit_tags(self):
# Checking that we indeed change the tags
......@@ -255,15 +255,17 @@ class TestArticleApi(TestCase):
codename='can_edit'))
self.client.force_login(user=self.user)
a = json.loads(serializers.serialize('json', [self.articles[0]]))[0]
a['fields']['tags'] = ['Tag 3']
a['fields']['screenshot'] = "test.png"
r = self.client.put('/api/articles/{}/'.format(a['pk']),
a['fields'],
pk = self.articles[0].pk
article = {'title': 'Zog Zog',
'url': 'https://article.org/Zog+Zog',
'tags': '["New Tag 1", "New Tag 2"]'}
r = self.client.put('/api/articles/{}/'.format(pk),
article,
format='json')
assert r.status_code == 200
a = Article.objects.get(pk=a['pk'])
assert list(a.tags.values('name',)) == [{'name': 'Tag 3'}]
a = Article.objects.get(pk=pk)
assert list(a.tags.values('name',).order_by('name')) == [{'name': 'New Tag 1'},
{'name': 'New Tag 2'}]
def test_api_filter_tag(self):
tag = 'Tag 1'
......@@ -296,10 +298,10 @@ class TestArticleApi(TestCase):
assert r.data['count'] == len(self.articles)
def test_api_tag_push_unauth(self):
a = ArticleFactory(tags=['ZogZog'],)
a = ArticleFactory()
r = self.client.post('/api/articles/',
{'url': a.url, 'title': a.title,
'tags': [t.name for t in a.tags.all()]},
'tags': '["Tag 1", "Tag 2"]'},
format='json')
assert r.status_code == 401
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment